Page 1 of 1

Align ?

Posted: Sun Jan 22, 2006 2:11 pm
by Unlink
Hi All,
Sorry for my stupid question, but asking is better than unkowing.
i don't know what is align and what does it really do ?
and what is the different between align & org
thanks
sorry being stupid

Re:Align ?

Posted: Mon Jan 23, 2006 2:58 am
by Pype.Clicker
well, [tt]org[/tt] says "this is where my program starts". It usually makes little sense to use it several time in one program.

[tt]align[/tt] on the other side, tells "the next byte i issue should have address X that is multiple of <argument>". You ask the assembler to provide as many "padding" bytes as required unless a suitable address is met.

E.g.

Code: Select all

org 0
hello db "hello"
    ; next byte should be at address 5
align 8
    ; override that: we want the GDT to start at an address
    ; that is a multiple of 8 bytes for performances reasons.
null_desc: dd 0,0
code_desc: dd CODE_DESC1,CODE_DESC2
data_desc ...


align 4096
    ; say we want code to be unwritable thanks to paging, 
    ; it makes sense to force the first function to be aligned 
    ; on a page boundary (we could have used linker script too
_start:
    mov [0xb8000],':-)-'
    cli
    hlt

Re:Align ?

Posted: Mon Jan 23, 2006 8:10 am
by Brendan
Hi,
Pype.Clicker wrote: well, [tt]org[/tt] says "this is where my program starts". It usually makes little sense to use it several time in one program.
This is actually "assembler-specific". For example, it is true for NASM but not for MASM. For MASM, [tt]ORG[/tt] says "this is where instructions should be assembled to".

For example, in MASM you could write a boot sector with:

Code: Select all

        ORG 0 

        ; some boot sector code 

        ORG 510 
        DW 0xAA55
And you might be able to do something like:

Code: Select all

        ORG 0 
        ; some stuff

        ORG ( ($+3) & ~3)

        ; some more stuff
Which would do exactly the same thing as "align 4" - not sure if it'd actually work though (I've never used MASM).


Cheers,

Brendan

Re:Align ?

Posted: Mon Jan 23, 2006 8:19 am
by Solar
Read, check your assembler manual. 8)

Re:Align ?

Posted: Mon Jan 23, 2006 10:06 am
by Unlink
Thanks all of you