Computer Systems: A Programmer's Perspective Plus Mastering Engineering With Pearson Etext -- Access Card Package (3rd Edition)
Computer Systems: A Programmer's Perspective Plus Mastering Engineering With Pearson Etext -- Access Card Package (3rd Edition)
3rd Edition
ISBN: 9780134123837
Author: Randal E. Bryant, David R. O'Hallaron
Publisher: PEARSON
Question
Book Icon
Chapter 4, Problem 4.45HW

A.

Program Plan Intro

Given Assembly code:

subq $8, %rsp

movq REG, (%rsp)

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.

Unary and Binary Operations:

  • The details of unary operations includes:
    • The single operand functions as both source as well as destination.
    • It can either be a memory location or a register.
    • The instruction “incq” causes 8 byte element on stack top to be incremented.
    • The instruction “decq” causes 8 byte element on stack top to be decremented.
  • The details of binary operations includes:
    • The first operand denotes the source.
    • The second operand works as both source as well as destination.
    • The first operand can either be an immediate value, memory location or register.
    • The second operand can either be a register or a memory location.

Jump Instruction:

  • The “jump” instruction causes execution to switch to an entirely new position in program.
  • The “label” indicates jump destinations in assembly code.
  • The “je” instruction denotes “jump if equal” or “jump if zero”.
    • The comparison operation is performed.
    • If result of comparison is either equal or zero, then jump operation takes place.
  • The “ja” instruction denotes “jump if above”.
    • The comparison operation is performed.
    • If result of comparison is greater, then jump operation takes place.
  • The “pop” instruction resumes execution of jump instruction.
  • The “jmpq” instruction jumps to given address. It denotes a direct jump.

A.

Expert Solution
Check Mark

Explanation of Solution

Behavior of instruction pushq:

  • No, the given code sequence is not correctly describes the behavior of given instruction.
  • The instruction “subq $8, %rsp” subtracts 8 from value of “%rsp”.
  • If “REG” denotes “%rsp” then it computes “%rsp-8”.
  • The instruction “movq REG, (%rsp)” moves value of “REG” into location of “(%rsp)”.
  • The value “%rsp-8” is been pushed into stack instead of “%rsp”.
  • Hence, it does not describe behavior of instruction “pushq %rsp”.

B.

Program Plan Intro

Given Assembly code:

subq $8, %rsp

movq REG, (%rsp)

Processing stages:

  • The processing of an instruction has number of operations.
  • The operations are organized into particular sequence of stages.
  • It attempts to follow a uniform sequence for all instructions.
  • The description of stages are shown below:
    • Fetch:
      • It uses program counter “PC” as memory address to read instruction bytes from memory.
      • The 4-bit portions “icode” and “ifun” of specifier byte is extracted from instruction.
      • It fetches “valC” that denotes an 8-byte constant.
      • It computes “valP” that denotes value of “PC” plus length of fetched instruction.
    • Decode:
      • The register file is been read with two operands.
      • It gives values “valA” and “valB” for operands.
      • It reads registers with instruction fields “rA” and “rB”.
    • Execute:
      • In this stage the ALU either performs required operation or increments and decrements stack pointer.
      • The resulting value is termed as “valE”.
      • The condition codes are evaluated and destination register is updated based on condition.
      • It determines whether branch should be taken or not in a jump instruction.
    • Memory:
      • The data is been written to memory or read from memory in this stage.
      •  The value that is read is determined as “valM”.
    • Write back:
      • The results are been written to register file.
      • It can write up to two results.
    • PC update:
      • The program counter “PC” denotes memory address to read bytes of instruction from memory.
      • It is used to set next instruction’s address.

B.

Expert Solution
Check Mark

Explanation of Solution

Modified code:

movq REG, -8(%rsp)

subq $8, %rsp

Explanation:

  • The instruction “movq REG, -8(%rsp)” moves value of “REG” into location of “(%rsp)-8”.
  • The instruction “subq $8, %rsp” subtracts 8 from value of “%rsp”.
  • If “REG” denotes “%rsp” then it computes “%rsp”.
  • The value “%rsp” is now been pushed into stack.
  • Hence, it describes behavior of instruction “pushq %rsp”.

Want to see more full solutions like this?

Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Write MIPS assembly for the following function. Assume N is passed to yourfunction in register $a0. Your output should be in register $v0 at the end of yourfunction. Note: You must implement this function recursively. The purpose of thisassignment is to learn how to manipulate the stack correctly in MIPS. int Myfun (int N){ if (N<3) return 1; return ( 2* Myfun(N-1)+ Myfun(N-2));}Please explain each instruction with a comment. Please submit your source codeand a screenshot that shows the registers with correct output value for N=3, i.e.,Myfun(3) returns 3 and Myfun(4) returns 7
This problem is adapted from an earlier edition of P&H, and should be submitted.Consider the following code used to implement a new instruction: foo $t3,$t1,$t2:mask : . word 0xFFFFF83Fs t a r t : l a $t0 , masklw $t0 , 0 ( $ t 0 )l a $t3 , s h f t rlw $t3 , 0 ( $ t 3 )and $t3 , $t3 , $ t 0a ndi $t2 , $t2 , 0 x 0 0 1 fs l l $t2 , $t2 , 6o r $t3 , $t3 , $ t 2l a $t5 , s h f t rsw $t3 , 0 ( $ t 5 )s h f t r : s l l $t3 , $t1 , 0Add meaningful comments to the code and write a brief (2 sentence max) description of what foo does. Thisis not the same as saying how it does it - e.g., when asked to describe what a pedestrian is doing, you wouldsay they are walking, not that they are ilfting their left leg, angling it forward, putting it down, . . ..State at least one reason why writing “self-modifying code” such as this is a bad idea (and often times notactually allowed by the operating system)?
write a subroutine (in assembly) for ARMcortex-A9 that 1. accepts a memory address A passed in register r0 2. Sum the words incrementing from address A, until the accumulating sum would be considered a negative number ( A is first address read). 3. Return the final value in r 0 . Should preserve state of system using the stack pointer (sp). If you are unable to write Assembly code to complete this problem, please use comments and/or pseudocode as much as possible to describe what should be done.

Chapter 4 Solutions

Computer Systems: A Programmer's Perspective Plus Mastering Engineering With Pearson Etext -- Access Card Package (3rd Edition)

Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education