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
expand_more
expand_more
format_list_bulleted
Question
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.
- movb:
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
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.
- Fetch:
B.
Expert Solution
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
In x86-64 assembly, how many registers do we have, and can we use registers like %rsp for anything we like?
Group of answer choices
A. We get 8664 general-purpose registers. Registers are like variables in assembly where we can store information. We can in theory use them for whatever we want, however we do need to follow conventions in order for our program to operate without errors (%rsp for example keeps track of the stack pointer).
B. We get unlimited general-purpose registers. Registers are like variables in assembly where we can store information. We can use them for whatever we want.
C. We get 16 general-purpose registers. Registers are like variables in assembly where we can store information. We can in theory use them for whatever we want, however we do need to follow conventions in order for our program to operate without errors (%rsp for example keeps track of the stack pointer).
Writing for gnu(at&t) assembly
Copy the top 2 words from the stack into registers AX and CX respectively. Do this without changing the stack pointer(dont use pop) Use BP as the base register. Place the following code at thebeginning of your program:mov dx, 1234Hpush dxmov dx, 0ABCDHpush dx
Given the typical stack frame set up, what will be in edx after executing this instruction:
mov edx, [ebp + 4]?
Hint: It is NOT any of the selections above.
Chapter 4 Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
Ch. 4.1 - Prob. 4.1PPCh. 4.1 - Prob. 4.2PPCh. 4.1 - Prob. 4.3PPCh. 4.1 - Prob. 4.4PPCh. 4.1 - Prob. 4.5PPCh. 4.1 - Prob. 4.6PPCh. 4.1 - Prob. 4.7PPCh. 4.1 - Prob. 4.8PPCh. 4.2 - Practice Problem 4.9 (solution page 484) Write an...Ch. 4.2 - Prob. 4.10PP
Ch. 4.2 - Prob. 4.11PPCh. 4.2 - Prob. 4.12PPCh. 4.3 - Prob. 4.13PPCh. 4.3 - Prob. 4.14PPCh. 4.3 - Prob. 4.15PPCh. 4.3 - Prob. 4.16PPCh. 4.3 - Prob. 4.17PPCh. 4.3 - Prob. 4.18PPCh. 4.3 - Prob. 4.19PPCh. 4.3 - Prob. 4.20PPCh. 4.3 - Prob. 4.21PPCh. 4.3 - Prob. 4.22PPCh. 4.3 - Prob. 4.23PPCh. 4.3 - Prob. 4.24PPCh. 4.3 - Prob. 4.25PPCh. 4.3 - Prob. 4.26PPCh. 4.3 - Prob. 4.27PPCh. 4.4 - Prob. 4.28PPCh. 4.4 - Prob. 4.29PPCh. 4.5 - Prob. 4.30PPCh. 4.5 - Prob. 4.31PPCh. 4.5 - Prob. 4.32PPCh. 4.5 - Prob. 4.33PPCh. 4.5 - Prob. 4.34PPCh. 4.5 - Prob. 4.35PPCh. 4.5 - Prob. 4.36PPCh. 4.5 - Prob. 4.37PPCh. 4.5 - Prob. 4.38PPCh. 4.5 - Prob. 4.39PPCh. 4.5 - Prob. 4.40PPCh. 4.5 - Prob. 4.41PPCh. 4.5 - Prob. 4.42PPCh. 4.5 - Prob. 4.43PPCh. 4.5 - Prob. 4.44PPCh. 4 - Prob. 4.45HWCh. 4 - Prob. 4.46HWCh. 4 - Prob. 4.47HWCh. 4 - Prob. 4.48HWCh. 4 - Modify the code you wrote for Problem 4.47 to...Ch. 4 - In Section 3.6.8, we saw that a common way to...Ch. 4 - Prob. 4.51HWCh. 4 - The file seq-full.hcl contains the HCL description...Ch. 4 - Prob. 4.53HWCh. 4 - The file pie=full. hcl contains a copy of the PIPE...Ch. 4 - Prob. 4.55HWCh. 4 - Prob. 4.56HWCh. 4 - Prob. 4.57HWCh. 4 - Our pipelined design is a bit unrealistic in that...Ch. 4 - Prob. 4.59HW
Knowledge Booster
Similar questions
- 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"…arrow_forwardi need the answer quicklyarrow_forwardSay we have a function that takes 8 arguments: long foo (long one, long two, long thr, long fou, long fiv, long six, long sev, long eig); Screen Shot 2021-10-2... Stack Following the x86-64 calling conventions, any arguments past the 6th have to be stored on the Stack. Write an assembly instruction (that would appear inside of foo) to copy the value of eig into the return register. Assume that this is the first instruction to be executed after foo is called. Tips: It may help you to draw out what the Stack will look like at the beginning of foo . Answer using the form: " , " with a single space between each of the three parts and include the instruction suffix.arrow_forward
- From 61: current values in stack segment register and stack pointer: C00016 & FF0016. address of the current top of the stack CFF00arrow_forwardWhat is the contents of the stack after executing the instruction marked by * for the second time .org Ox00 LDI R16, HIGH(RAMEND) OUT SPH, R16 LDI R16, LOW(RAMEND) OUT SPL, R16 LDI R17, 0 CALL L1 CALL L2 CALL L3 HERE: JMP HERE .org 0x100 L1: INC R17 CALL L2 INC R17 RET .org 0x200 L2: INC R17 * CALL L3 INC R17 RET .org 0x300 L3: INC R17 RETarrow_forwardThe content of the stack pointer SP is 3560, and the register PC contains the value 2000. The location 2000 contains the two word instruction BSR 2500. Given that the size of the stack frame is 4 bytes, and that each instruction(along with the data it uses) is 4 bytes long, what is the value contained in SP immediately after the BSR instruction is executed? Select one: а. 2500 O b. 3556 O C. None of these choices d. 2004 O e504arrow_forward
- Explain the Register stack organization of 32 locations of the stack (0 to 31 ). take the initial value of the stack pointer is SP = 09 in Hex. Explain the following push and pop instructions through the Register stack organization diagram.(1) PUSH R2 WHERE R2 = XX in Hex(2) POP R1 WHERE R1 = (XX + 5 ) in Hex where XX is your class roll no , for example roll no 64 is having the data in R2 = 64 Hex and R1=( 64+5 = 69 Hex)arrow_forwardThe correct optionarrow_forward5. Below is a depiction of a loop in instruction memory address Охо TOP: instruction 1 Ox4 instruction 2 Ox8 instruction 3 OxC instruction 4 Ох10 conditional branch to TOP Assume that the branch target buffer is initially empty, and the prediction bits are set to Strongly Taken (ST). Fill in the blanks On the first pass through the loop we take the branch. The branch target bits are now We suffer stalls. On the second pass through the loop we don't take the branch. The branch target bits are now We suffer stalls. On the third pass through the loop we don't take the branch. The branch target bits are now We suffer stalls. On the fourth pass through the loop we don't take the branch. The branch target bits are now We suffer stalls.arrow_forward
- In some instruction sets, call and return instructions make use of a RR register to hold the return address rather than doing so on the stack. Show how the code in the above problem should be changed if call and return instructions used a RR register for return addresses rather than the stack. Don't change the program's function. 500 MOV R1, X 501 MOV R2, Y 502 MOV R3, Z 503 PUSH R1 504 CALL 550 505 POP R3 506 CALL 560 507 HALT · · 550 PUSH R2 551 CALL 560 552 POP R2 553 RET · · 560 PUSH R3 561 PUSH R1 562 POP R2 563 POP R1 564 RETarrow_forwardThe 32-bit RISC-V base integer instruction set (rv32i) does not support multiplication and division operations. To deal with this, a compiler may call a function when a multiplication is needed. For example, gcc expects that a function - mulsi3(unsigned int a, unsigned int b) is provided to multiply two integers. A multiplication can be carried out by repeated additions and shifts: unsigned int -_mulsi3 (unsigned int a, unsigned int b) { unsigned int r = 0; while (a) { if (a & 1) { r += b; } a >>= 1; b <<= 1; } return r; } a) Translate the above C code into equivalent RISC-V rv32i assembler code. Comment the as- sembler code to explain how the calculation proceeds. Note that the arguments are passed via the registers a0 (x10) and a1 (x11) and that the result is returned in a0 (x10). b) Does the function need function call prolog and epilog? Explain why or why not. You are invited to use emulsiV to develop and test your assembler code.arrow_forwardConsider a hypothetical computer having instruction length 32 bit and Byte addressable memory. You need to run a program P having 10 Q.4 CO4 instructions 11,12,13...10. All the instructions are stored in consecutive memory locations started from 1000. To run an instruction li, you have to complete four operations: Fetch, Decode, Execute, and Store. The content of Program Counter will be after the completion of fetch operation of instruction 12. There are no jump or branch instruction in program Parrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education