Answered step by step
Verified Expert Solution
Question
1 Approved Answer
TITLE Elementary Arithemetic Program ( ElementaryArithmeticProgram . asm ) ; Author: Tommy Thao ; Last Modified: 1 / / 2 5 / 2 4 ;
TITLE Elementary Arithemetic Program ElementaryArithmeticProgramasm
; Author: Tommy Thao
; Last Modified:
; OSU email address: thaot@oregonstate.edu
; Course numbersection: CS Section
; Project Number: Due Date:
; EC: Description: A simple program that will do the following below:
;Display your name and program title on the output screen.
;Display instructions for the user.
;Prompt the user to enter three numbers A B C in strictly descending order.
;Calculate the sum and differences: AB AB AC AC BC BC ABC
;Display the results of the above calculations.
;Repeat until the user chooses to quit
;Display a closing message.
INCLUDE Irvineinc
data
;
; All variables that would be used for calculations along with strings
;
userName BYTE "Tommy Thao",
programtitle BYTE "Elementary Arithmetic by
instruction BYTE "Enter numbers A B C and I'll show you the sums and differences.",
prompt BYTE "First number:
prompt BYTE "Second number:
prompt BYTE "Third number:
num DWORD ; first integer to be entered by user
num DWORD ; second integer to be entered by user
num DWORD ; third integer to entered by user
equals BYTE
plus BYTE
minus BYTE
sumofAB DWORD ; to be caluculated
differenceofAB DWORD ; to be caluculated
sumofAC DWORD ; to be caluculated
differenceofAC DWORD ; to be caluculated
sumofBC DWORD ; to be caluculated
differenceofBC DWORD ; to be caluculated
sumofABC DWORD ; to be caluculated
closemessage BYTE "Thanks for using Elementary Arithmetic! Goodbye!",
code
main PROC
;
;Introduction: Displays your name, program title, and instructions
; on the output screen.
;
MOV EDX, OFFSET programtitle
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 ABC in a descending order and stores them in
; in an array for calculations.
;
MOV EDX, OFFSET prompt
CALL WriteString
CALL ReadInt
MOV num EAX
MOV EDX, OFFSET prompt
CALL WriteString
CALL ReadInt
MOV num EAX
MOV EDX, OFFSET prompt
CALL WriteString
CALL ReadInt
MOV num EAX
;
;Takes the user's input and calculates the sum and differences:
; AB AB AC AC BC BC ABC
;
; AB
MOV EAX,num ;store numA into eax
ADD EAX, num ; add numA and numB
MOV sumofAB EAX ; store result in sum of AB
;AB
MOV EAX,num ; store numA into eax
SUB EAX, num ; subtract numA and numB
MOV differenceofAB eax ; store result in difference of AB
;AC
MOV EAX,num ; store numA into eax
ADD EAX, num ; add numA and numC
MOV sumofAC EAX ; store result in sum of AC
;AC
MOV EAX,num ; store numA into eax
SUB EAX, num ; subtract numA and numC
MOV differenceofAC EAX ; store result in difference of AC
;BC
MOV EAX,num ; store numB into eax
ADD EAX, num ; add numB and numC
MOV sumofBC EAX ; store result in sum of BC
;BC
MOV EAX,num ; store numB into eax
SUB EAX, num ; subtract numB and numC
MOV differenceofBC EAX ; store result in difference of BC
;ABC
MOV EAX, num ; store numA into eax
ADD EAX, num ; add numA and numB
ADD EAX, num ; add numA numB and numC
MOV sumofABC, EAX ; store result in sum of ABC
;
; Displays the results of the above calculations:
; AB AB AC AC BC BC ABC
;
;addition of A and B
MOV EAX, num
CALL WriteDec
MOV EDX, OFFSET plus
CALL WriteString
MOV EAX, num
CALL WriteDec
MOV EDX, OFFSET equals
CALL WriteString
MOV EAX, sumofABC
CALL WriteDec
CALL Crlf
;Subtraction of A and B
MOV EAX, num
CALL WriteDec
MOV EDX, OFFSET minus
CALL WriteString
MOV EAX, num
CALL WriteDec
MOV EDX, OFFSET equals
CALL WriteString
MOV EAX, differenceofAB
CALL WriteDec
CALL Crlf
;Addition of A and C
MOV EAX, num
CALL WriteDec
MOV EDX, OFFSET plus
CALL WriteString
MOV EAX, num
CALL WriteDec
MOV EDX, OFFSET equals
CALL WriteString
MOV EAX, sumofAC
CALL WriteDec
CALL Crlf
;Subtraction of A and C
MOV EAX, num
CALL WriteDec
MOV EDX, OFFSET minus
CALL WriteString
MOV EAX, num
CALL WriteDec
MOV EDX, OFFSET equals
CALL WriteString
MOV EAX, differenceofAC
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started