Question

In: Computer Science

Description: Write and test a MASM program to perform the following tasks: 1. Display your name...

Description:
Write and test a MASM program to perform the following tasks:
1. Display your name and program title on the output screen.
2. Display instructions for the user.
3. Prompt the user to enter two numbers.
4. Calculate the sum, difference, product, (integer) quotient and remainder of the numbers.
5. Display a terminating message.
Requirements:
1. The main procedure must be divided into sections:
 introduction
 get the data
 calculate the required values
 display the results
 say goodbye
2. The results of calculations must be stored in named variables before being displayed.

Solutions

Expert Solution

Program Screenshot:

Sample output1:

Sample output2:

Code to copy:

; include the irvine library
INCLUDE Irvine32.inc

;Data section declare all the variables
.data
   myName BYTE   "Mila Chung ", 0
   programTitle BYTE   "Programming Assignment #1", 0
   instructions BYTE   "Enter 2 numbers, and I'll show you the sum, difference, product, quotient, and remainder.", 0
   askNum1   BYTE   "First Number: ", 0
   askNum2   BYTE   "Second Number: ", 0
   number1   DWORD   ?   ; integer entered by user
   number2 DWORD   ?   ; second integer entered by user.
   goodByeMessage BYTE   "Impressed? Bye!",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
   errorMessage BYTE   "The second number must be less than the first!", 0

.code
;main procedure
main PROC
   ;print the name
   mov   edx, OFFSET myName
   call WriteString

   ;print the program title
   mov edx, OFFSET programTitle
   call WriteString
   call CrLf

   ;print the instructions
   mov edx, OFFSET instructions
   call   WriteString
   call   CrLf
   call   CrLf

   ;prompt the user to enter first number
   mov edx, OFFSET askNum1
   call WriteString
   ;read the first number
   call ReadInt
   mov number1, eax
   call CrLf

   ;prompt the user to enter second number
   mov edx, OFFSET askNum2
   call WriteString
   ;read the second number
   call ReadInt
   call CrLf
   mov number2, eax
   mov eax, number2
   ;compare the number
   ;if the second number is grater than first number
   ;then jump to Error loop else jump to Calculate
   cmp eax, number1
   jg Error
   jle Calculate

Error:
   ;print the error message
   mov edx, OFFSET errorMessage
   call WriteString
   call CrLf
   ;jump to endProgram
   jg endProgram

Calculate:
   ;move the values of number1 and number2
   ;into eax
   mov eax, number1
   add eax, number2
   mov   sum, eax

   ; find the difference
   mov eax, number1
   sub eax, number2
   mov difference, eax

   ; find the product
   mov eax, number1
   mov ebx, number2
   mul ebx
   mov product, eax

   ; find the quotient
   mov edx, 0
   mov eax, number1
   cdq
   mov ebx, number2
   cdq
   div ebx
   mov quotient, eax
   mov remainder, edx

   ; print the sum Results
   mov eax, number1
   call WriteDec
   mov edx, OFFSET sumString
   call WriteString
   mov eax, number2
   call WriteDec
   mov edx, OFFSET equalsString
   call WriteString
   mov eax, sum
   call WriteDec
   call CrLf

   ;print the difference results
   mov eax, number1
   call WriteDec
   mov edx, OFFSET differenceString
   call WriteString
   mov eax, number2
   call WriteDec
   mov edx, OFFSET equalsString
   call WriteString
   mov eax, difference
   call WriteDec
   call CrLf

   ;print the product results
   mov eax, number1
   call WriteDec
   mov edx, OFFSET productString
   call WriteString
   mov eax, number2
   call WriteDec
   mov edx, OFFSET equalsString
   call WriteString
   mov eax, product
   call WriteDec
   call CrLf

   ;print the quotient results
   mov eax, number1
   call WriteDec
   mov edx, OFFSET quotientString
   call WriteString
   mov eax, number2
   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
  
endProgram:
   ; prin the Goodbye
   call CrLf
   mov edx, OFFSET goodByeMessage
   call WriteString
   call CrLf

