0

I'm working on a program that prompts the user for the numerator and denominator for two fractions. Then it will display the two fractions, then display the product of the two multiplied together, then the reduce form of that, and then finally it will prompt the user if they want to go again. If so repeat if not then terminate. I have everything working except the reduce fraction part. I would appreciate any help that could be given.

Sincerely yours;

jdm

INCLUDE Irvine32.inc

.data                                                                          ;Declare values
myMessage  BYTE "Enter first numerator:     ", 0                                  ;Stores a string
myMessage2 BYTE "Enter first denominator:   ",0
myMessage3 BYTE "Enter second numerator:    ",0
myMessage4 BYTE "Enter second denominator:  ",0
myMessage5 BYTE "/", 0                                                 ;Stores a string
myMessage6 BYTE "Your first fraction is:  ",0
myMessage7 BYTE "Your second fraction is:  ",0
myMessage8 BYTE "The product of these two are:  ",0
myMessage9 BYTE "The reduced form is:  ",0
myMessage10 BYTE "Do you want to do it again:  ",0
myMessage11 BYTE "Terminating...",0dh,0ah,0
myMessage12 BYTE " ",0dh, 0ah, 0
myMessage13 BYTE "You can't store a 0 in the denominator",0dh, 0ah, 0
n1    SDWORD 0
n2    SDWORD 0
d1    SDWORD 0
d2    SDWORD 0
temp  SDWORD 0                                                                   ;Temp variable for eax
temp2 SDWORD 0

.code                                                                          ;Declare main
main PROC                                                                      ;Declare proc
	top:
	call Clrscr                                                                ;Clears the screen
	mov eax, 0                                                                 ;Clear eax
	mov ebx, 0                                                                 ;Clear ebx
	mov ecx, 0                                                                 ;Clear ecx
	
	mov edx, OFFSET myMessage                                                  ;Mov message into edx
	call writestring                                                           ;Display to screen
	
	call readint                                                               ;Reads the input number and store into eax in decimal form.  
	mov n1, eax

top2:
	mov edx, OFFSET myMessage2
	call writestring

	call readdec
	mov d1, eax
	cmp d1, 0
	je wrong2
	jmp sec3

wrong2:
	call wrong
	jmp top2

sec3:	
	mov edx, OFFSET myMessage3
	call writestring

	call readdec
	mov n2, eax

top3:
	mov edx, OFFSET myMessage4
	call writestring

	call readdec
	mov d2, eax
	cmp d2, 0
	je wrong3
	jmp sec4

wrong3:
	call wrong
	jmp top3

sec4:
	mov edx, OFFSET myMessage12
	call writestring

	mov edx, OFFSET myMessage6
	call writestring

	mov eax, n1
	call writeint

	mov edx, OFFSET myMessage5
	call writestring

	mov eax, d1
	call writeint

	mov edx, OFFSET myMessage12
	call writestring

	mov edx, OFFSET myMessage7
	call writestring

	mov eax, n2
	call writeint

	mov edx, OFFSET myMessage5
	call writestring

	mov eax, d2
	call writeint

	mov edx, OFFSET myMessage12
	call writestring

	mov edx, OFFSET myMessage12
	call writestring

	mov edx, OFFSET myMessage8
	call writestring

	mov eax, n1
	mul n2
	mov temp, eax

	mov eax, d1
	mul d2
	mov temp2, eax

	mov eax, temp
	call writeint

	mov edx, OFFSET myMessage5
	call writestring

	mov eax, temp2
	call writeint

	mov edx, OFFSET myMessage12
	call writestring

	mov edx, OFFSET myMessage12
	call writestring

	mov edx, OFFSET myMessage10
	call writestring
	call readchar
	cmp al, 'y'
	cmp al, 'Y'
	je top

	mov edx, OFFSET myMessage12
	call writestring

	mov edx, OFFSET myMessage12
	call writestring

	mov edx, OFFSET myMessage11
	call writestring

	mov edx, OFFSET myMessage12
	call writestring

	mov edx, OFFSET myMessage12
	call writestring

	exit                                                                       ;Exit main
main ENDP                                                                      ;Exit proc

wrong PROC
	mov edx, OFFSET myMessage12
	call writestring
	mov edx, OFFSET myMessage13
	call writestring
	mov edx, OFFSET myMessage12
	call writestring
ret
wrong ENDP

END main
2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by thines01
0

You will need a routine that finds the greatest common Divisor, then divides both the numerator and denominator by that number.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.