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
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
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)
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 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_forward1. Consider the following y86-64 program: .pos 0x0irmovq $128,%rdxirmovq $3,%rcxrmmovq %rcx, 0(%rdx)irmovq $10,%rbxmrmovq 0(%rdx), %rax # Load %raxaddq %rbx,%rax # Use %raxhalt What value will be in register %rbx when the halt statement is reached? Give your result in hex, without leading 0s or 0x. Answer: 2. Consider the following y86-64 program: .pos 0x0irmovq $128,%rdxirmovq $3,%rcxrmmovq %rcx, 0(%rdx)irmovq $10,%rbxmrmovq 0(%rdx), %rax # Load %raxaddq %rbx,%rax # Use %raxhalt Memory is written to by this program. What is the memory address? Give your result in hex, without leading 0s or 0x. Answer: 3. Consider the following y86-64 program: .pos 0x0irmovq $128,%rdxirmovq $3,%rcxrmmovq %rcx, 0(%rdx)irmovq $10,%rbxmrmovq 0(%rdx), %rax # Load %raxaddq %rbx,%rax # Use %raxhalt Memory is written to by this program. What value is written to memory? Give your result in hex, without leading 0s or 0x. Answer: 4. Consider the following y86-64 program: .pos 0x0irmovq…arrow_forward10. Consider the following code: .386 .model flat, stdcall .stack 4096 ExitProcess PROTO, dwExitCode : DWORD .data aVal SDWORD -6 bVal SWORD 19h cVal DWORD 17h .code mov edx, aVal add edx, edx mov eax, 0FFFFFFFFh mov ax, bVal sub edx, eax Show the content of edx and eax after executing each instruction in Hexadecimaarrow_forward
- 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).arrow_forwardBy using an equation off = ( a - b ) / [ ( d x e ) + c ];(a) illustrate the step to realize this equation by using the stack concept. (b) construct its’ CISC zero address format. (c) construct its CISC one address format. (d) construct the CISC two address format by using only 3 register. (e) In your opinion, do we need to have at least as possible instruction line? Do it will reflectthe performance of computer execution time?arrow_forwardIn this exercise we examine in detail how an instruction is executed in a single-cycle datapath. Problems in this exercise refer to a clock cycle in which theprocessor fetches the following instruction word: 10101100100001010000000000011100 Assume that the data memory is all zeros and that the processor’s registers havethe following values at the beginning of the cycle in which the above instructionword is fetched: R0 R1 R2 R3 R4 R5 R6 R8 R12 R31 0 2 4 6 13 10 12 16 24 31 a. What are the outputs of the sign-extend and the jump “Shift-Left-2” (near the topof the following Figure) for this instruction word? (Pic3) b. What are the values of ALU control unit’s inputs (ALUOp and Instruction[5-0])for this instruction? c. What is the new PC address after this instruction is executed? Highlight the paththrough which this value is determined. d. For the ALU and the two add units, what are their data input values? ALU Add (PC+4) Add…arrow_forward
- Consider a HW ISA program P1 with the following Instruction Memory IM: Jamie wants to translate program P1 (except for the final HALT instruction) into a sequence of statements in a version of C with a 16-bit int type. Using the IM Fill in the rest of her program with assignments to variables named R2, R3, and R4 that represent the registers with these names in P1 and a while loop. int R0 = 0; int R1 = 1; int R2 = R0 + R0; // ...arrow_forwardExplain the Memory stack organization of 16 locations of stack( 0 to 15). take the initial value of thestack pointer is SP = 0E in Hex. Explain the following push and pop instructions through the Memorystack organization diagram.(1) PUSH R5 WHERE R5 = XX in Hex(2) POP R4 WHERE R4 = (XX + 3 ) Hex for example roll no 64 is having the data in R5 = 64Hex and R4 is ( 64+3 = 67 Hex)arrow_forwardBelow is a program with ARM Assembly. PC = 0x2000, Stack pointer sp = 0x400 (no heap or memory = 0x2000), no x2028 can be read (when in the corresponding row) What is the SP value and what dataset is in the stack base address 0x3F8?arrow_forward
- Write an Arm Assembly Program that does the following:•Stores on the stack a list of words of memory where the first element of the list is how manyremaining elements are in the list, and the rest of the elements in the list are initialized tosome random values.– Example:list: 6, -3, 4, 5, 9, 22, 99//stores a list of the 6 elements -3, 4, 5, 9, 22, 99•At the end of the program, register r0 should hold the sum of only the negative values in thearray (nonnegative elements are ignored).•Note that your program must work correctly even if the values stored in the list are changed.arrow_forwardPlease solve and show work. Thank you. What is the MIPS instructions corresponding to this C code: Int leaf_example (int g, h, i, j){ int f; f = (g - h) - (i + j); f +=2 return f;} Arguments g, …, j in $a0, …, $a3, f in $s0 (hence, need to save $s0 on stack), Result in $v0arrow_forward4-Write MIPS assembly for the following function. Assume N is passed to your function in register $a0. Your output should be in register $v0 at the end of your function. Note: You must implement this function recursively. The purpose of this assignment is to learn how to manipulate the stack correctly in MIPS.int Myfun (int N){ if (N<4) return 1; return ( 4* Myfun(N-3)+ 2*Myfun(N-2)+ Myfun(N-1)+N );}Please explain each instruction with a comment. Please submit your source code and a screenshot that shows the registers with correct output value for N=4, i.e., Myfun(4) returns 11.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