Computer Systems: A Programmer's Perspective (3rd Edition)
Computer Systems: A Programmer's Perspective (3rd Edition)
3rd Edition
ISBN: 9780134092669
Author: Bryant, Randal E. Bryant, David R. O'Hallaron, David R., Randal E.; O'Hallaron, Bryant/O'hallaron
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
The programming language:  C++ The union of two ordered lists (Sequential linear list)[the solution introduction: The first video of in 3.1, 35:00-43:00] [Problem description] Give the union of two ordered lists. The maximal number of elements in an inputted set is 30. [Basic requirements] 1) Use sequential linear list. 2) The result list should also be ordered. [Example] Problem: Give the union of the ordered lists (3,4,9,100,103) and (7,9,43,53,102,105). What you need to show in the terminal(the back part is outputted by you and the blue part is inputted by the user, i.e., teacher): Please input the first ordered list: (3,4,9,100,103)Please input the second ordered list: (7,9,43,53,102,105) The union is: (3,4,7,9,9,43,53,100,102,103,105)
(Base Indexed Memory Addressing Mode) Only at [{DS | SS | ES}: {SI | DI} + {BX + BP}] BA EA There is a combination between (Base and Index) in Effective Add. (EA) Ex. Described each line and write down the equation of physical add. For the following assembly code: 01 org 100 02 MOV [BX+DI], CL 03 MOV CH, [вх+SI) 04 MOV AH, [BP+DI] 05 MOV [BP+SI], AL 06 ret
[1] ( Show your work. Show hoe you compute memory address by using the effective memory address computation. Assume the following values are stored at the indicated memory addresses and registers: Address Value 0x100 OxFF 0x104 OxAB 0x108 0x13 0x10c 0x11 Register %rax %rcx %rdx $0x108 (%rax) 4(%rax) 9(%rax, %rdx) 260(%rcx,%rdx) OxFC (,%rcx, 4) (%rax, %rdx, 4) Value 0x100 0x1 0x3 Fill in the following table showing the values for the indicated operands: Operand Value %rax 0x104

Chapter 4 Solutions

Computer Systems: A Programmer's Perspective (3rd Edition)

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