Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- section .bss
- answer resb 1
- section .text
- global _start
- _start:
- ; read one byte of data from stdin
- mov eax, 0x03 ; sys_read
- mov ebx, 0x00 ; stdin
- mov ecx, answer
- mov edx, 0x01
- int 0x80
- ; counter
- mov cx, [answer]
- sub cx, 0x30 ; get non-ascii value
- loop_start:
- add cx, 0x30
- push cx ; push ascii value
- ; write the current counter value
- mov eax, 0x04
- mov ebx, 0x01
- mov ecx, esp
- mov edx, 0x01
- int 0x80
- ; check if the loop is done
- pop cx
- sub cx, 0x30
- dec cx
- cmp cx, 0x00
- jge loop_start
- ; write newline
- push 0x0a
- mov eax, 0x04
- mov ebx, 0x01
- mov ecx, esp
- mov edx, 0x01
- int 0x80
- ; exit program
- mov eax, 0x01 ; sys_exit
- mov ebx, 0x00 ; no file descriptor
- int 0x80
Advertisement
Add Comment
Please, Sign In to add comment