flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Assume The Assumptions!

Author
Thread Post new topic Reply to topic
Mercury Knight



Joined: 09 Nov 2008
Posts: 15
Mercury Knight
Hmmmmm an interesting quandry. I use the assume macro for registers which points to structures in cases where the structure is used a lot. But in the case of a structure within a structure (i.e. a structure that is stand alone, yet also included in other structures), assume does not work as expected if I try to use the name of the substructure without referencing any of the elements within that substructure.

Code:
include 'macro\struct.inc'
include 'macro\masm.inc'
use32

Struct TestStruct1
   Key1  rd 1
EndStruct

Struct TestStruct2
   Key2  TestStruct1
EndStruct


StartX:
        mov     eax,[eax+TestStruct1.Key1]      ; works
        mov     ebx,[ebx+TestStruct2.Key2]      ; works
        mov     ecx,[ecx+TestStruct2.Key2.Key1] ; works

        assume  eax:TestStruct1
        assume  ebx:TestStruct2
        assume  ecx:TestStruct2
        mov     eax,[eax.Key1]                  ; works
        mov     ebx,[ebx.Key2]                  ; BOOM!
        mov     ecx,[ecx.Key2.Key1]             ; works
    


The last two lines are identical to each other, yet fasm refuses to assemble the first one. Even if one changes it from mov to lea, fasm still refuses to assemble it since ebx.Key2 is undefined in both cases. I've used the tools and traced what the preprocessor was seeing, but it wasn't quite making sense to me as how assume labels ebx.Key2 but does not define it. I could do it the long way, but it does gets tedious after a while typing in the struct names.

So I am asking... is there a way to get the assume macro to also define variables to structures, like in this case ebx.Key2? It would be much better than typing in ebx+TestStruct2.Key2...

BTW: It should just create a simple binary file when you assemble it, the file is not meant to be runnable.

Thanks!
M
Post 03 May 2009, 20:31
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17663
Location: In your JS exploiting you and your system
revolution
The fault is here:
Code:
        mov     ebx,[ebx+TestStruct2.Key2]      ; shouldn't work    
The macros give the correct result.

You can prove the the above line is wrong by doing this:
Code:
include 'macro\struct.inc'
include 'macro\masm.inc'
use32

struct TestStruct1
   Key1  rq 1           ;<-- change to quad word for testing
ends

struct TestStruct2
   Key2  TestStruct1
ends

        mov     ebx,[ebx+TestStruct2.Key2]      ; shouldn't work    
It loaded a 32bit value from a 64bit variable without an override!
Post 04 May 2009, 01:43
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
revolution, could you start a thread in Compiler Internals about this bug?

Thanks
Post 04 May 2009, 01:48
View user's profile Send private message Reply with quote
Mercury Knight



Joined: 09 Nov 2008
Posts: 15
Mercury Knight
Wow... looking for one bug shows up another!

And I can see where using

Code:
   mov ebx,[ebx+TestStruct2.Key2]
    


shouldn't work since TestStruct2.Key2 is a structure variable and not a pointer to a structure... but it should be valid if one wants the address by using lea instead of mov (I've been getting the same error whether using lea or mov).

I'm still looking at the assume macro, but I still can't get it to define ebx.Key2 to use as thus:

Code:
   lea ebx,[ebx.Key2]
    


I haven't looked inside of the struct macro since it defines TestStruct2.Key2, as well as TestStruct2.Key2.Key1, but my brain already fried earlier trying to figure out what changes needed to be made in assume in order for it to define ebx.Key2.

BTW: I forgot to remove Struct and EndStruct in my original post, I use a fix definition to rename them!

M
Post 04 May 2009, 02:10
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17663
Location: In your JS exploiting you and your system
revolution
LocoDelAssembly wrote:
revolution, could you start a thread in Compiler Internals about this bug?
Actually I considered it but I am still wondering if it is a compiler bug. Basically the value of TestStruct2.Key2 is an unsized number. This is that same as "mov ebx,[ebx+A_Random_Number]". I think fasm doesn't (can't?) distinguish between normally defined numbers (A_Random_Number = 1) and structure defined offsets.

However since you think it is a bug I will make a new thread and see what Tomasz has to say about it.
Post 04 May 2009, 03:32
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
Quote:

Basically the value of TestStruct2.Key2 is an unsized number.

Aahh damn, I forgot about that fact. It is still odd the "mov ebx, [ebx.Key2]" error though (perhaps MASM doesn't support this neither?).
Post 04 May 2009, 03:53
View user's profile Send private message Reply with quote
Mercury Knight



Joined: 09 Nov 2008
Posts: 15
Mercury Knight
Quote:

Basically the value of TestStruct2.Key2 is an unsized number.


Hmmmm why not have the struct macro simply mark the variable as a label (and fix the assume macro to account for it)? Then an instruction such as

Code:
   mov eax,[eax+TestStruct2.Key2]
    


shouldn't work without an override because Key2 is just label that points to an offset within its main structure (pointing to the start of the embedded structure) and doesnt have a size associated with it... while at the same time, using the assume macro...

Code:
   lea eax,[eax.Key2]    ; same as lea eax,[eax+TestStruct2.Key2]
    


should work since Key2 is basically a label now and would load eax with the starting address of the embedded structure. Just a thought...
Post 04 May 2009, 18:23
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.