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: A Programmer's Perspective (3rd Edition)
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)
- 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_forwardTake the following machine language instruction and fill in the translation of it in assembly language. The "alternative operand values" is how the operand may be expressed in assembly language either has hex (prefixed with Ox) or decimal (not prefixed with Ox). C00005 Binary IS: Mask: Instruction: [Select] [Select] [Select] [Select] Operand specifier: (four hex digits) Operand specifier: [Select] (alternative operand values) Addressing mode: [Select] (symbolic) Assembly: [Select] (instruction and operand)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
- Description: Implement a transistor-level schematic of a computational unit/ALU that can perform the following operations. XOR ● XNOR Multiplication Addition Subtraction ● Rotate Shift Right Magnitude Comparator ● Equality Comparator The computational unit/ALU has a decoder to decode an instruction and a multiplexer to select outputs of different operations. Data inputs are 4-bit wide. Make sure you test your design for all the operations listed above.arrow_forwardQuiz 5: In this problem we want to set the control signals of the datapath shown below (also in in slide # 1 of "chapter3_single_cycle_datapaths.pptx") so that it supports execution of a new instruction called swi. Single Cycle Datapath: PC Read Instru- address ction [31-0] Instruction memory Sns Add Ins 1 [25-21] 1 [20-16] [15-11]. 1[10-0] RegWrite Read register 1 Read register 2 Write register Write data Read data 1 Read data 2 Read Ins Write 3ns Sign extend 2ns MemWrite Read Read address data Write address Read Gns Write data Write 10ns ins ALUSTO1 MemRead ALU Result 2ns ALUOP1 -XEWO) ins ALUSrc2 ALUSrc3 x=3 ins ALU Result 2ns ALUOP2 swi rd, rs, rt, imm # Memory [R[rs]]= R[rt], R[rd] =R [rs]+R [rt]+Imm #this instruction copies contents of "rt" register into the main memory addressed by the "rs" register. In the same cycle it add "rs" and "rt" register contents along with the "imm" field of the instruction and writes the final result into the "rd" register. You are NOT allowed to…arrow_forwardConsider the following fragment of IA32 code modeling the C standard library: Øx560d700d5d : call ex560d700d62 Øx560d700d62 : popl %eax After the popl instruction completes, what hex value does the register %eax contain?arrow_forward
- Write 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_forwardThere is an application that requires the following hardware: an Intel 8031, a Program ROM of 8Kx8, a Data ROM of 4Kx8 for look-up tables and a Data RAMs of 8Kx8. The memory map of the design: Program ROM should start at address 0000H. Then, the Data ROM should come above the Program ROM. Finally the Data RAM must go to the top of the memory map. There should be no gaps between the memory addresses of the external ROMs. Show the design’s address space on a memory map, starting with 0000H at the bottom and FFFFH at the top.arrow_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_forward
- rite an assembly program for the processor family x86-32 that reads three real numbers from the keyboard and shows on the console the average value of them. In your implementation include the function averageOfThree and define for that function the interface below. averageOfThree: ; Input: Three memory addresses on the stack of three 64-bit floating point numbers in main memory. ; Output: The average value of the three input numbers on the stack as a 64-bit floating point number. ;TODO retarrow_forwardQuestion Write 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…arrow_forwardWrite a code in sim8085 for the following problem: The pressure of two boilers is monitored and controlled by a microcomputer works based on microprocessor programming. A set of 6 readings of first boiler, recorded by six pressure sensors, which are stored in the memory location starting from 2050H. A corresponding set of 6 reading from the second boiler is stored at the memory location starting from 2060H. Each reading from the first set is expected to be higher than the corresponding position in the second set of readings. Write an 8085 sequence to check whether the first set of reading is higher than the second one or not. If all the readings of first set is higher than the second set, store 00 in the ‘D’ register. If any one of the readings is lower than the corresponding reading of second set, stop the process and store FF in the register ‘D’. Data (H): First set: 78, 89, 6A, 80, 90, 85 Second Set:71, 78, 65, 89, 56, 75arrow_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