Concept explainers
In Section 3.6.8, we saw that a common way to implement switch statements is to create a set of code blocks and then index those blocks using a jump table. Consider the C code shown, in Figure 4.69 for a function switchv, along with associated test code.
Implement switchv in Y86-64 using a jump table. Although the Y86-64 instruction set does not include an indirect jump instruction, you can get the same effect by pushing a computed address onto-the stack and then executing the ret instruction. Implement test code similar to what is shown in C to demonstrate that your implementation of switchv will handle both the cases handled explicitly as well as those that trigger the default case.
Figure 4.69 Switch statement can be translated into Y86-64 code. This requires implementation of a jump table.
Want to see the full answer?
Check out a sample textbook solutionChapter 4 Solutions
Computer Systems: Program... -Access
Additional Engineering Textbook Solutions
Programming in C
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Artificial Intelligence: A Modern Approach
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with C++: Early Objects (9th Edition)
Java: An Introduction to Problem Solving and Programming (7th Edition)
- What the code below does? Consider the following code used to implement a new instruction: foo $t3,$t1,$t2: mask : . word 0xFFFFF83Fstart : la $t0 , masklw $t0 , 0 ( $ t 0 )la $t3 , s h f t rlw $t3 , 0 ( $ t 3 )and $t3 , $t3 , $ t 0andi $t2 , $t2 , 0 x 0 0 1 fsll $t2 , $t2 , 6or $t3 , $t3 , $ t 2la $t5 , s h f t rsw $t3 , 0 ( $ t 5 ) shftr: sll $t3 , $t1 , 0 What does foo does?arrow_forwardWhat the code below does? 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 , 0 What does foo does?arrow_forwardWhat happens if VA page 30 is written even if an instruction was not accepted? An instance of a software-managed TLB would outperform a hardware-managed TLB in the following cases:arrow_forward
- In this exercise, we consider the execution of a loop in a statically scheduled superscalar processor that has full forwarding. Loop: lw $t3, 0($s1) lw $t4, 0($s2) mul $t1, $t3, $t4 add $s0, $t1, $s0 addi $s1, $s1, -8 addi $s2, $s2, -8 bne $s1, $zero, Loop Unroll this loop so that three iterations of it are done at once and schedule it for a 2-issue pipelined processor. This processor can issue one ALU/branch instruction and one lw/sw instruction each cycle. Assume that the loop always executes a number of iterations that is a multiple of 3. You can use any unused registers when changing the code to eliminate dependencies.arrow_forwardWrite an assembly code to implement the y = (x1+x2) * (x3+x4) expression on 2-address machine, and then display the value of y on the screen. Assume that the values of the variables are known. Hence, do not worry about their values in your code. The assembly instructions that are available in this machine are the following: Load b, a Load the value of a to b Add b, a Add the value of a to the value of b and place the result in b Subt b, a Subtract the value of a from the value of b and place the result in b Mult b, a Multiply the values found in a and b and place the result in b Store b, a Store the value of a in b. Output a Display the value of a on the screen Halt Stop the program Note that a or b could be either a register or a variable. Moreover, you can use the temporary registers R1 & R2 in your instructions to prevent changing the values of the variables (x1,x2,x3,x4) in the expression. In accordance…arrow_forwardImplement a new unary instruction in place of N0P0 called ASL2 that does two left shifts on the accumulator. V should remain unchanged, but N and Z should correlate with the new value in the accumulator, and C should be the carry from the second shift. Write a program that tests all the features of the new instruction.arrow_forward
- In this exercise we compare the performance of 1-issue and 2-issue processors, taking into account program transformations that can be made to optimize for 2-issue execution. Problems in this exercise refer to the following loop(written in C):for(i=0;i!=j;i+=2)b[i]=a[i]–a[i+1];When writing MIPS code, assume that variables are kept in registers as follows, and that all registers except those indicated as Free are used to keep various variables, so they cannot be used for anything else. i j a b c Free R5 R6 R1 R2 R3 R10,R11,R12 Translate this C code into MIPS instructions. Your translation should be direct, without rearranging instructions to achieve better performance.arrow_forwardHere is a small snippet of code that saves $t0 $t1 and $t2 in order to stack ie first saves t0 then t1 and finally t2 what instruction should be put in the place of x y z X sw $t0, 8($sp) Y Zarrow_forwardConsider the code sequence below lw $t1, 4($t0) add $s2, $t1, $t2 lw $t3, 16($t0) add $s3, $t3, $t2 lw $t4, 28($t0) add $s4, $t4, $t2 Suppose there is no forwarding allowed, and for the result of a lw to be consumed by the following R-type of instruction requires 2 bubbles to be placed between the two instructions. Is it possible for the scheduler to juxtapose the commands in such a way that there is no need for any bubbles? If yes, give an example of how it can be done.arrow_forward
- Consider a multilevel computer in which levels are vertically stacked, with the lowest level being level 1. Each level has instructions that are m times as powerful as those of the level below it; that is, one level r instruction can do the work of m instructions at level r-1. However, n instructions at level r-1 are required to interpret each instruction at level r. Given this, answer the following questions: If a level 1 program requires k seconds to run, how long would the equivalent program take to run at levels 2, 3 and 4. Express your answer in terms of n, m, and r. What is the performance implication for the program if n > m? Conversely, what is the implication if m > n? Which case do you think more likely? Why?arrow_forwardCompile the following C code snippet with optimization level O0 and O1 using armv7-a clang 11.0.1 compiler. Which instruction(s) computes the return value of the function in O2? Compare and explain the difference between the three optimization levels. float foo1() { float sum = 0.0; unsigned int i = 0; for (i = 1; i <= 15; i++) { sum += i * i * i; } return sum; }arrow_forwardThis question is on Computer Architecture. Translate the following arithmetic and logical expressions written in C programming language intoinstructions sequences written in MIPS Assembly language. You may assume that the values (orbase addresses) of the variables a, b, c, and d are in the general-purpose registers $s0, $s1,$s2, and $s3. 1. d[3] = a - b + c[7];2. c[5] = (a << 3) & (b >> 2);Here, <<, >>, and & indicate the bitwise left-shift, right-shift, and AND operations respectively.arrow_forward
- 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