0
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
1201ProgramAlarm
  • 32,384
  • 7
  • 42
  • 56
felix
  • 1

1 Answers1

2

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.

vitsoft
  • 5,515
  • 1
  • 18
  • 31