COMPUTER SYSTEMS&MOD MSGT/ET SA AC PKG
COMPUTER SYSTEMS&MOD MSGT/ET SA AC PKG
3rd Edition
ISBN: 9780134671123
Author: Bryant
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
In this lab, we write function binary_search in RISC-V. The prototype of the function and an implementation in C is at the end of this page. Translate the C code at the bottom of the page to RISC-V assembly code. The skeleton code is in lab4.s. Function binary_search is located at the end of the file. It is empty in the skeleton code. There are some constraints/tips. 1. To ensure we do not use pseudoinstructions, we turn off the feature in RARs. In Settings, uncheck "Permit extended (pseudo) instructions and formats". 2. Follow the C code closely. Although binary search is simple, it is very easy to make mistakes if you have not written it many times. 3. We keep variable left in register s1. Other local variables do not have to be in a saved register. Think about why we need to keep left, but not other variables, in a saved register. 4. There should be only one exit (one return instruction) in the function. In the C code, we use goto f_exit on purpose. With one exit, we do not have…
Consider the following generic C comparison function and its assembly language representation: C: byte comp (byte a, byte b); // a in rdi, b in rei Assembly: cmpb set_inst ret Srdi, trsi Bal Now show how the condition flags will be set with the corresponding SET instruction and the given values of a and b.. View Available Hint(s) 0 set_inst setne setb setge seta a14x49 10 375 49 46 Oxaa b -101 0x53 -46 CF 0 0 1 N ZF 0 0 0 SF 0 1 0 OF 0 0 0 Reset al 1 1 Help
Programming Language Pragmatics, 4th Edition

Chapter 3 Solutions

COMPUTER SYSTEMS&MOD MSGT/ET SA AC PKG

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