Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

TITLE Elementary Arithemetic Program ( ElementaryArithmeticProgram . asm ) ; Author: Tommy Thao ; Last Modified: 1 / / 2 5 / 2 4 ;

TITLE Elementary Arithemetic Program (ElementaryArithmeticProgram.asm)
; Author: Tommy Thao
; Last Modified: 1//25/24
; OSU email address: thaot@oregonstate.edu
; Course number/section: CS271 Section 400
; Project Number: 1 Due Date: 1/28/24
; EC: Description: A simple program that will do the following below:
;1)Display your name and program title on the output screen.
;2)Display instructions for the user.
;3)Prompt the user to enter three numbers (A, B, C) in strictly descending order.
;4)Calculate the sum and differences: (A+B, A-B, A+C, A-C, B+C, B-C, A+B+C).
;5)Display the results of the above calculations.
;6)Repeat until the user chooses to quit
;7)Display a closing message.
INCLUDE Irvine32.inc
.data
;--------------------------
; All variables that would be used for calculations along with strings
;----------------------------
userName BYTE "Tommy Thao", 0
program_title BYTE "Elementary Arithmetic by ",0
instruction BYTE "Enter 3 numbers A > B > C, and I'll show you the sums and differences.", 0
prompt_1 BYTE "First number: ",0
prompt_2 BYTE "Second number: ",0
prompt_3 BYTE "Third number: ",0
num_1 DWORD ? ; first integer to be entered by user
num_2 DWORD ? ; second integer to be entered by user
num_3 DWORD ? ; third integer to entered by user
equals BYTE "=",0
plus BYTE "+",0
minus BYTE "-",0
sum_of_AB DWORD ? ; to be caluculated
difference_of_AB DWORD ? ; to be caluculated
sum_of_AC DWORD ? ; to be caluculated
difference_of_AC DWORD ? ; to be caluculated
sum_of_BC DWORD ? ; to be caluculated
difference_of_BC DWORD ? ; to be caluculated
sum_of_ABC DWORD ? ; to be caluculated
close_message BYTE "Thanks for using Elementary Arithmetic! Goodbye!", 0
.code
main PROC
;-------------------------------
;Introduction: Displays your name, program title, and instructions
; on the output screen.
; -------------------------------
MOV EDX, OFFSET program_title
CALL WriteString
MOV EDX, OFFSET userName
CALL WriteString
CALL Crlf
MOV EDX, OFFSET instruction
CALL WriteString
CALL Crlf
;-----------------------
; Get the data:Asks user to enter three numbers for (A,B,C) in a descending order and stores them in
; in an array for calculations.
;--------------------------------------
MOV EDX, OFFSET prompt_1
CALL WriteString
CALL ReadInt
MOV num_1, EAX
MOV EDX, OFFSET prompt_2
CALL WriteString
CALL ReadInt
MOV num_2, EAX
MOV EDX, OFFSET prompt_3
CALL WriteString
CALL ReadInt
MOV num_3, EAX
;----------------------------
;Takes the user's input and calculates the sum and differences:
; (A+B, A-B, A+C, A-C, B+C, B-C, A+B+C)
;--------------------------------------------
; A+B
MOV EAX,num_1 ;store num_1(A) into eax
ADD EAX, num_2 ; add num_1(A) and num_2(B)
MOV sum_of_AB, EAX ; store result in sum of AB
;A-B
MOV EAX,num_1 ; store num_1(A) into eax
SUB EAX, num_2 ; subtract num_1(A) and num_2(B)
MOV difference_of_AB, eax ; store result in difference of AB
;A+C
MOV EAX,num_1 ; store num_1(A) into eax
ADD EAX, num_3 ; add num_1(A) and num_3(C)
MOV sum_of_AC, EAX ; store result in sum of AC
;A-C
MOV EAX,num_1 ; store num_1(A) into eax
SUB EAX, num_3 ; subtract num_1(A) and num_3(C)
MOV difference_of_AC, EAX ; store result in difference of AC
;B+C
MOV EAX,num_2 ; store num_2(B) into eax
ADD EAX, num_3 ; add num_2(B) and num_3(C)
MOV sum_of_BC, EAX ; store result in sum of BC
;B-C
MOV EAX,num_2 ; store num_2(B) into eax
SUB EAX, num_3 ; subtract num_2(B) and num_3(C)
MOV difference_of_BC, EAX ; store result in difference of BC
;A+B+C
MOV EAX, num_1 ; store num_1(A) into eax
ADD EAX, num_2 ; add num_1(A) and num_2(B)
ADD EAX, num_3 ; add num_1(A), num_2(B), and num_3(C)
MOV sum_of_ABC, EAX ; store result in sum of ABC
;--------------------------
; Displays the results of the above calculations:
; (A+B, A-B, A+C, A-C, B+C, B-C, A+B+C)
;---------------------------------------
;addition of A and B
MOV EAX, num_1
CALL WriteDec
MOV EDX, OFFSET plus
CALL WriteString
MOV EAX, num_2
CALL WriteDec
MOV EDX, OFFSET equals
CALL WriteString
MOV EAX, sum_of_ABC
CALL WriteDec
CALL Crlf
;Subtraction of A and B
MOV EAX, num_1
CALL WriteDec
MOV EDX, OFFSET minus
CALL WriteString
MOV EAX, num_2
CALL WriteDec
MOV EDX, OFFSET equals
CALL WriteString
MOV EAX, difference_of_AB
CALL WriteDec
CALL Crlf
;Addition of A and C
MOV EAX, num_1
CALL WriteDec
MOV EDX, OFFSET plus
CALL WriteString
MOV EAX, num_3
CALL WriteDec
MOV EDX, OFFSET equals
CALL WriteString
MOV EAX, sum_of_AC
CALL WriteDec
CALL Crlf
;Subtraction of A and C
MOV EAX, num_1
CALL WriteDec
MOV EDX, OFFSET minus
CALL WriteString
MOV EAX, num_3
CALL WriteDec
MOV EDX, OFFSET equals
CALL WriteString
MOV EAX, difference_of_AC

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Image Databases Towards Advanced Image Retrieval

Authors: Yihong Gong

1st Edition

1461375037, 978-1461375036

More Books

Students also viewed these Databases questions