News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Fasm Question

Started by remus2k, January 04, 2011, 03:03:57 AM

Previous topic - Next topic

remus2k

I Translate a routine from Fasm to Masm

Fasm:

local Font LOGFONT
add dword[Font+RECT.left],eax




Masm:

.data?
pFont LOGFONT <?>

add dword ptr [pFont+Rect.left], eax


I need this pFont variable in the Data? section

If i compile it have i this error ?!
A2101: cannot add two relocatable labels

Can you help?

dedndave

strange wording on the error

you are not showing us the fasm declaration for RECT
the RECT structure and the LOGFONT structure are not related
pFont can be either local or global - that is not the problem

show us a larger chunk of the fasm code   :bg

and....
RECT is a structure definition name
i am guessing maybe it is from GetClientRect ???
you need another structure, like

rct RECT <>
or
local rct RECT

fasm is wierd - lol

remus2k

YEs correct i have wonder me

Ok this Fasm source works and my source without this chunk works now fine
Have i this complete tranlate can i post this Havy Fasm code :bg

Sorry i have me wonder with this font and rect struct :U

Tight_Coder_Ex

I'm not sure why you're getting an error but here's an example that may shed a little light on the difference between FASM & MASM

I have no idea what LOGFONT, I'd have to assume as Dave suggests it is actually a RECT structure.
Notice how [Reg/Mem],eax in FASM & NASM is the same as RegMem.eax in MASM.


.586
.model flat, stdcall
option casemap:none

LOGFONT struct
left dd ?
top dd ?
right dd ?
bottom dd ?
LOGFONT ends

.data?
pFont LOGFONT <?>

.code
start:
push ebp
mov ebp, esp

mov eax, 138d7H
mov pFont.left, eax
mov dword ptr [pFont+LOGFONT.left], eax
mov pFont.bottom, ecx
mov dword ptr [pFont+LOGFONT.bottom], ecx

assume ebx:ptr LOGFONT
mov [ebx].bottom, ecx
assume ebx: nothing

leave
ret
end start


Notice how the two methods of address give exactly the same result but inside assume, a lot less code is producted
Output from DUMPPE


00 55 push    ebp
01 8BEC                 mov     ebp,esp
03 B8D7380100 mov     eax,138D7h
08 A300304000 mov     [pFont],eax
0D A300304000     mov     [pFont],eax
12 890D0C304000                 mov     [40300Ch],ecx
18 890D0C304000                 mov     [40300Ch],ecx
1E 894B0C                 mov     [ebx+0Ch],ecx
21 C9 leave
22 C3 ret



jj2007

assume ebx:ptr LOGFONT
mov [ebx].bottom, ecx
assume ebx: nothing


That is not sufficient. You need to assign ebx:
mov ebx, offset pFont

Instead of the assume, you can then use:
mov [ebx.LOGFONT.bottom], ecx

Here is the correct LOGFONT structure:
LOGFONT STRUCT
  lfHeight          DWORD      ?
  lfWidth           DWORD      ?
  lfEscapement      DWORD      ?
  lfOrientation     DWORD      ?
  lfWeight          DWORD      ?
  lfItalic          BYTE      ?
  lfUnderline       BYTE      ?
  lfStrikeOut       BYTE      ?
  lfCharSet         BYTE      ?
  lfOutPrecision    BYTE      ?
  lfClipPrecision   BYTE      ?
  lfQuality         BYTE      ?
  lfPitchAndFamily  BYTE      ?
  lfFaceName        BYTE LF_FACESIZE dup(?)
LOGFONT ENDS

donkey

Quote from: jj2007 on January 04, 2011, 06:30:59 AM
That is not sufficient. You need to assign ebx:
mov ebx, offset pFont

jj2007,

Tsk, tsk, tsk... You know that you can't use MOV with LOCALs...

lea ebx, pFont

remus2k,

The RECT.Left just resolves to 0 so it is the same as LOGFONT.lfHeight which resolves to 0 as well. Why the original programmer would choose to obfuscate the code that way is a mystery though...
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

jj2007

Quote from: Tight_Coder_Ex on January 04, 2011, 06:21:32 AM
.data?
pFont   LOGFONT <?>

Hi Edgar,
It's midnight in Canada, you must be tired... :wink

donkey

Quote from: jj2007 on January 04, 2011, 06:55:32 AM
Quote from: Tight_Coder_Ex on January 04, 2011, 06:21:32 AM
.data?
pFont   LOGFONT <?>

