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