I tried writing my first, very simple program in Assembly. It is supposed to take two digits as input and perform addition, subtraction, multiplication and division on it. I currently do not care about how the program performs when you enter numbers like 5 and 5 (the sum and product of which wouldn't display correctly), cause I'm still learning, and will get to expanding the program further later. Right now, everything works like a charm, except division. When inputting 4 and 2, it, for example, returns the letter 'r' under the quotient. The code that should do this is:
;lastly, division
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, msg6
mov edx, len6
int 0x80
mov ax, [num1]
sub ax, '0'
mov ebx, [num2]
sub ebx, '0'
div ebx
add al, '0'
add ah, '0' ;in case there is a remainder
mov [quot], al
mov [rem], ah
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, quot
mov edx, 1
int 0x80
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, spacer
mov edx, len8
int 0x80
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, msg7
mov edx, len7
int 0x80
mov eax, SYS_WRITE
mov ebx, STDOUT
mov ecx, rem
mov edx, 1
int 0x80
Just for the record, msg6
is just the message: "The quotient is: " and msg7
is the message "The remainder is: ". num1
and num2
are the input numbers. spacer
is my way of inputting spacing between the results. Thanks in advance!