-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRiceAAssignment1.asm
51 lines (42 loc) · 1.99 KB
/
RiceAAssignment1.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
TITLE RiceAAssignment1 (RiceAAssignment1.asm)
INCLUDE Irvine32.inc
.data
blank BYTE " ",0ah,0
promptA BYTE "Input a number for A: ",0dh,0ah,0
promptB BYTE "Input a number for B: ",0dh,0ah,0
zeroErr BYTE "Cannot divide by 0!",0ah,0
intA SDWORD ?
intB SDWORD ?
.code
main PROC
oErrA: mov edx,OFFSET promptA ;Prompt user for input
call WriteString ;Prompt user for input
call ReadInt ;Accept input from user
jo oErrA ;Jump back to prompt on OF
mov intA,eax ;Store input as intA
mov ebx,intA ;Prep ebx to become divisor
oErrB: mov edx,OFFSET promptB ;Prompt user for input
call WriteString ;Prompt user for input
call ReadInt ;Accept input from user
jo oErrB ;Jump back to prompt on OF
mov intB,eax ;Store input as intB
add eax,intA ;Compute numerator (A+B)
sub ebx,intB ;Compute denominator (A-B)
jz err ;Jump on zero denominator
cdq ;Extend sign bit for div
idiv ebx ;Compute quotient (A+B)/(A-B)
mov ebx,eax ;Move quotient to ebx
mov ecx,edx ;Move remainder to ecx
mov eax,intA ;Prepare eax for mul
imul intB ;Compute product (A*B)
sub eax,ebx ;Compute final result
call WriteInt ;Print result to console
mov edx,OFFSET blank ;Insert carriage return
call WriteString ;Insert carriage return
invoke ExitProcess,0 ;Terminate gracefully
err: mov edx,OFFSET zeroErr ;Print error
call WriteString ;Print error
invoke ExitProcess,0 ;Terminate gracefully
exit
main ENDP
END main