Page 1 of 1
org 0x7c00
Posted: Tue Jun 24, 2003 9:48 am
by slacker
when you say org 0x7c00 does the address refer to a linear address or the offset of an address? i think it has to refer to the linear.....anyone know for sure..?
Re:org 0x7c00
Posted: Tue Jun 24, 2003 9:54 am
by TB
It refers to linear (absolute) address.
Re:org 0x7c00
Posted: Tue Jun 24, 2003 10:09 am
by Tim
The ORG directive in an assembly source file specifies the offset from the start of a segment. The assembler doesn't know anything about where segments are located.
The number in the ORG directive is also a linear address wihtin a segment if the segment starts at address zero.
Re:org 0x7c00
Posted: Tue Jun 24, 2003 10:54 am
by slacker
when the pc boots up what is the initial value of cs? wouldnt it have to be 0?
Re:org 0x7c00
Posted: Tue Jun 24, 2003 11:59 pm
by Pype.Clicker
unfortunately, the early PC cloners weren't clear at this: it was just mentionned that the code will be loaded by the bios at physical address 0x7C00, but the exact CS:IP combination to be used was never clearly defined.
Potentially, any combination that fits CS*16+IP=0x7C00 would be valid (such as CS=0x700, IP=0xC00), but in practice only two are used: 0000:7C00 anc 07C0:0000.
So the only wise way to work is to *force* the combination you want by the mean of a far jump as the first instruction:
Code: Select all
[ORG 0]
jmp far 07c0h:label
label:
or
Code: Select all
[ORG 7C00h]
jmp far 0000:label
label:
Re:org 0x7c00
Posted: Wed Jun 25, 2003 6:59 am
by slacker
i was thinking about something like this:
Code: Select all
;(booter)
[bits 16]
[org 0x00]
jump:
mov ax, 0x7c00
add ax, boot
jmp far 0x00:ax
boot:
code
shouldnt something like this work?
Re:org 0x7c00
Posted: Wed Jun 25, 2003 7:29 am
by Pype.Clicker
in fact, there's no such thing as "jmp register-value" ... but you're right on one point: using jmp 0x7c00:0 wouldn't have worked either (just creates an endless loop). Patched my previous code ...
Re:org 0x7c00
Posted: Mon Jun 30, 2003 2:34 pm
by slacker
this works...
Code: Select all
;(booter)
[bits 16]
[org 0x00]
jmp jump
myvar dw 0x7c00+boot
jump:
jmp 0x00:myvar
boot:
mov ax, cs
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov sp, 0x700
Re:org 0x7c00
Posted: Mon Jun 30, 2003 3:27 pm
by Pype.Clicker
1. as your variable's content is constant, while not putting it directly in the jump statement ?
2. are you sure it's really correct ? you say the assembler the sector will start at offset 0 and then you jump to offset 7C00 ... weird, weird, imho.
Re:org 0x7c00
Posted: Mon Jun 30, 2003 3:41 pm
by slacker
works for me....
Re:org 0x7c00
Posted: Mon Jun 30, 2003 4:34 pm
by Tim
I think what Pype.Clicker means is:
Code: Select all
;(booter)
[bits 16]
[org 0x7c00]
jmp 0x00:boot
boot:
mov ax, cs
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov sp, 0x700
This way you get the assembler to add the 7C00 for you. If you keep the [org 0x00], you will have problems when you start to use variables.
Re:org 0x7c00
Posted: Mon Jun 30, 2003 6:06 pm
by slacker
oh yea.....your right