flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > align & struc

Author
Thread Post new topic Reply to topic
S.T.A.S.



Joined: 09 Jan 2004
Posts: 173
Location: Ru#27
S.T.A.S. 28 Mar 2004, 10:56
Hi all!
I've got very simple variant of "assume" macro:
Code:
macro   .assume  reg, structure
 {       virtual at reg
              .#reg structure
     end     virtual  }    


And there's a problem with some structures:
Code:
struc foo
 {      align 4
     db      ? }

virtual at ebx
.ebx  foo
end virtual    
error: section is not aligned enough for this operation.
"rb 4-($ and 3)" instead of align gives "invalid expression."

I see $ isn't allowed because of register is used, but data alignment should be very nece in some cases.

Any solutions or ideas how to use "align" inside struc?
Thanks in advance.
Post 28 Mar 2004, 10:56
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 28 Mar 2004, 11:13
All these errors are to signalize, that fasm is not able to determine the value of $ (as it doesn't know what the value of ebx would be), and whether it is aligned on some boundary or not. But when you want just to align relatively to register base (assuming that this base will be also aligned correctly), you can use some trick like this:
Code:
macro falign value
 {
   virtual
     inc byte [dword $]
     load addrimm from $-4
   end virtual
   rb (value-1)-(addrimm+value-1) mod value
 }    
Post 28 Mar 2004, 11:13
View user's profile Send private message Visit poster's website Reply with quote
S.T.A.S.



Joined: 09 Jan 2004
Posts: 173
Location: Ru#27
S.T.A.S. 28 Mar 2004, 12:31
Privalov, thanks a lot!!
Hmm.. I guess this is not just "some trick", but some kind of magic beyond my mind Smile
Post 28 Mar 2004, 12:31
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8356
Location: Kraków, Poland
Tomasz Grysztar 28 Mar 2004, 12:36
It just generates some virtual instruction (in this case "inc byte") with the address operand forced to use 32-bit immediate, and then loads this immediate from the generated instruction code to get only the immediate part of the address (ignoring the register base). This address is then used instead of $ for alignment (the last line is the same as good old "align" macro from the fasm's docs, with "$" replaced by "addrimm").
Post 28 Mar 2004, 12:36
View user's profile Send private message Visit poster's website Reply with quote
S.T.A.S.



Joined: 09 Jan 2004
Posts: 173
Location: Ru#27
S.T.A.S. 28 Mar 2004, 15:55
Thanks again for detailed explanation!
Now I see:
inc [ebx+disp32] & inc [disp32] -
of cource, the last DWORD of opcode is the same in both cases..
It seems easy when I see HOW this works, but it's not so easy to INVENT such nice trick..
I guess with new "store" directive there'll be more magic in FASM Cool
Post 28 Mar 2004, 15:55
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.