Hi Edgar,
It's midnight in Canada, you must be tired... :wink


Not so tired that I didn't look at the first post, the FASM code that needs to be translated ;)

Quote from: remus2k on January 04, 2011, 03:03:57 AM
Fasm:

local Font LOGFONT
add dword[Font+RECT.left],eax


Which is by the way valid code which should assemble just fine.

BTW, its anywhere from 11:00pm to 02:30am in Canada, but yes, its midnight here.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

jj2007

Quote from: donkey on January 04, 2011, 06:59:17 AM
Not so tired that I didn't look at the first post, the FASM code that needs to be translated ;)
...
BTW, its anywhere from 11:00pm to 02:30am in Canada, but yes, its midnight here.

Here it's 8:00 A.M., everywhere in Italy, and I just had a strong coffee. That's why I could read up to the fourth post, the one that uses pFont and assume :bg
:thumbu

japheth

Quote from: remus2k on January 04, 2011, 03:03:57 AM

.data?
pFont LOGFONT <?>

add dword ptr [pFont+Rect.left], eax


If i compile it have i this error ?!
A2101: cannot add two relocatable labels

I agree the error msg is strange. I guess it is because you changed "RECT" to "Rect". While RECT is a type and known to Masm, "Rect" is unknown and Masm will create a ( forward referenced ) label "Rect" when trying to evaluate the expression. Since there are now two labels ( pFont and Rect) used as operands for the '+' operator, the error msg may start making sense.

donkey

Quote from: jj2007 on January 04, 2011, 07:05:57 AM
Quote from: donkey on January 04, 2011, 06:59:17 AM
Not so tired that I didn't look at the first post, the FASM code that needs to be translated ;)
...
BTW, its anywhere from 11:00pm to 02:30am in Canada, but yes, its midnight here.

Here it's 8:00 A.M., everywhere in Italy, and I just had a strong coffee. That's why I could read up to the fourth post, the one that uses pFont and assume :bg
:thumbu

Hi jj, unfortunately everything after the original FASM code has little to do with the code to be translated. There is no need for a pointer to the structure at all and certainly no reason to use ASSUME. A quick scan through the thread shows that nobody was of the opinion that the original is probably just an obfuscation and that the original FASM code works fine. In MASM it would simply be:

local font :LOGFONT

mov DWORD PTR font, eax
; or alternately mov [font+LOGFONT.lfHeight], eax


Ofcourse there is a lot of code missing here that might explain why the original source used a RECT structure to get offset 0 but that's pretty much academic, the original code to be translated required the structure to be local so the translated code should leave it local. The local requirement may have been for any number of reasons and changing it neglects the possibility that it may have been expressly made local to allow for thread safe execution. The fact is we don't know so we can't arbitrarily change the original code, only translate it verbatim. And since it is local, it is already using REG+OFFSET ([esp+xxx]) so using assume or another register to point to it just make no sense.
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

jj2007

Quote from: remus2k on January 04, 2011, 03:03:57 AM
I need this pFont variable in the Data? section

Hi Edgar,
Is it really worth a fight??? My post referred to Tight_Coder_Ex remark "inside assume, a lot less code is producted" - maybe a misunderstanding of what assume does (i.e., it does not load the ptr into ebx).

Take care,
Jochen

donkey

 :bg I'm just screwing with you Jochen, nothing else to do and I can't sleep. Just having a bit of fun...
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

jj2007

Try television - usually I fall asleep after ten minutes :wink
Good night Edgar :8)

remus2k

 :bg

Thanks for the info

I have the next question with this call DrawText
Call this DrawText 2x?



push 0x800
push eax
push 2
push szString
push esi
push ebx
push esi
push eax
push [hDlg]
  invoke SetTextColor,esi,53248
call [GetClientRect]
call [SetBkColor]

;     Calc routine for pos and Rect
;     ...
;     ..
;     .

@@: call [DrawText]
                inc pPos
jmp @Ret



Can I not write?



invoke SelectObject,hdc,[hFont2]
lea eax, [Rect]

invoke SetTextColor,hdc,0D000h
invoke GetClientRect,hDlg,addr Rect
invoke SetBkColor,hdc,0

;     Calc routine for pos and Rect
;     ...
;     ..
;     .

@@: invoke DrawText,hdc,offset szString,2,addr Rect,800h
                inc pPos
jmp @Ret



Thanks