exit  
main ENDP
END main


Related Solutions

Write a program to perform the following two tasks: 1. The program will accept a string...
Write a program to perform the following two tasks: 1. The program will accept a string as input in which all of the words are run together, but the first character of each word is uppercase. Convert the string to a string in which the words are separated by spaces and only the first word starts with an uppercase letter. For example, the string "StopAndSmellTheRose" would be converted to "Stop and smell the rose". Display the result string. 2. Then...
Write a program to perform the following two tasks: 1. The program will accept a string...
Write a program to perform the following two tasks: 1. The program will accept a string as input in which all of the words are run together, but the first character of each word is uppercase. Convert the string to a string in which the words are separated by spaces and only the first word starts with an uppercase letter. For example, the string "StopAndSmellTheRose" would be converted to "Stop and smell the rose". Display the result string. 2. Then...
ACTIVITY #1: Defining Strings √ Write an assembly program that display your name, your id, and...
ACTIVITY #1: Defining Strings √ Write an assembly program that display your name, your id, and your college name on the screen. √ Remember: the format of the assembly program should be like this. TITLE your title (FileName.asm) .MODEL FLAT .386 .STACK 64 .DATA str1 DB "My name: Essam Alnatsheh",13,10,'$' .CODE main PROC mov ax,@data mov ds,ax mov ah,09h mov dx, offset str1 int 21h ​mov ah,4Ch​​ ; terminate process ​mov al,0​​ ; return code ​int 21h main ENDP END...
Using c++, write a program that will display your name as a void function then will...
Using c++, write a program that will display your name as a void function then will perform the following by user-defined functions: a. to compute for the sum of two numbers (n1, n2) using function.
Write a C++ program to display toy name
Write a C++ program to display toy name
Part 1 Write a program that displays a frame containing two labels that display your name,...
Part 1 Write a program that displays a frame containing two labels that display your name, one for your first name and one for your last. Experiment with the size of the window to see the labels change their orientation to each other. USE FIRST NAME: Aya LAST NAME: KAYED. SEND THE CODE IN THE EXACT FORMAT FOR JAVA ECLIPSE. I WILL COPY AND PASTE THE CODE SO I CAN RUN IT. Part 2 Propose and solve your own digital...
Write C++ programs to perform the following tasks. In the program descriptions below, example input and...
Write C++ programs to perform the following tasks. In the program descriptions below, example input and output is provided. NOTE: You don’t need arrays to solve any of these problems. You should NOT use arrays to solve any of these problems. • stat.cpp: Let the user input a one or more integers, space separated, on a single line (as seen below), then work out and display the sum, average, sum of squares and population variance of the numbers. Remember, you...
Write a program with class name ForLoops that uses for loops to perform the following steps:1....
Write a program with class name ForLoops that uses for loops to perform the following steps:1. Prompt the user to input two positive integers: firstNum and secondNum (firstNum must be smallerthan secondNum).2. Output all the even numbers between firstNum and secondNum inclusive.3. Output the sum of all the even numbers between firstNum and secondNum inclusive.4. Output all the odd numbers between firstNum and secondNum inclusive.5. Output the sum of all the odd numbers between firstNum and secondNum inclusive. Java programming
Write a program that asks the user to enter five test scores. The program should display...
Write a program that asks the user to enter five test scores. The program should display a letter grade for each score and the average test score. Write the following methods in the program: calcAverage: This method should accept five test scores as arguments and return the average of the scores. determineGrade: This method should accept a test score as an argument and return a letter grade for the score, based on the following grading scale: Score Letter Grade 90-100...
Q1: Write a Java program that will display different messages depending on your age. Your program...
Q1: Write a Java program that will display different messages depending on your age. Your program should ask the user for his/her name and their age in years and give one or more answers from the following ones below: if the age of the user is less than 16, the program should print on the screen “You are not allowed to drive at the moment”. if the age of the user is less than 18, the program should print on...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT