EBK COMPUTER SYSTEMS
EBK COMPUTER SYSTEMS
3rd Edition
ISBN: 8220101459107
Author: O'HALLARON
Publisher: YUZU
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

Chapter 4 Solutions

EBK COMPUTER SYSTEMS

Knowledge Booster
Background pattern image
Recommended textbooks for you
Text book image
Computer Networking: A Top-Down Approach (7th Edi...
Computer Engineering
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:PEARSON
Text book image
Computer Organization and Design MIPS Edition, Fi...
Computer Engineering
ISBN:9780124077263
Author:David A. Patterson, John L. Hennessy
Publisher:Elsevier Science
Text book image
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:9781337569330
Author:Jill West, Tamara Dean, Jean Andrews
Publisher:Cengage Learning
Text book image
Concepts of Database Management
Computer Engineering
ISBN:9781337093422
Author:Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:Cengage Learning
Text book image
Prelude to Programming
Computer Engineering
ISBN:9780133750423
Author:VENIT, Stewart
Publisher:Pearson Education
Text book image
Sc Business Data Communications and Networking, T...
Computer Engineering
ISBN:9781119368830
Author:FITZGERALD
Publisher:WILEY