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 3, Problem 3.72HW

A.

Explanation of Solution

Given Assembly code:

# long aframe(long n, long idx, long *q)

# n in %rdi, idx in %rsi, q in %rdx

aframe:

  pushq %rbp

  movq %rsp, %rbp

  subq $16, %rsp

  leaq 30(,%rdi,8), %rax

  andq $-16, %rax

  subq %rax, %rsp

  leaq 15(%rsp), %r8

  andq $-16, %r8

Explanation:

  • The instruction “pushq %rbp” creates a stack element and pushes stack pointer.
  • The instruction “movq %rsp, %rbp” stores stack pointer into “%rbp”.
  • The instruction “subq $16, %rsp” allocates space for “i”.
    • It sets “s1” in “%rsp”.
  • The instruction “leaq 30(,%rdi,8), %rax” loads value at offset “8*%rdi+30 ” into register “%rax”.
  • The instruction “andq $-16, %rax” performs “AND” operation between given immediate value and value in register “%rax”.
  • The instruction “subq %rax, %rsp” allocates space for array “p”.
    • It sets “s2” in “%rsp”.
  • The instruction “leaq 15(%rsp), %r8” loads value at offset “%rsp+15 ” into register “%r8”

B.

Explanation of Solution

Logic in computation of p:

  • The expression for “p” is shown below:

    p=(s2 +15)&0

C.

Explanation of Solution

Values of n and s1:

  • The details of values are shown below:
whiche1ns1
Minimum1evenn%16==1
Maximum24oddn%16==0
  • The details of minimum case are shown below:
    • The “e1” cannot be 0, if “e1” equals 0, “p” should be equal to “s2”.
    • When “n” is even, “e1+e2==16”, if “e2” is 15, “e1” will be minimum value.
    • Hence, “s1==n” and “n%16==1

D.

Explanation of Solution

Alignment properties:

  • The value “p” is been aligned by 16.
  • The value “s2” denotes least multiple of 16...

Blurred answer
Students have asked these similar questions
Draw the stack frame just before the RET instruction in the swap function is executed in the code shown below:
Programming Language Pragmatics, 4th Edition
In this problem we want to modify the single cycle datapath shown below (also in in slide #1 of "chapter3_single_cycle_datapaths.pptx") so that it supports execution of a new instruction called jump register (jr). PC Add Read address Instruction [31:0) Instruction [25:21) Instruction [20:16] Instruction Instruction [15:11] memory (DMUXT RegDst Instruction [15:0] RegWrite Read register 1 Read register 2 Read data 1 Write Read register data 2 Write data Registers 16 Sign- extend Instruction [5:0] 32 Shift left 2/ ALUSrc (OMUXI) ALU Addresult Zero ALU ALU result ALU control ALUOP #copy contents of "rs" register to PC (PC = $rs) PCSrc ( E3X MemWrite Read data Address Data Write memory data MemRead MemtoReg (-MUXO) jr $rs You are allowed to add new control signal(s), wire(s), muxe(s) to support this instruction. First briefly explain the required modifications. Then indicate the value of each control signal (RegDst, RegWrite, ALUSrc, ALUOP, MemRead, Mem Write, MemToReg). You must use "X"…

Chapter 3 Solutions

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

Ch. 3.5 - Prob. 3.11PPCh. 3.5 - Prob. 3.12PPCh. 3.6 - Prob. 3.13PPCh. 3.6 - Prob. 3.14PPCh. 3.6 - Prob. 3.15PPCh. 3.6 - Prob. 3.16PPCh. 3.6 - Practice Problem 3.17 (solution page 331) An...Ch. 3.6 - Practice Problem 3.18 (solution page 332) Starting...Ch. 3.6 - Prob. 3.19PPCh. 3.6 - Prob. 3.20PPCh. 3.6 - Prob. 3.21PPCh. 3.6 - Prob. 3.22PPCh. 3.6 - Prob. 3.23PPCh. 3.6 - Practice Problem 3.24 (solution page 335) For C...Ch. 3.6 - Prob. 3.25PPCh. 3.6 - Prob. 3.26PPCh. 3.6 - Practice Problem 3.27 (solution page 336) Write...Ch. 3.6 - Prob. 3.28PPCh. 3.6 - Prob. 3.29PPCh. 3.6 - Practice Problem 3.30 (solution page 338) In the C...Ch. 3.6 - Prob. 3.31PPCh. 3.7 - Prob. 3.32PPCh. 3.7 - Prob. 3.33PPCh. 3.7 - Prob. 3.34PPCh. 3.7 - Prob. 3.35PPCh. 3.8 - Prob. 3.36PPCh. 3.8 - Prob. 3.37PPCh. 3.8 - Prob. 3.38PPCh. 3.8 - Prob. 3.39PPCh. 3.8 - Prob. 3.40PPCh. 3.9 - Prob. 3.41PPCh. 3.9 - Prob. 3.42PPCh. 3.9 - Practice Problem 3.43 (solution page 344) Suppose...Ch. 3.9 - Prob. 3.44PPCh. 3.9 - Prob. 3.45PPCh. 3.10 - Prob. 3.46PPCh. 3.10 - Prob. 3.47PPCh. 3.10 - Prob. 3.48PPCh. 3.10 - Prob. 3.49PPCh. 3.11 - Practice Problem 3.50 (solution page 347) For the...Ch. 3.11 - Prob. 3.51PPCh. 3.11 - Prob. 3.52PPCh. 3.11 - Practice Problem 3.52 (solution page 348) For the...Ch. 3.11 - Practice Problem 3.54 (solution page 349) Function...Ch. 3.11 - Prob. 3.55PPCh. 3.11 - Prob. 3.56PPCh. 3.11 - Practice Problem 3.57 (solution page 350) Function...Ch. 3 - For a function with prototype long decoda2(long x,...Ch. 3 - The following code computes the 128-bit product of...Ch. 3 - Prob. 3.60HWCh. 3 - In Section 3.6.6, we examined the following code...Ch. 3 - The code that follows shows an example of...Ch. 3 - This problem will give you a chance to reverb...Ch. 3 - Consider the following source code, where R, S,...Ch. 3 - The following code transposes the elements of an M...Ch. 3 - Prob. 3.66HWCh. 3 - For this exercise, we will examine the code...Ch. 3 - Prob. 3.68HWCh. 3 - Prob. 3.69HWCh. 3 - Consider the following union declaration: This...Ch. 3 - Prob. 3.71HWCh. 3 - Prob. 3.72HWCh. 3 - Prob. 3.73HWCh. 3 - Prob. 3.74HWCh. 3 - Prob. 3.75HW
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
  • Text book image
    Systems Architecture
    Computer Science
    ISBN:9781305080195
    Author:Stephen D. Burd
    Publisher:Cengage Learning
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning