Howdy;
I am currently working on a program to review what I have learned so far, in the PCASM book written by Dr. Paul Carter. I have accomplished 3/4ths of my overall goal, however; my program doesn't seem to like me especially the division part of it.
The goal of my program is: output the sum, difference, product, and quotient of 2 numbers inputted by the user.
My question: How come my division doesn't seem to want to work?
Here is what I have so far:
; file math_review.asm
; This program, will aks the user to input two numbers,
; then based on user input, output the sum, difference,
; product and quotient of the specified values
; using Linux and gcc:
; nasm -f elf math_review.asm
; gcc -o math_review math_review.o driver.c asm_io.o
%include "asm_io.inc"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
segment .data
;
; Input prompts
;
user_input_prompt_1 db "Enter first integer: ", 0
user_input_prompt_2 db "Enter second integer: ", 0
;
; Output strings
;
sum_of_input db "Sum: ", 0
diff_of_input db "Difference: ", 0
prod_of_input db "Product: ", 0
quot_of_input db "Quotient: ", 0
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
segment .bss
;
; labels that represent double words that will store user input
;
user_input_1 resd 1
user_input_2 resd 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
segment .text
global asm_main
asm_main:
enter 0, 0
pusha
;
; get first user input
;
mov eax, user_input_prompt_1
call print_string
call read_int
mov [user_input_1], eax
;
; get second user input
;
mov eax, user_input_prompt_2
call print_string
call read_int
mov [user_input_2], eax
;
; addition
;
mov eax, [user_input_1]
add eax, [user_input_2]
mov ebx, eax
mov eax, sum_of_input
call print_string
mov eax, ebx
call print_int
call print_nl
;
; subtraction
;
mov eax, [user_input_1]
sub eax, [user_input_2]
mov ebx, eax
mov eax, diff_of_input
call print_string
mov eax, ebx
call print_int
call print_nl
;
; multiplication
;
mov eax, [user_input_1]
imul eax, [user_input_2]
mov ebx, eax
mov eax, prod_of_input
call print_string
mov eax, ebx
call print_int
call print_nl
;
; division
;
mov eax, [user_input_1]
idiv eax, [user_input_2]
mov ebx, eax
mov eax, quot_of_input
call print_string
mov eax, ebx
call print_int
call print_nl
;
; el fin
;
popa
mov eax, 0
leave
ret
a few of the methods that you see have been provided by the textbook, these are what specified methods do:
print_string - prints the string within the EAX register
read_int - reads user input (integer), and stores it within' the EAX register
print_nl - creates a new line
Thank you for any help/suggestions.