section .data
section .bss
x2 resb 4
section .text
global _start
_start:
mov ecx, 5
mov eax, 6
push ecx
push eax
pop ebp
mov eax, 4
mov ebx, 1
mov ecx, ebp
mov edx, 15
int 80h
mov eax, 1
mov ebx, 0
int 0x80

- 32,384
- 7
- 42
- 56

- 1
-
Welcome to Stack Overflow! Your question in lacking in details. What doesn't work with your code? [Edit] the question to include enough details that we can provide an answer. See [ask]. – 1201ProgramAlarm Sep 20 '21 at 15:24
-
Please re-read the documentation for the `int 80h/eax=4` system call. – 500 - Internal Server Error Sep 20 '21 at 15:34
-
AT&T duplicate of the same question: [Print Register in Assembly x86](https://stackoverflow.com/q/22621780) – Peter Cordes Sep 20 '21 at 17:43
1 Answers
If you want to print a number on console standard output in human-readable format, you need to convert it to this format first. It doesn't matter where you've got the number from: a memory variable, stack or from an immediate value loaded to a register, as it is in your example:
mov eax, 6
push eax
pop ebp
mov ecx, ebp
Kernel service sys_write expects that the second argument *buf is a pointer to memory variable (buffer). It is provided to int 80h
in register ecx
; in your case you loaded this register with 00000006h
. When kernel tries to read edx=15
bytes from this address, this will fail because such low address is not available for your program.
Reserve a buffer for the decimal digits, e.g. Decimal resb 12
, convert your number to this buffer and load its address by lea ecx,[Decimal]
before using the service int 80h/eax=4
.

- 5,515
- 1
- 18
- 31