3

this is my code (test.asm)

expected "num = 1337"

output: "num = 4199373"

question: How do I fix it.

intent: curiosity towards assembly language, not assignment.

; nasm -fwin32 test.asm
; gcc test.obj -o test
    extern _printf
    global _main

    section .text
_main:
    push num
    push msg
    call _printf
    add esp, 8
    ret

msg db 'num = %i', 0xa, 0
num dd 1337

changing push num to push dword [num] fixed it.

nrz
  • 10,237
  • 4
  • 38
  • 71
Dmitry
  • 4,752
  • 4
  • 35
  • 48

1 Answers1

3

push num pushes the address of num (similar to push msg), but not the value contained there.

You need push dword [num] instead.

Alexey Frunze
  • 59,618
  • 10
  • 77
  • 173