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
Align ?
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:Align ?
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.
[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 ?
Hi,
For example, in MASM you could write a boot sector with:
And you might be able to do something like:
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
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".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.
For example, in MASM you could write a boot sector with:
Code: Select all
ORG 0
; some boot sector code
ORG 510
DW 0xAA55
Code: Select all
ORG 0
; some stuff
ORG ( ($+3) & ~3)
; some more stuff
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.