Ok, I'm having a painful time in FASM right now.
I can't figure out what the difference between offset and addr is.
In masm it says push addr d3ddm, but when I do that in FASM, this is what I get:
;FASM -- decompiled
push d3ddm ;push offset 401018h
push ;push dword ptr [401018h]
I need to have to do:
push addr d3ddm ;push 401018h
what gives? any ideas?
I can't figure out what the difference between offset and addr is.
In masm it says push addr d3ddm, but when I do that in FASM, this is what I get:
;FASM -- decompiled
push d3ddm ;push offset 401018h
push ;push dword ptr [401018h]
I need to have to do:
push addr d3ddm ;push 401018h
what gives? any ideas?
Kenny,
ADDR is part of the syntax for MASM's invoke statement and it handles addresses that are constructed in a couple of different ways.
LEA eax, variable
or
mov eax, offset variable
Try the LEA approach, it might do the job for you.
Regards,
hutch@pbq.com.au
ADDR is part of the syntax for MASM's invoke statement and it handles addresses that are constructed in a couple of different ways.
LEA eax, variable
or
mov eax, offset variable
Try the LEA approach, it might do the job for you.
Regards,
hutch@pbq.com.au
yeah, but I want it directly in FASM... am I going to have to fire up the FASM source and start hacking?
I think I already know my answer... dang...
I think I already know my answer... dang...
In FASM you have to use brackets to get the value. You want the address, that is just the name of the variable. The following groups produce the same code bytes in the respective assembler.
;address
mov eax,variable ;FASM
mov eax,offset variable ;MASM
;value at address
mov eax, ;FASM
mov eax,variable ;MASM
mov eax, ;MASM isn't this confusing?
;address
mov eax,variable ;FASM
mov eax,offset variable ;MASM
;value at address
mov eax, ;FASM
mov eax,variable ;MASM
mov eax, ;MASM isn't this confusing?
Kenny,
LEA is an Intel opcode and I imagine that FASM would support it properly. If you are porting MASM to FASM, just construct the variable address as a manual opcode and it should work for you.
Regards,
hutch@pbq.com.au
LEA is an Intel opcode and I imagine that FASM would support it properly. If you are porting MASM to FASM, just construct the variable address as a manual opcode and it should work for you.
Regards,
hutch@pbq.com.au
I had a problem with using '' and plain A with trying to get the adress at the beggining as well.
I don't like how they both mean the same thing at some points and not in others. Major headache at first, then I gave up and used offset. What do you figure:)
I am glad FASM has it right. Props.
T
I don't like how they both mean the same thing at some points and not in others. Major headache at first, then I gave up and used offset. What do you figure:)
I am glad FASM has it right. Props.
T
Ok, lemme elaborate on my problem a little better:
MASM code:
mcall ,IDirect3D8_GetAdapterDisplayMode,\
D3DADAPTER_DEFAULT,ADDR d3ddm
disassembled:
00401039 681C304000 push 40301Ch
0040103E 6A00 push 0
00401040 8BD2 mov edx,edx
00401042 A19F304000 mov eax,[40309Fh]
00401047 50 push eax
00401048 8B00 mov eax,
0040104A FF5020 call dword ptr
FASM code:
calldx ,IDirect3D8.GetAdapterDisplayMode,\
D3DADAPTER_DEFAULT,d3ddm
dissassembled:
00402036 6868104000 push offset 401068h
0040203B 6A00 push 0
0040203D 8B1D20104000 mov ebx,[401020h]
00402043 53 push ebx
00402044 8B1B mov ebx,
00402046 FF5320 call dword ptr
Oh, and FASM doesn't like it when I change it to ; it says invalid...
Hutch:
I was meaning building addr into FASM, not lea.
MASM code:
mcall ,IDirect3D8_GetAdapterDisplayMode,\
D3DADAPTER_DEFAULT,ADDR d3ddm
disassembled:
00401039 681C304000 push 40301Ch
0040103E 6A00 push 0
00401040 8BD2 mov edx,edx
00401042 A19F304000 mov eax,[40309Fh]
00401047 50 push eax
00401048 8B00 mov eax,
0040104A FF5020 call dword ptr
FASM code:
calldx ,IDirect3D8.GetAdapterDisplayMode,\
D3DADAPTER_DEFAULT,d3ddm
dissassembled:
00402036 6868104000 push offset 401068h
0040203B 6A00 push 0
0040203D 8B1D20104000 mov ebx,[401020h]
00402043 53 push ebx
00402044 8B1B mov ebx,
00402046 FF5320 call dword ptr
Oh, and FASM doesn't like it when I change it to ; it says invalid...
Hutch:
I was meaning building addr into FASM, not lea.
Well, you need
Try to use the override:
d ;force dword :)
...it might be how you have d3ddm defined?
Edit: This is wrong!
Try to use the override:
d ;force dword :)
...it might be how you have d3ddm defined?
Edit: This is wrong!
That produces this:
00402036 FF3568104000 push dword ptr [401068h]
0040203C 6A00 push 0
0040203E 89D2 mov edx,edx
00402040 8B1D20104000 mov ebx,[401020h]
00402046 53 push ebx
00402047 8B1B mov ebx,[ebx]
00402049 FF5320 call dword ptr [ebx+20h]
ok in the data section I have:
d3ddm D3DDISPLAYMODE
struc D3DDISPLAYMODE
{
.Width dd ?
.Height dd ?
.RefreshRate dd ?
.Format dd ?
.End:
}
Oooohh.. I got it!
Posted on 2001-09-11 00:21:18 by NaN
Posted on 2001-09-11 00:21:18 by NaN
But why??? I LOVE FASM.. accept for the small little bugs...
Besides a few small annoyances, it outweighs all the small annoyances of MASM.
I guess I could always just ditch the structure and do a virtual over it... Hey, I guess I will give it a try tomorrow. But until then, I have a final and what little sleep I can get :)
Besides a few small annoyances, it outweighs all the small annoyances of MASM.
I guess I could always just ditch the structure and do a virtual over it... Hey, I guess I will give it a try tomorrow. But until then, I have a final and what little sleep I can get :)
I was wrong Kenny, your original code should have been fine. :) ( use just 'd3ddm', sorry to confuse you ) Where did you get the disassembly listings from?
NaN, Why not?
NaN, Why not?
dang... it still does the offset though...
I got the code from pe dumper thing that comes with MASM...
Ok, so I got this brilliant idea of this:
That doesn't work either...
it should be: mov eax,401068h
DANG! I think it's time to start learning how to write nifty macros using custom intel macros or maybe start to code directly in FASM source....
I got the code from pe dumper thing that comes with MASM...
Ok, so I got this brilliant idea of this:
00402036 A168104000 mov eax,[401068h]
0040203B 50 push eax
0040203C 6A00 push 0
0040203E 89D2 mov edx,edx
00402040 8B1D20104000 mov ebx,[401020h]
00402046 53 push ebx
00402047 8B1B mov ebx,[ebx]
00402049 FF5320 call dword ptr [ebx+20h]
That doesn't work either...
it should be: mov eax,401068h
DANG! I think it's time to start learning how to write nifty macros using custom intel macros or maybe start to code directly in FASM source....
Wait, what's the difference between
mov eax,401068h
and
mov eax,offset 401068h
???
mov eax,401068h
and
mov eax,offset 401068h
???
Each time i have pointed to this problem, everybody fainted to not
understand what i was saying (including Tomasz...).
The real fact is that you can have nothing else than *two* things:
- either an Adress.
- or the content of an Adress.
Nothing else do exist. Now, another fact is that, following the weird
syntax of MASM, Tasm, and later FASM (halas), they have all considered
that, the ability of symbol 'Typing', this is to say the ability to
define a symbol either as an Adress or as a Label,... was a great thing.
... Well, this is the result.
Solution1: Write to Tomasz ( Tomasz.Grysztar@omega.im.uj.edu.pl ) until
he conforms to the actual standard (NASM).
(I already did it, but he answered me that he wrote FASM, essentially for
his own use, and that he prefers TASM Ideal mode syntax over any other...
Just try to bore him to death). :)
Solution2: Give a try to NASM or SpAsm (Oooopppsss,... you already did it
for SpAsm, ... sorry -Oh you, nasty boy!!! Excuse me, i am so happy today,
that you might hear it-) :]
Betov.
understand what i was saying (including Tomasz...).
The real fact is that you can have nothing else than *two* things:
- either an Adress.
- or the content of an Adress.
Nothing else do exist. Now, another fact is that, following the weird
syntax of MASM, Tasm, and later FASM (halas), they have all considered
that, the ability of symbol 'Typing', this is to say the ability to
define a symbol either as an Adress or as a Label,... was a great thing.
... Well, this is the result.
Solution1: Write to Tomasz ( Tomasz.Grysztar@omega.im.uj.edu.pl ) until
he conforms to the actual standard (NASM).
(I already did it, but he answered me that he wrote FASM, essentially for
his own use, and that he prefers TASM Ideal mode syntax over any other...
Just try to bore him to death). :)
Solution2: Give a try to NASM or SpAsm (Oooopppsss,... you already did it
for SpAsm, ... sorry -Oh you, nasty boy!!! Excuse me, i am so happy today,
that you might hear it-) :]
Betov.
I might go back to SpAsm, just when I first started using SpAsm I didn't know much about asm, and therefore I was VERY confused ALL THE TIME :) hehe
So, anyways, I think I might fire up SpAsm again, but SpAsm doesn't have some of the cool options I liked with FASM (being able to write my program in QEditor, being able to back up my source every time I pressed compile.bat, and also creating a decompiled text every time I hit compile.bat.) I also liked the ability to control what is going in what segment, and the segments that are used, I can set their properties and stuff like that...
*sigh*...
So, anyways, I think I might fire up SpAsm again, but SpAsm doesn't have some of the cool options I liked with FASM (being able to write my program in QEditor, being able to back up my source every time I pressed compile.bat, and also creating a decompiled text every time I hit compile.bat.) I also liked the ability to control what is going in what segment, and the segments that are used, I can set their properties and stuff like that...
*sigh*...
Hey, forget all of that other stuff, could you, add a command line option so I could run spasm this way:
SpAsm.exe -exe myprog.asm
SpAsm.exe -dll mydll.asm
or, maybe....
SpAsm.exe -compile lala.exe (or .dll)
If you could do that, I would become a HARDCORE SpAsm user :) The reason why I want command line is so I can run it with a .bat file that will automatically decompile my code and back it up... I make so many mistakes, this is the only way I have to debug... hehe
SpAsm.exe -exe myprog.asm
SpAsm.exe -dll mydll.asm
or, maybe....
SpAsm.exe -compile lala.exe (or .dll)
If you could do that, I would become a HARDCORE SpAsm user :) The reason why I want command line is so I can run it with a .bat file that will automatically decompile my code and back it up... I make so many mistakes, this is the only way I have to debug... hehe
Actually, the only two moves are:
- a value
- the value that is pointed to by a value
(of course, forgetting where that value comes from: immediate, register, or any of the other addressing modes). The difference between:
mov eax,offset 401068h ;relocated
mov eax,401068h ;immediate value
(look at the bytes produced: same.) ...is the fact that one is a relocated value - which means it's value is based on the position of the code apon loading into memory. And the other is just an immediate value - this only works if the code is located at the same place in memory all the time. The loader does the relocation - it's not a feature of the processor, but of the OS.
It appears as if the PE dumper isn't seeing the relocation data in the MASM executable? Please, some one burst my bubble here if I'm wrong - because I've been wrong a lot lately, and I'm trying to get over it. ;)
- a value
- the value that is pointed to by a value
(of course, forgetting where that value comes from: immediate, register, or any of the other addressing modes). The difference between:
mov eax,offset 401068h ;relocated
mov eax,401068h ;immediate value
(look at the bytes produced: same.) ...is the fact that one is a relocated value - which means it's value is based on the position of the code apon loading into memory. And the other is just an immediate value - this only works if the code is located at the same place in memory all the time. The loader does the relocation - it's not a feature of the processor, but of the OS.
It appears as if the PE dumper isn't seeing the relocation data in the MASM executable? Please, some one burst my bubble here if I'm wrong - because I've been wrong a lot lately, and I'm trying to get over it. ;)
to my experience there are three ways:
mydata dd 1
mov eax, mydata ; eax = 1
mov eax, ; eax = 101106h
mov eax, dword ptr mydata ; eax = what is at 01h
offset is the same as the brackets thing...
mydata dd 1
mov eax, mydata ; eax = 1
mov eax, ; eax = 101106h
mov eax, dword ptr mydata ; eax = what is at 01h
offset is the same as the brackets thing...