Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define a function with parameters in MASM assembly language

Tags:

assembly

masm

I'm trying to write a function in x86 assembly language that will accept three parameters. Is it possible to define a function in MASM assembly language with multiple parameters?

//this is pseudocode: I'm trying to convert this to a valid macro in MASM
//if var1 is equal to var2, jump to the label jumpToHere
function jumpIfEqual(var1, var2, jumpToHere){
    cmp var1, var2;
    je jumpToHere;
}

If I could write a valid function to do this, then jumpIfEqual(5, 5, jumpToHere) would be equivalent to

cmp 5, 5;
je jumpToHere;
like image 902
Anderson Green Avatar asked Apr 22 '26 21:04

Anderson Green


1 Answers

Yes, you can.

For example:

jumpIfEqual PROC var1:DWORD, var2:DWORD, jmpAddress:DWORD
    mov eax,var1
    cmp eax,var2
    jne skip
    pop eax
    push jmpAddress
    skip:
    ret
jumpIfEqual ENDP

....

push OFFSET jumpToHere
mov eax, 5
push eax
push eax
call jumpIfEqual
like image 96
Michael Avatar answered Apr 28 '26 20:04

Michael



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!