Computer Systems: Program... -Access
Computer Systems: Program... -Access
3rd Edition
ISBN: 9780134071923
Author: Bryant
Publisher: PEARSON
Question
Book Icon
Chapter 4, Problem 4.46HW

A.

Program Plan Intro

Given Assembly code:

movq (%rsp), REG

addq $8, %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.

B.

Program Plan Intro

Given Assembly code:

movq (%rsp), REG

addq $8, %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.

Blurred answer
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
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.
For the (pseudo) assembly code below, replace X, Y, P, and Q with thesmallest set of instructions to save/restore values on the stack and update the stackpointer. Assume that procA and procB were written independently by two differentprogrammers who are following the MIPS guidelines for caller-saved and callee-savedregisters. In other words, the two programmers agree on the input arguments andreturn value of procB, but they can't see the code written by the other person.   procA:$s0 = ...$s1 = ...$s2 = ...$t0 = ...$t1 = ...$t2 = ...X$a0 = ...$a1 = ...jal procBY... = $s1... = $t0... = $t1... = $a0jr $raprocB:P... = $a0... = $a1$s2 = ...$t0 = ...Qjr $ra

Chapter 4 Solutions

Computer Systems: Program... -Access

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