Please Do it ASPS. Thanks 1. Consider the following C code: long func(long x, long m, long n) { long result =

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Please Do it ASPS. Thanks 1. Consider the following C code: long func(long x, long m, long n) { long result =

Post by answerhappygod »

Please Do it ASPS. Thanks
1. Consider the following C code:
long func(long x, long m, long n)
{
long result = 0;
int p = 1;
int q = 10

if ((x > m) && (x < n)){
p = p + m;
q = q + n;
}
else
p = p * m;
q = q * n;

result = p – q;
return result;
}

• Rewrite the code and replace the if-else with ‘goto’ statements.

• Write the assembly code that corresponds to the C ‘goto’ version.

• Compile the C code to assembly using gcc compiler and see how
your code compares
with the compiler version.
2. Assume the following values are stored at the indicated
memory addresses and registers:
Address Value
Register Value

0x200 0xFF
%rax
0x200
0x204 0xAA
%rcx
0x1
0x208 0x11
%rdx
0x3
0x20C 0x13

Fill in the following table showing the values for the
indicated operands:

Operand

Value
addq %rcx,(%rax)
-----------
subq %rdx,4(%rax)
-----------
imulq $16, (%rax,%rdx,4)
-----------
incq 8(%rax)

--------------
decq %rcx

---------------
subq %rdx,%rax
-------------------
xorq %rdx,%rdx
-----------------
sarq 3, %rdx
--------------
notq %rdx

----------------------------
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply