CS350 Intro Computer Systems Homework 4

Homework 4 Basic Assembly Instructions

  1. Following the style of Practice Problem 3.1 (page.182), assume the following values are stored at the indicated memory addresses and registers:
    AddressValue--RegisterValue
    0x10000xAA--%rdi0x1000
    0x10040xBB--%rsi0x1
    0x10080xCC--%rdx0x2
    0x100C0xDD--%rcx0x4

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

    OperandValue
    %rdi
    0x1004
    $0x1008
    (%rdi)
    4(%rdi)
    8(%rdi,%rcx)
    0x1002(%rdx,%rcx)
    -4(%rdi,%rsi,4)
    (%rdi,%rdx,4)

  2. Using the Address and Register table in Problem 1, fill in the table below showing the values for the indicated operands (similar to Practice Problem 3.8 of page 194):

    InstructionDestinationValue
    addq (%rdi),%rsi
    andq %rsi,%rdi
    subq %rsi,(%rdi)
    incq %rsi
    decq %rdx
    xorq (%rdi,%rdx,4),%rcx
    orq 0x1002(%rdx,%rcx),%rsi

  3. For the unknown assembly shown below, fill in the missing return statement in the C function unknown.
      unknown:
    	imulq	%rdx, %rsi
    	leaq	(%rsi,%rdi), %rax
    	ret
    
      long unknown(long x, long y, long z) {
            return ____________________________;
      }
      
      unknown:
    	movq	%rdi, %rax
    	salq	$3, %rax
    	addq	%rdi, %rax
    	ret
    
      long unknown(long x) {
            return ____________________________;
      }
      
  4. Do problem 3.58 which says "Write C code for the assembly shown in the problem."
  5. Write an assembly program to perform the C function below using the following register assignment:
    x:rdi; y:rsi, z:rdx, t1:rcx, t2:rdi, t3:rsi, t4:rax
    No 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;
    }