Question: in ASM language please! In this lab we are going to work on some simple and maybe not so simple arithmetic operators. In this lab
in ASM language please!
In this lab we are going to work on some simple and maybe not so simple arithmetic operators. In this lab you are going to take in from the keyboard two WORD values. You will then output the sum, difference, product, and quotient of those two numbers. In other words, add, subtract, multiply, and divide the two numbers. You should also output the remainder of the division.
Here are the steps:
- Create a prompt that will output \"Enter a number\". In the data segment
- Create output messages \"Sum: \", \"Diff : \", \"Prod: \", \"Quot: \", \"Rem: \" as literal strings in the data segment
- Create two WORD variables called val1 and val2. Initialize them to undefined
- Write the prompt to the screen
- Input a number
- Store the number in the val1 variable
- Write the prompt to the screen
- Input a number
- Store the number in the val2 variable
- Add val1 to val2
- Output the \"Sum: \" message
- Output the sum of the two numbers.
- Subtract val2 from val1
- Output the \"Diff : \" message
- Output the difference of the two numbers
- Multiply val1 and val2
- Output the \"Prod: \" message
- Output the product of the two numbers
- Divide val1 by val2
- Output the \"Quot: \" message
- Output the quotient of the two numbers
- Output the \"Rem: \" message
- Output the remainder of the division
The above steps are not really detailed. So there are a couple of things to consider
- When moving a variable to the ax register for arithmetic. It might be best to use movzx. Otherwise you will have to clear the eax register
- When doing division the edx holds the remainder. This is problematic because we use the edx to output strings. Once the division is done you need to store the remainder somewhere until you need to output it. You might want to consider another register for this.
- The writeString procedure does not place a newline at the end. The writeLine procedure does.
- The macro endl writes a new line. The macro cls clears the screen.
The output of your program should look like the following:
Enter a number 22 Enter a number 10 Sum: 32 Diff: 12 Prod: 220 Quot: 2 Remainder: 2 Press any key to close this window . . .
The above values of 22 and 10 are simply an example. Your program should allow the user to type in any two whole numbers.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
