org 0x7c00

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
slacker

org 0x7c00

Post 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..?
TB

Re:org 0x7c00

Post by TB »

It refers to linear (absolute) address.
Tim

Re:org 0x7c00

Post 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.
slacker

Re:org 0x7c00

Post by slacker »

when the pc boots up what is the initial value of cs? wouldnt it have to be 0?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:org 0x7c00

Post 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:
slacker

Re:org 0x7c00

Post 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?
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:org 0x7c00

Post 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 ...
slacker

Re:org 0x7c00

Post 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

User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:org 0x7c00

Post by Pype.Clicker »

1. as your variable's content is constant, while not putting it directly in the jump statement ?

Code: Select all

jmp 0x00: 0x7c00+boot 
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.
slacker

Re:org 0x7c00

Post by slacker »

works for me....
Tim

Re:org 0x7c00

Post 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.
slacker

Re:org 0x7c00

Post by slacker »

oh yea.....your right
Post Reply