Computer Systems: Program... -Access
Computer Systems: Program... -Access
3rd Edition
ISBN: 9780134071923
Author: Bryant
Publisher: PEARSON
Expert Solution & Answer
Book Icon
Chapter 4.1, Problem 4.4PP

Explanation of Solution

Given C code:

long rsum(long *start, long count)

{

if(count <= 0)

return 0;

return *start + rsum(start+1, count-1);

}

Data movement instructions:

  • The different instructions are been grouped as “instruction classes”.
  • The instructions in a class performs same operation but with different sizes of operand.
  • The “Mov” class denotes data movement instructions that copy data from a source location to a destination.
  • The class has 4 instructions that includes:
    • movb:
      • It copies data from a source location to a destination.
      • It denotes an instruction that operates on 1 byte data size.
    • movw: 
      • It copies data from a source location to a destination.
      • It denotes an instruction that operates on 2 bytes data size.
    • movl:
      • It copies data from a source location to a destination.
      • It denotes an instruction that operates on 4 bytes data size.
    • movq:
      • It copies data from a source location to a destination.
      • It denotes an instruction that operates on 8 bytes data size.

Corresponding x86-64 code:

long rsum(long *start, long count)

start in %rdi, count in %rsi

rsum:

movl $0, %eax     

testq %rsi, %rsi

jle .L9

pushq %rbx

movq (%rdi),%rbx

subq $1, %rsi

addq $8, %rdi

call rsum

addq %rbx, %rax

popq %rbx

.L9:

rep; ret

Explanation:

  • The instruction “movl $0, %eax” initializes value in register “%eax” to 0.
  • The instruction “testq %rsi, %rsi” checks for count to be zero.
  • The instruction “jle .L9” jumps to label “.L9” if first value is less than or equal to second.
  • The instruction “pushq %rbx” saves callee-saved register.
  • The instruction “movq (%rdi),%rbx” moves value at location of register “%rdi” to register “%rbx”.
  • The instruction “subq $1, %rsi” decrements value of “count” stored in register “%rsi”...

Blurred answer
Students have asked these similar questions
Here is my question from homework: int x; short y, z; cin>>x; y=x; z= y+2; cout<<"First number is: "<<x<<endl; cout<<"Second number is: "<<y<<endl; cout<<"Third number is: "<<z<<endl; End of HW problem My question is how do I utilize short variable type in MIPS assembly code and get it to work with int data type?
4.1.1 Complete solution and answer only no need explanation Given three data points (1,6), (3,28), and (10, 231), What is the value of y at x = 2 if the function y = 2x2 + 3x + 1 passes through the three data points.
1. We wish to compare the performance of two different machines: M1 and M2. The following measurements have been made on these machines:   Program Time on M1 Time on M2 1 10 seconds 5 seconds 2 3 seconds 4 seconds Which machine is faster for each program, and by how much?   2. For M1 and M2 of problem 1, the following additional measurements are made:. Find the instruction execution rate (instructions per second) for each machine when running program 1.   Program Instructions executed on M1 Instructions executed on M2 1 200 x 106 160 x 106   3. For M1 and M2 of problem 1, if the clock rates are 200 MHz and 300 MHz, respectively, find the CPI for program 1 on both machines using the data provided in problems 1 and 2.   4. You are going to enhance a machine, and there are two possible improvements: either make multiply instructions run four times faster than before or make memory access instructions run two times faster than before. You…

Chapter 4 Solutions

Computer Systems: Program... -Access

Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr