03-printf.asm 754 B

123456789101112131415161718192021222324252627
  1. ;;; Required packages: nasm, gcc, gcc-multilib
  2. ;;; Compile commands:
  3. ;;; nasm -f elf 03-printf.asm -o bin/03-printf.o
  4. ;;; gcc -m32 -o bin/03-printf.out bin/03-printf.o
  5. ;;;
  6. section .data
  7. message_fmt db "Value %d, address %d", 0xa, 0 ; 0 - end of string, required by printf func
  8. variable dd 120 ; 4 byte
  9. section .text
  10. extern printf
  11. global main
  12. main:
  13. ; output
  14. push variable ; get memory address
  15. push DWORD [variable] ; get value by memory address
  16. push message_fmt
  17. call printf
  18. add esp, 12 ; sizeof(variable) + sizeof(DWORD [variable]) + sizeof(message_fmt)
  19. ; exit code
  20. mov eax, 1 ; 1 - system call sys_exit
  21. mov ebx, 0 ; 0 - error code 0
  22. int 0x80 ; processor interruption to run syscall