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?
Posted on 2001-09-10 21:13:24 by 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


mov eax, offset variable

Try the LEA approach, it might do the job for you.


Posted on 2001-09-10 21:25:14 by hutch--
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...
Posted on 2001-09-10 21:27:47 by Kenny
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.

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?
Posted on 2001-09-10 21:41:24 by bitRAKE

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.


Posted on 2001-09-10 21:42:02 by hutch--
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.

Posted on 2001-09-10 22:18:47 by -T-
Ok, lemme elaborate on my problem a little better:

MASM code:
mcall ,IDirect3D8_GetAdapterDisplayMode,\

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,\

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...

I was meaning building addr into FASM, not lea.
Posted on 2001-09-10 22:22:12 by Kenny
Well, you need

Try to use the override:

d ;force dword :)

...it might be how you have d3ddm defined?

Edit: This is wrong!
Posted on 2001-09-10 22:30:10 by bitRAKE
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]
Posted on 2001-09-10 23:13:51 by Kenny
ok in the data section I have:


.Width dd ?
.Height dd ?
.RefreshRate dd ?
.Format dd ?
Posted on 2001-09-10 23:17:54 by Kenny
Oooohh.. I got it!

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 :)
Posted on 2001-09-11 00:24:58 by Kenny
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?
Posted on 2001-09-11 08:29:23 by bitRAKE
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:

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....
Posted on 2001-09-11 13:11:23 by Kenny
Wait, what's the difference between

mov eax,401068h
mov eax,offset 401068h
Posted on 2001-09-11 13:27:27 by Kenny
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-) :]

Posted on 2001-09-11 14:05:15 by 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...

Posted on 2001-09-11 15:27:54 by Kenny
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
Posted on 2001-09-11 15:52:30 by Kenny
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. ;)
Posted on 2001-09-11 18:07:53 by bitRAKE
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...
Posted on 2001-09-11 22:10:58 by Kenny