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.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.
- 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.
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.
- Fetch:
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
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
Draw the stack frame just before the RET instruction in the swap function is executed in the code shown below:
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).
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_forwardGiven 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.arrow_forwardThe correct optionarrow_forward
- Say 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_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_forwardFrom 61: current values in stack segment register and stack pointer: C00016 & FF0016. address of the current top of the stack CFF00arrow_forward
- i need the answer quicklyarrow_forwardSuppose that we have the following stack, where the red line is the indicator for sp. The stack grows downwards in main memory, just as it does in a regular RISC-V main memory. Both Wordo and Word1 occupy 1 word each: Word ( Word1 If we want to store the following contents of the stack: (i) a byte from to, (ii) a half word from t1, (iii) a word from t2, such that the stack becomes the following shown below: Word to I t1 t2 So essentially, we are popping Word1 from stack and then pushing t0, t1 and t2 in order. Given the following RISC-V code: 1 addi sp, sp, 2 sb to, 3 sh tl, 4 SW t2, O -7,0, 1, 5 Please select the proper number sequence to fill in the blanks in lines of code maintaining the correct order. All the numbers in the options below are in decimal O-3, 0, 1, 5 ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬ (sp) (sp) (sp) O-3, 6, 4, 0 O None of the optionsarrow_forwardThe STACK is a dynamic data structure. The 80x86 computer controls its stack via stack pointer ESP. Whenever you POP data out of the stack segment memory using POP BX, the 80x86 will transfer data by: Increasing the stack pointer ESP by 4. a. b. Decreasing the stack pointer ESP by 4. Decreasing the stack pointer ESP by 2. C. d. Increasing the stack pointer ESP by 2.arrow_forward
- Translate the following C code into RISC-V assembly code. You can only use RV64I and RV64M instructions and cannot use pseudoinstuctions. Note that according to RISC-V spec, “In the standard RISC-V calling convention, the stack grows downward and the stack pointer is always kept 16-byte aligned.”.long long int func(int n) { if (n == 0 or n == 1 or n == 2)return n; else return n*n + func(n - 1) + 8*func(n - 2) + func(n - 3);}arrow_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 NOP CALL L1 CALL L2 CALL L3 HERE: JMP HERE .org Ox100 L1: INC R17 NOP CALL L2 INC R17 RET .org 0x200 L2: INC R17 NOP NOP CALL L3 INC R17 RET .org Ox300 L3: INC R17 * RETarrow_forwardThe STACK is a dynamic data structure. The 80x86 computer controls its stack via stack pointer ESP. Whenever you PUSH data onto the stack segment memory using PUSH EBX, the 80x86 will transfer data by: Decreasing the stack pointer ESP by 4. O b. Incrcasing the stack pointer ESP by 2. Decreasing the stack pointer ESP by 2. Increasing the stack pointer ESP by 4.arrow_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