使用MASM汇编语言定义带参数的函数

时间:2013-03-11 18:15:06

标签: assembly masm

我正在尝试用x86汇编语言编写一个接受三个参数的函数。是否可以使用多个参数在MASM汇编语言中定义函数?

//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;
}

如果我可以写一个有效的函数来执行此操作,那么jumpIfEqual(5, 5, jumpToHere)将等同于

cmp 5, 5;
je jumpToHere;

1 个答案:

答案 0 :(得分:2)

Yes, you can

例如:

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