0

Extremely new to MASM here. I'm having trouble figuring out how to access the values passed into a procedure through the stack? For instance, here I try to simply add 2 vars, but the output gives me some crazy long address. Any suggestions?

INCLUDE Irvine32.inc

.data
;//DECOY VARS
operand1   WORD    46
operand2   WORD    -20
dest       DWORD   0

.code
main PROC
push    operand1 ;[EBP + 16]
push    operand2 ;[EBP + 12]
push    OFFSET  dest ;[EBP + 8]
call    compute
call    writeint

exit
main ENDP

compute PROC
    push    ebp ;save ebp state
    mov     ebp, esp ;set ebp to activation record

    mov     eax, [ebp + 16]
    add     eax, [ebp + 12]

    pop     ebp
    ret     12
compute ENDP

END main
  • `push operand1` is a 16-bit push because `operand1` is only a `WORD`! You need to zero-extend into a register so you can do a 32-bit push that fills a whole stack slot. – Peter Cordes Mar 09 '21 at 04:44
  • @PeterCordes , This totally worked and clarified everything, thank you! – Lucas Cannon Mar 09 '21 at 05:15
  • Cheers. I looked for a duplicate about how to actually do the zero-extending (e.g. `movzx eax, word ptr [operand1]`) but didn't find a duplicate for that part. Maybe I should reopen and answer this, since passing narrow args to a function in MASM is something people could google on. But I probably won't bother unless you want to post a self-answer; let me know and I can reopen if you (or other future readers) want to do that. – Peter Cordes Mar 09 '21 at 05:18

0 Answers0