I'm learning assmebler by myself at the moment and I finally managed to read input from the terminal and calculate with it.
I use sys_read for that and it works perfectly fine but when I use it the terminal acts like I pressed enter after runnning the program (one line with root@kali:~/ASM$). This does not happen when using scanf.
Here is my code:
sys_read equ 3
sys_write equ 4
stdout equ 1
stdin equ 2
section .data
prompt db "Enter two 1-digit numbers for an integer division.", 10, 0
result db 10, "%i / %i = %i.", 10, 0
section .bss
a resb 4
b resb 4
c resb 4
section .text
extern printf
global main
main:
push ebp
mov ebp, esp
push ebx
push esi
push edi
push prompt
call printf
mov eax, sys_read
mov ebx, stdin
mov ecx, a
mov edx, 1
int 80h
sub dword [a], 0x30
mov eax, sys_read
mov ebx, stdin
mov ecx, b
mov edx, 1
int 80h
mov eax, sys_read
mov ebx, stdin
mov ecx, b
mov edx, 1
int 80h
sub dword [b], 0x30
mov dx, 0
mov ax, [a]
div dword [b]
mov [c], ax
push dword [c]
push dword [b]
push dword [a]
push result
call printf
add esp, 40
pop edi
pop esi
pop ebx
mov esp, ebp
pop ebp
ret
And here is the output I get:
root@kali:~/ASM$ ./div Enter two 1-digit numbers for an integer division. 1 1 1 / 1 = 1. root@kali:~/ASM$ root@kali:~/ASM$
I don't understand why this extra line appears.
1 1but that leaves the actual new line in the buffer. You don't do anything with it in your program so it gets processed by the shell after. You could flush stdin after reading the 3 character or change the lastsys_readto read 2 characters instead of 1. That would consume the newline.$instead of the usual#to indicate UID=0? Experimenting with asm development is not a smart thing to do on a privileged account.sudosetup is a much more sane way to approach that. No wonder I've heard negative comments about Kali Linux, if that's the kind of choice they make. It stand by my comment that running buggy asm code you're working on as root is not wise.