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,435
  • 4
  • 39
  • 71
Dmytro
  • 5,068
  • 4
  • 39
  • 50

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
  • 61,140
  • 12
  • 83
  • 180