Question: Rules: The answer must be stored in a variable of the correct data type given your data. The values for your data (A, B, C,
Rules:
- The answer must be stored in a variable of the correct data type given your data.
- The values for your data (A, B, C, D) must be stored in register (e.g. eax, ebx), not variables.
- You must supply the initial values for the data (A, B, C, D).
- Create a string that could accompany the answer in an output statement.
- Comment each line of your code as Demonstrated in Program 3.2 (I know I said not to do this, but for the first assignment it is better is you figure out the usage of every line)
C++ code:
int main()
{
int answer = 0;
// A, B, C, D should be replaced by any number,
// for example A = 1, B = 2, C = 3, D = 4 or any other set of values
answer = (A + B) (C + D);
return 0;
}
How will you know the program is correct?
Take any set of 4 values for example 1, 2, 3, 4 for A, B, C, D. If that is true then the operation (A + B) (C + D) will have to store (1 + 2) (3 + 4) = -4 or FFFFFFFC in hex. Make sure the answer variable is storing that value by debugging your program and directly check the value stored.
Template for NASM
| SECTION .data |
| ; Write your data definitions here |
|
|
| SECTION .text |
| global _main |
| _main: |
| ; Write your code here
|
| mov eax, 1 |
| mov ebx, 0 |
| int 80h |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
