Question

In: Computer Science

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

Program 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 three numbers (A, B, C) in descending order.
  4. Calculate and display the sum and differences: (A+B, A-B, A+C, A-C, B+C, B-C, A+B+C).
  5. Display a closing message.

Program Requirements

  1. The program must be fully documented and laid out according to the CS271 Style Guide. This includes a complete header block for identification, description, etc., and a comment outline to explain each section of code.
  2. The main procedure must be divided into logical sections:
    1. introduction
    2. get the data
    3. calculate the required values
    4. display the results
    5. say goodbye
  3. 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

THANK YOU!! PLEASE VOTE


Related Solutions

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...
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...
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
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...
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...
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...
Description Write a program that prints out your name, the course ID of this class, what...
Description Write a program that prints out your name, the course ID of this class, what programming/computer courses you've taken. Ask the user for two numbers. Show the sum of the two numbers, the difference, the product and the quotient. For the difference subtract the second number from the first, for the quotient, use the first number as the numerator(dividend) and the second as the denominator(divisor). Sample Output: My name is Jianan Liu, I'm in course CS36. I've taken: C...
write a program to perform the following in C Your program should prompt the user to...
write a program to perform the following in C Your program should prompt the user to enter ten words, one at a time, which are to be stored in an array of strings. After all of the words have been entered, the list is to be reordered as necessary to place the words into alphabetical order, regardless of case. Once the list is in alphabetical order, the list should be output to the console in order. The program should execute...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT