News:

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

using Proc in MASM

Started by hrxxx, May 05, 2010, 01:43:21 AM

Previous topic - Next topic

hrxxx

Im verybeginner in MASM, i will practise about proc
How to use Proc in MASM, may be ini Basic will look like this

FUNCTION MyAdd(Bil1 as DWORD, Bil2 as DWORD) as DWORD
Local A as DWORD
    A=Bil1+Bil2
    Mov Function, A
END FUCNTION

how ro erite in MASM style, smple of project please  :(

clive

; Assemble with ML -c -coff -Fl xxx.asm

.386

.MODEL FLAT,C

.CODE

;FUNCTION MyAdd(Bil1 as DWORD, Bil2 as DWORD) as DWORD
;Local A as DWORD
;    A=Bil1+Bil2
;    Mov Function, A
;END FUCNTION

MyAdd PROC Bil1:DWORD, Bil2:DWORD

        mov eax,Bil1
        add eax,Bil2

; Data in EAX returned with answer

ret

MyAdd ENDP

END
It could be a random act of randomness. Those happen a lot as well.

dedndave

hi hrxxx
here is a very simple example....


;place proto's near the beginning of the file
;in this example, the proc is called with 2 dword parameters

MyProc  PROTO   :DWORD,:DWORD

;calling the proc
;2 parameters are used
;for the first parm, we use a dword pointer to some label
;for the second parm, we use a dword value

       INVOKE  MyProc,addr SomeLabel,SomeVar

;the proc
;in this example, we tell the assembler to save EBX, ESI, EDI, and EBP
;those registers should be preserved across win32 GUI application function calls
;the contents of EAX, ECX, and EDX may be altered
;the assembler saves and restores the "uses" registers
;also, it pops the 2 parameters off the stack at the RET, balancing the stack
;in most cases, a value is returned in EAX reflecting either the result or the status of the operation

MyProc  proc uses ebx esi edi ebp lpBuffer:DWORD,dwVar:DWORD

        mov     edx,lpBuffer   ;load EDX with the pointer from parm1
        mov     eax,dwVar      ;load EAX with the variable from parm2

        ret

MyProc  endp

hrxxx

Thanks for ALl sample, im learning masm32 now  :bg

hrxxx

What wrong with my PROC, so it cant perform what i want
.............

ShowMsg  PROTO   :DWORD,:DWORD
...............
..............

.data
    szKata db "Hello Guys", 0

..................

ShowMsg proc uses ebx esi edi ebp lpBuffer:DWORD,dwVar:DWORD
    xor ebx, ebx
    .while ebx <= dwVar
        invoke MessageBox, NULL, addr lpBuffer, addr lpBuffer, MB_OK
        inc ebx
    .endw   
    ret
ShowMsg endp

invoke ShowMsg, addr szKata, 3


The result does not show Message Box "Hello Guys"  :'(

dedndave


;this include file has a most of the stuff you need - have a look at it to see what is in it

include \masm32\include\masm32rt.inc

.............

ShowMsg  PROTO   :DWORD,:DWORD
...............
..............

.data
    szKata db "Hello Guys", 0
..................

.code
main proc

invoke ShowMsg, addr szKata, 3

;the program needs some way to exit - although, you may want a button to click on or something

invoke ExitProcess,0

main endp

..................

ShowMsg proc uses ebx esi edi ebp lpBuffer:DWORD,dwVar:DWORD
    xor ebx, ebx
    .while ebx <= dwVar
        invoke MessageBox, NULL, addr lpBuffer, addr lpBuffer, MB_OK
        inc ebx
    .endw   
    ret
ShowMsg endp

..................

end main    ;you need to indicate the entry point in the END directive