flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
ivan_tux 23 Jun 2012, 12:18
Can someone explain to me about 'align' in assembly?
I'm still newbie.... ![]() example: abc dd 1 align 4 ;<<<what for he place this? def db 1 |
|||
![]() |
|
ivan_tux 23 Jun 2012, 12:53
@cod3b453. thanks....
![]() |
|||
![]() |
|
shutdownall 23 Jun 2012, 13:15
Alignment is a performance issue.
As modern CPUs have minimum 32 bit data bus it reads for example 4 bytes with one access, always beginning with the last two bits zeroed. Imagine you have following command reading a dword (dd): mov eax,[buffer] and buffer will start at address 0001:5551 This could result in worst case in two external memory access *: 0001:5550 (and throw the first byte) 0001:5554 (and throw 3 more bytes) To avoid this, you could do align 4 which will always put buffer at an address divideable by 4 and add some extra space in memory structure. A more common alignment is in "paragraphs" (16 bytes) or sometimes 200h for data in physical sectors on harddisc. The point is, that alignment will also produce some waste of memory. So it is a good idea to think of manual alignments for your variable section through moving data definitions in a proper way. * in fact it is not the fully truth, architecture is more complicate and all memory access is controlled by a on chip memory controller which also feed and controls the internal caches (L1 and L2) which is structured in memory aligned portions. But my example is more easy to understand, I think. ![]() |
|||
![]() |
|
ivan_tux 23 Jun 2012, 14:06
shutdownall wrote: Alignment is a performance issue. I think it's better ![]() |
|||
![]() |
|
nts94 06 Jul 2012, 23:48
Ok, so if i understand well, this is a bug, isn't it?
Code: format PE GUI include 'win32a.inc' struct DUMMY a dd ? ; offset 0 b db ? ; offset 4 align 4 c dd ? ; offset 8 due to alignment ends section '.text' code readable executable entry $ xor eax,eax lea eax,[eax + DUMMY.c] ret [img]http://www.elenalermadansa.com/UserFiles/Media/imprpant.bmp[/img] |
|||
![]() |
|
LocoDelAssembly 07 Jul 2012, 00:15
Not precisely, it is the struct macro which doesn't support alignment, but I think such support should be there (although not sure if it is a simple to implement as I'm imagining it).
This alternate way of defining the structure will give you the desired alignment: Code: format PE GUI include 'win32a.inc' struc DUMMY { .a dd ? ; offset 0 .b db ? ; offset 4 align 4 .c dd ? ; offset 8 due to alignment } virtual at 0 DUMMY DUMMY sizeof.DUMMY = $ end virtual section '.text' code readable executable entry $ xor eax,eax lea eax,[eax + DUMMY.c] ret |
|||
![]() |
|
AsmGuru62 07 Jul 2012, 00:19
Looks like a bug.
There are two more methods to define structures: 1. Use 'virtual at 0' directive 2. Use native FASM 'struc' statement (not struct) Both work fine with align. I just checked in debugger - offset is 8 at this 3rd member. |
|||
![]() |
|
nts94 07 Jul 2012, 00:19
Oh, ok, I didn't know it, I'm coming from tasm and the change is being a bit hard
![]() |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.