Align ?

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
Unlink

Align ?

Post 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
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:Align ?

Post 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
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:Align ?

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Align ?

Post by Solar »

Read, check your assembler manual. 8)
Every good solution is obvious once you've found it.
Unlink

Re:Align ?

Post by Unlink »

Thanks all of you
Post Reply