flat assembler
Message board for the users of flat assembler.

Index > Windows > [solved] Call a function add two numbers

Author
Thread Post new topic Reply to topic
frankobach26



Joined: 10 Apr 2026
Posts: 13
Location: Kassel
frankobach26 12 May 2026, 16:28
Hello. Need Help to get correct result. Thanks!

Code:
; test call pobamain and add two numbers
;
format PE64 GUI
entry start

include 'win64ax.inc'


section '.data' data readable writeable

    text  db 'Ergebnis: %d',0
    title db 'calculation OK',0
    buffer     db 64 dup(0)

section '.text' code readable executable

start:

   sub rsp,28h

   call pobamain

   invoke ExitProcess,0
   ret

pobamain:

    call AddNumbers

    sub rsp,28h

    invoke MessageBoxA,0,text,title,MB_OK

    add rsp,28h

    ret


AddNumbers:

    mov rax,5
    add rax,7
    ret


section '.idata' import data readable writeable

    library kernel32,'KERNEL32.DLL',\
            user32,'USER32.DLL'

    import kernel32,\
            ExitProcess,'ExitProcess'

    import user32,\
            MessageBoxA,'MessageBoxA'    


My second idea was to add an include File to call the function but that Doesnt Work yet
Post 12 May 2026, 16:28
View user's profile Send private message Reply with quote
frankobach26



Joined: 10 Apr 2026
Posts: 13
Location: Kassel
frankobach26 12 May 2026, 17:27
New edit: I have found my correct solution:
WsprintfA

Code:
            format PE64 GUI
entry start

include 'win64ax.inc'

section '.data' data readable writeable

    text   db 'Ergebnis: %d',0
    title  db 'calculation OK',0
    buffer db 64 dup(0)

section '.text' code readable executable

start:
    sub rsp, 28h

    call pobamain

    invoke ExitProcess, 0

pobamain:
    sub rsp, 28h

    call AddNumbers        ; RAX = Ergebnis

    ; wsprintfA(buffer, text, eax)
    invoke wsprintfA, buffer, text, eax

    invoke MessageBoxA, 0, buffer, title, MB_OK

    add rsp, 28h
    ret

AddNumbers:
    mov rax, 5
    add rax, 7
    ret

section '.idata' import data readable writeable

    library kernel32,'KERNEL32.DLL',\
            user32,'USER32.DLL'

    import kernel32,\
            ExitProcess,'ExitProcess'

    import user32,\
            MessageBoxA,'MessageBoxA',\
            wsprintfA,'wsprintfA'    
Post 12 May 2026, 17:27
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-2026, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.