Stage OPl rA, rB rrmovl rA, rB irmovl V, rB Fetch icode: ifun ← M1[PC] icode: ifun ← M1[PC] icode: ifun ← M1[PC] rA:rB ← M1[PC + 1] rA:rB ← M1[PC + 1] rA:rB ← M1[PC + 1] valC ← M4[PC + 2] Decode valP ← PC + 2 valP ← PC + 2 valA ← R[rA] valA ← R[rA] valP ← PC + 6 valB ← R[rB] Execute valE ← valB OP valA valE ← 0 + valA valE ← 0 + valC Set CC Memory Write back R[rB] ← valE R[rB] ← valE R[rB] ← valE PC Update PC ← valP PC ← valP PC ← valP Figure 4.16 Computations in sequential implementation of Y86 instructions OPl, rrmovl and irmovl. These instructions compute a value and store the result in a register. The notation icode:ifun indicates the two components of the instruction byte, while rA:rB indicates the two components of the register specifier byte. The notation M1[x] indicates accessing (either reading or writing) one byte at memory location x, while M4[x] indicates accessing four bytes. Stage pushl rA popl rA Fetch icode: ifun ← M1[PC] icode: ifun ← M1[PC] rA:rB ← M1[PC + 1] rA:rB ← M1[PC + 1] valP ← PC + 2 valP ← PC + 2 valA ← R[rA] valA ← R[%esp] valB ← R[%esp] valB ← R[%esp] Execute valE ← valB + (-4) valE ← valB + 4 Memory M4[valE] ← valA valM ← M4[valA] Write back R[%esp] ← valE R[%esp] ← valE Decode R[rA] ← valM PC Update PC ← valP PC ← valP Figure 4.18 Computations in sequential implementation of Y86 instructions pushl and popl. These instructions push and pop the stack. Homework Problem 4.32 In our example Y86 problems, we encounter many cases in which we want to add a constant value to a register. This requires first using an irmovl instruction to set a register to the constant, and then an addl instruction to add this value to the destination register. Suppose we want to add a new instruction iaddl with the following format: iaddl V, rB 0 1 C 0 2 8 3 rB 4 5 Byte V This instruction adds the constant value V to register rB. Describe the computations performed to implement this instruction. Use the computations for irmovl and OPl (Figure 4.16) as a guide. Homework Problem 4.33 The instruction leave can be used to prepare the stack for returning. It is equivalent to the following Y86 code sequence: 1 2 rrmovl %ebp, %esp popl %ebp Set stack pointer to beginning of frame Restore saved %ebp and set stack ptr to end of caller's frame Suppose we add this instruction to the Y86 instruction set, using the following encoding: leave 0 1 D 2 3 4 5 Byte 0 Describe the computations performed to implement this instruction. Use the computations for popl (Figure 4.18) as a guide. Homework Problem 4.34 The file seq-full.hcl contains the HCL description for SEQ, along with the declaration of a constant IIADDL having hexadecimal value C, the instruction code for iaddl. Modify the HCL descriptions of the control logic blocks to implement the iaddl instruction, as described in Homework Problem 4.32. See the lab material for directions on how to generate a simulator for your solution and how to test it. Homework Problem 4.35 The file seq-full.hcl also contains the declaration of a constant ILEAVE having hexadecimal value D, the instruction code for leave, as well as the declaration of a constant REBP having value 7, the register ID for %ebp . Modify the HCL descriptions of the control logic blocks to implement the leave instruction, as described in Homework Problem 4.33. See the lab material for directions on how to generate a simulator for your solution and how to test it.