;-----PASS BY REFERENCE-----
section .data
x dw 2
y dw 9
msg db 'Sum=%d', 10, 0
section .bss
num resb 1
section .text
global _main
extern _printf
_main:
push num
push 2
push 9
call sum
push num
push msg
call _printf
add esp, 8
pop ebp
mov esp, ebp
ret
sum:
mov ebp, esp ;1st step (always)
mov ax, [ebp + 4] ;ax = 9
add ax, [ebp + 6] ;ax = ax + 2
mov ebx, [ebp + 8] ;ebx = &num ;moves adress of num to ebx
mov [ebx], ax ;*ebx = 11 ;moves 11 (the value at ax) to num (or the value at address contained in ebx (which is the value of num))
ret 8
the nasm code above should print the sum by implementing pass by reference
Welcome to Stack Overflow. Please read the help pages, take the SO tour, and read How to Ask. Also please read about how to write the “perfect” question, especially its checklist. Then edit your question to improve it, like actually asking us a question. What is the problem you with the show code? How do you build the code? How do you run the program? What happens? What should happen?
What is your question?
Welcome to SO. You forgot to show the C code you are using together with that assembler code? If that
_main
function is all you use, how is that related to C? That doesn’t seem to be generated from some C file.