Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MASM Assembly language: Write and test a MASM program to perform the following t

ID: 3876434 • Letter: M

Question

MASM Assembly language: Write and test a MASM program to perform the following tasks:

-Display your name and program title on the output screen.

-Display instructions for the user.

-Prompt the user to enter two numbers.

-Calculate the sum, difference, product, (integer) quotient and remainder of the numbers.

-Display a terminating message.

Requirements:

The main procedure must be divided into sections:

introduction

get the data

calculate the required values

display the results

say goodbye

The results of calculations must be stored in named variables before being displayed.

The program must be fully documented. This includes a complete header block for identification,

description, etc., and a comment outline to explain each section of code.

Example execution (user input is in italics):

First number: 37

Second number: 5

Explanation / Answer

INCLUDE Irvine32.inc

.data

myName BYTE "Your name ", 0

programTitle BYTE " Assignment #1", 0

instructions BYTE "Enter 2 numbers, and I'll show you the sum, difference,product, quotient, and remainder.", 0

prompt_1 BYTE "First Number: ", 0

prompt_2 BYTE "Second Number: ", 0

firstNumber DWORD ? ; first integer entered by user

secondNumber DWORD ? ; second integer entered by user.

goodBye BYTE "Impressed ?Goodbye",0

equalsString BYTE " = ", 0

sum DWORD ?

sumString BYTE " + ",0

difference DWORD ?

differenceString BYTE " - ",0

product DWORD ?

productString BYTE " * ",0

quotient DWORD ?

quotientString BYTE " / ",0

remainder DWORD ?

remainderString BYTE " remainder ",0

EC1prompt BYTE "**EC: This program verifies the second number is less than the first", 0

EC1warn BYTE "The second number must be less than the first!", 0

EC2prompt BYTE "**EC: This program also calculates and displays the quotient as a floating-point number, rounded to the nearest .001", 0

EC2string BYTE "EC: Floating-point value: ", 0

EC2FloatingPoint REAL4 ? ; short real single precision floating point variable

oneThousand DWORD 1000 ; to convert an int to a floating point number rounded to .001 (can be changed to increase or decrease precision)

bigInt DWORD 0 ; represents the floating point number multiplied by 1000

ECremainder DWORD ? ; for floating point creation

dot BYTE ".",0 ; to serve as the decimal place of a floating point number

firstPart DWORD ? ; for the first part of the floating point representation of the quotient

secondPart DWORD ? ; fot the part of the floating point number after the decimal place

temp DWORD ? ; temporary holder for floating point creation

EC3prompt BYTE "EC: Would you like to play again? Enter 1 for YES or 0 for NO: ", 0

EC3explain BYTE "**EC: This program loops until the user decides to quit.", 0

EC3response DWORD ? ; BOOL for user to loop or exit.

.code

main PROC

; Introduction

; This section prints out the instructions

mov edx, OFFSET myName

call WriteString

mov edx, OFFSET programTitle

call WriteString

call CrLf

mov edx, OFFSET EC1prompt

call WriteString

call CrLf

mov edx, OFFSET EC2prompt

call WriteString

call CrLf

mov edx, OFFSET EC3explain

call WriteString

call CrLf

; Get The Data

; This section gets the first and second number and jumps if the user's second number is greater than the first number

; the program will still allow them to loop even if they enter a second number that is greater than the first.

mov edx, OFFSET instructions

call WriteString

call CrLf

; get firstNumber

top:

mov edx, OFFSET prompt_1

call WriteString

call ReadInt

mov firstNumber, eax

; get secondNumber

mov edx, OFFSET prompt_2

call WriteString

call ReadInt

mov secondNumber, eax

; **EC: Jump if second number greater than first

mov eax, secondNumber

cmp eax, firstNumber

jg Warning

jle Calculate

Warning:

mov edx, OFFSET EC1warn

call WriteString

call CrLf

jg JumpToLoop ; jump if secondNumber > firstNumber

Calculate: ; Calculate Required Values

; sum

mov eax, firstNumber

add eax, secondNumber

mov sum, eax

; difference

mov eax, firstNumber

sub eax, secondNumber

mov difference, eax

; product

mov eax, firstNumber

mov ebx, secondNumber

mul ebx

mov product, eax

; quotient

mov edx, 0

mov eax, firstNumber

cdq

mov ebx, secondNumber

cdq

div ebx

mov quotient, eax

mov remainder, edx

; EC floating point representation of quotient and remainder

fld firstNumber ; load firstNumber (integer) into ST(0)

fdiv secondNumber ; divide firstNumber by secondNumber ?

fimul oneThousand

frndint

fist bigInt

fst EC2FloatingPoint ; take value off stack, put it in EC2FloatingPoint

; Display Results

; sum results

mov eax, firstNumber

call WriteDec

mov edx, OFFSET sumString

call WriteString

mov eax, secondNumber

call WriteDec

mov edx, OFFSET equalsString

call WriteString

mov eax, sum

call WriteDec

call CrLf

; difference results

mov eax, firstNumber

call WriteDec

mov edx, OFFSET differenceString

call WriteString

mov eax, secondNumber

call WriteDec

mov edx, OFFSET equalsString

call WriteString

mov eax, difference

call WriteDec

call CrLf

; product results

mov eax, firstNumber

call WriteDec

mov edx, OFFSET productString

call WriteString

mov eax, secondNumber

call WriteDec

mov edx, OFFSET equalsString

call WriteString

mov eax, product

call WriteDec

call CrLf

; quotient results

mov eax, firstNumber

call WriteDec

mov edx, OFFSET quotientString

call WriteString

mov eax, secondNumber

call WriteDec

mov edx, OFFSET equalsString

call WriteString

mov eax, quotient

call WriteDec

mov edx, OFFSET remainderString

call WriteString

mov eax, remainder

call WriteDec

call CrLf

; EC2 Output

mov edx, OFFSET EC2string

call WriteString

mov edx, 0

mov eax, bigInt

cdq

mov ebx, 1000

cdq

div ebx

mov firstPart, eax

mov ECremainder, edx

mov eax, firstPart

call WriteDec

mov edx, OFFSET dot

call WriteString

;calculate remainder

mov eax, firstPart

mul oneThousand

mov temp, eax

mov eax, bigInt

sub eax, temp

mov secondPart, eax

call WriteDec

call CrLf

; Loop until user quits

; prompts the user to enter a 0 or 1 to continue looping.

; if they do want to play again, it takes them to section 'top'

; skipping the instrucitons

; get response for loop

JumpToLoop: mov edx, OFFSET EC3prompt

call WriteString

call ReadInt

mov EC3response, eax

cmp eax, 1

je top ; jump to top if response == 1

; Say Goodbye

mov edx, OFFSET goodBye

call WriteString

call CrLf

exit ; exit to operating system

main ENDP

END main