flat assembler
Message board for the users of flat assembler.

Index > Windows > Problem with invoke (masm->fasm)

Author
Thread Post new topic Reply to topic
okasvi



Joined: 18 Aug 2005
Posts: 382
Location: Finland
okasvi
cant figure out what is wrong... already hoping that there is bug in fasm which gives the error Sad

Code:
format PE GUI 4.0
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
;szLeft.asm from ..\masm32\m32lib
include '%fasminc%\WIN32AXP.INC'
.code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

proc szLeft stdcall uses edi ecx edx,\
     src:DWORD,dst:DWORD,ln:DWORD

    mov ecx, [ln]             ; length in ECX
    mov edx, [src]            ; source address
    add edx, ecx            ; add required length
    mov edi, [dst]            ; destination address
    add edi, ecx            ; this also sets the terminator position
    neg ecx                 ; invert sign

  @@:
    mov al, [edx+ecx]
    mov [edi+ecx], al
    add ecx, 1
    jnz @B

    ;mov BYTE PTR [edi], 0   ; write terminator
    mov byte [edi], 0   ; write terminator

    mov eax, [dst]

    ret

endp

start:
        invoke szLeft,szString,szResString,dword [lpLen]
        invoke MessageBox,0,eax,"blehbleh",0
        invoke ExitProcess,0

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
.data
        lpLen           dd      6
        szString        db      "okasvialksjdlkajds",0
        szResString     db      ?
.end start    

_________________
When We Ride On Our Enemies
support reverse smileys |:
Post 08 Jan 2006, 05:23
View user's profile Send private message MSN Messenger Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner
Code:
format PE GUI 4.0 
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««« 
;szLeft.asm from ..\masm32\m32lib 
include '%fasminc%\WIN32AXP.INC' 
.code 
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««« 

proc szLeft src, dst,ln
;stdcall uses edi ecx edx,\ 
;     src:DWORD,dst:DWORD,ln:DWORD 

    mov ecx, [ln]             ; length in ECX 
    mov edx, [src]            ; source address 
    add edx, ecx            ; add required length 
    mov edi, [dst]            ; destination address 
    add edi, ecx            ; this also sets the terminator position 
    neg ecx                 ; invert sign 

  @@: 
    mov al, [edx+ecx] 
    mov [edi+ecx], al 
    add ecx, 1 
    jnz @B 

    ;mov BYTE PTR [edi], 0   ; write terminator 
    mov byte [edi], 0   ; write terminator 

    mov eax, [dst] 

    ret 

endp 

start: 
        stdcall szLeft,szString,szResString,[lpLen]
        invoke MessageBox,0,eax,"blehbleh",0 
        invoke ExitProcess,0 

; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««« 
.data 
        lpLen           dd      6 
        szString        db      "okasvialksjdlkajds",0 
        szResString     db      ? 
.end start
    


the above code solve ur problem.
check the things i commented.
Post 08 Jan 2006, 05:33
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7712
Location: Kraków, Poland
Tomasz Grysztar
For directly calling the functions defined in your code use "stdcall", not "invoke". fasm's "invoke" macro uses the given label as an address of double word variable containing the address of function (the entry in import table usually).

So "invoke ExitProcess,0" is the same as "stdcall [ExitProcess],0", which is the same as "push 0"/"call [ExitProcess]" pair of instructions.
Look here for more details.

After changing "invoke szLeft ..." to "stdcall szLeft ..." your code works correctly.

okasvi wrote:
already hoping that there is bug in fasm which gives the error Sad

Bad boy! Wink (just joking)
Post 08 Jan 2006, 12:04
View user's profile Send private message Visit poster's website Reply with quote
okasvi



Joined: 18 Aug 2005
Posts: 382
Location: Finland
okasvi
Thank you vbVeryBeginner and Privalov Smile

I was just about giving up on converting m32lib to fasm for my own use.

_________________
When We Ride On Our Enemies
support reverse smileys |:
Post 08 Jan 2006, 14:00
View user's profile Send private message MSN Messenger Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner
hi okasvi,
you are welcome
Post 08 Jan 2006, 23:20
View user's profile Send private message Visit poster's website 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.

Powered by rwasa.