In: Computer Science
Must use AT&T x64/GNU Assembly syntax.
Write an assembly language program that reads in two integers, A and B, and uses them to compute the following expressions. You must use the same values for A and B throughout all three expressions.
1) A * 5
2) (A + B) - (A / B)
3) (A - B) + (A * B)
The given first expression is:
1) A*5
Let X=A*5
Therfore, GNU Assembly syntax for the above expession can be written as:
MOV(A, eax);
MUL(5, eax:edx);
Mov(edx, X);
____________________________________________________________________________________________
The given second expression is:
2) (A+B)-(A/B)
Let X: (A+B)-(A/B)
Therfore, GNU Assembly syntax for the above expession can be written as:
MOV(A, eax);
ADD(B, eax);
MOV(eax, Temp1);
MOV(A, eax);
DIV(B, eax);
MOV(eax, Temp2);
MOV(Temp1, eax);
SUB(Temp2, eax);
MOV(eax, x);
____________________________________________________________________________________________
The given third expression is:
3) (A-B)+(A*B)
Let X: (A-B)+(A*B)
Therfore, GNU Assembly syntax for the above expession can be written as:
MOV(A, eax);
SUB(B, eax);
MOV(eax, Temp1);
MOV(A,eax);
MUL(B, eax);
MOV(eax, Temp2);
MOV(Temp1, eax);
ADD(Temp2, eax);
MOV(eax, x)
____________________________________________________________________________________________
Here, we have assigned 32 bit signed integer value to register eax in all the expressions.