Basic Assembly Homework: Operand Values and C Translations

School
New Jersey Institute Of Technology**We aren't endorsed by this school
Course
CS 350
Subject
Mechanical Engineering
Date
Dec 12, 2024
Pages
3
Uploaded by sa223489543
Homework 4 Basic Assembly Instructions1.Following the style of Practice Problem 3.1 (page.182), assume the following values arestored at the indicated memory addresses and registers:AddressValue--RegisterValue0x10000xAA--%rdi0x10000x10040xBB--%rsi0x10x10080xCC--%rdx0x20x100C0xDD--%rcx0x4Fill in the following table showing the values for the indicated operands:OperandValue%rdi0x10000x10040xBB$0x10080xCC(%rdi)0xAA4(%rdi)0xBB8(%rdi,%rcx)0xDD0x1002(%rdx,%rcx)0xCC-4(%rdi,%rsi,4)0xAA(%rdi,%rdx,4)0xCC2.Using the Address and Register table in Problem 1, fill in the table below showing thevalues for the indicated operands (similar to Practice Problem 3.8 of page 194):InstructionDestinationValueaddq (%rdi),%rsi%rsi0xAB
Background image
andq %rsi,%rdi%rdi1000subq %rsi,(%rdi)0x10000xA9incq %rsi%rsi0x2decq %rdx%rdx0x1xorq (%rdi,%rdx,4),%rcx%rcx0xC8orq 0x1002(%rdx,%rcx),%rsi%rsi0xCD3. For the unknown assembly shown below, fill in the missing return statement in the C functionunknown.unknown:imulq%rdx, %rsileaq(%rsi,%rdi), %raxretlong unknown(long x, long y, long z) {return ____(y*z)+x_______________________;}unknown:movq%rdi, %raxsalq$3, %raxaddq%rdi, %raxretlong unknown(long x) {return __(x*2^3)__________________________;}4. Do problem 3.58 which says "Write C code for the assembly shown in the problem."long decode2(longx, longy, long z){y=y-z;x=x*y;t=y;t=t<<63;rt=t>>63;t=t^x;
Background image
return t;}5. Write an assembly program to perform the C function below using the following registerassignment:x:rdi; y:rsi, z:rdx, t1:rcx, t2:rdi, t3:rsi, t4:raxNo credit will be given to the ones with stack addresses.long arith(long x, long y, long z) {long t1,t2,t3,t4;t1 = x + y;t2 = t1 - z;t3 = t1 & t2;t4 = t2 * t3;return t4;}Answer:arith:movq rdi, rcxaddq rsi, rcxmovq rcx,rdisubq rdx,rdimovq rcx, rsiandq rdi,rsimovq rdi, raximulq rsi,raxret
Background image