=====Question 1 Consider the instruction add $s0,$s1,$s2. First, figure out the machine code for the instruction. Find the places on the figure where pieces of the instruction are referred to. Make sure you figure out which bits of the instruction go where in the figure. Pls ask if you have a question. Answer: machine code in hex 0x02328020 instruction[31-26] (opcode) 000000 instruction[25-21] (rs = $s1) 10001 instruction[20-16] (rt = $s2) 10010 instruction[15-11] (rd = $s0) 10000 **The subset of MIPS covered in this chapter does not include the shift instructions. So, none of these figures will do anything with the "shamt" field of the R instructions** instruction[15-0] (garbage for R instructions) 1000000000100000 instruction[5-0] (funct) 100000 The Control Unit (the oval in the middle of the figure) generates control signals, based on the opcode. The ALU Control Unit (the oval toward the bottom right) also generates control signals (specifically, the ALU control signals), based on the funct field of the instruction and an output from the top Control Unit. HOWEVER, these are not direct mappings, so you won't see a one-to-one correspondence between bits in the opcode & funct fields, and the control signals. Nevertheless, you can figure out what values the control signals should be, by looking at the figure and using your knowledge of the instructions. (At least, for most of them.) Write down the values below for the following control signals. If a control signal turns something on or off, its value is either 1 or 0. E.g., MemRead = 1 if something is read from memory, and 0 if not. For "Output of ALU Control" (the control signal generated by the ALU Control Unit), we haven't yet covered enough for you to know what particlar binary values these are. So, please just indicate one of 'add', 'sub', 'or', 'and'. Also, if a signal's value does not matter for that instruction, please indicate an X. That is, the instruction would execute exactly the same way, whatever value an X signal has. As you do this lab, it will be interesting to recognize the X signals. Please ask if you have any questions. Signal Value ------ ----- RegDst 1 For R-instructions, rd specifies the register to be written to. --------------------------------------- Branch 0 This is not a branch instruction. --------------------------------------- MemRead 0 There is no memory read for the add instruction --------------------------------------- MemToReg 0 The mux controlled by this signals determines which value is written to register rd. When this mux is 0, the output of the ALU is written to rd, which is what we want (the output of the ALU is the result of adding rs and rt) --------------------------------------- (ALUOp - we haven't yet covered enough to answer this) --------------------------------------- MemWrite 0 There is no memory write for the add instruction --------------------------------------- ALUSrc 0 The mux controlled by this signal determines the lower input to the ALU. 0 means that the input is rt. --------------------------------------- RegWrite 1 Yes, a value is written to a register (namely register rd) --------------------------------------- Output of ALU Control add --------------------------------------- Output of the And Gate at the top right 0 Since Branch is 0, the output of the AND gate is 0 (whatever Zero happens to be) --------------------------------------- Now, assuming that $s1 contains 0x00000007 and $s2 contains 0x00000004, what values are at the following inputs and outputs of the functional units? If an input or output doesn't matter for the instruction, then put an X next to the value. (Since combinatorial logic determines all of these inputs and outputs, there ARE values at all of them. It's just that some of them may be irrelevant for this instruction. The same is true for the control signals, but we don't have enough information at this point to determine what the values of the X control signals are.) Input Value ----- ----- Read 10001 register 1 --------------------------------------- Read register 2 10010 --------------------------------------- Write register 10000 --------------------------------------- Write data of 0x0000000b register file --------------------------------------- Top input to ALU 0x0000007 --------------------------------------- Bottom input to ALU 0x0000004 --------------------------------------- Address of memory 0x000000b X The value present at the Address input of memory is 0x0000000b. However, we mark this as X, because this value doesn't matter for an add instruction, which does not involve a memory access --------------------------------------- Write data 0x00000004 X of memory Similar comment to the above. The contents of rs are present at the Write data input to memory, but this value doesn't matter for an add instruction. Output Value ------ ----- Read 0x00000007 data 1 --------------------------------------- Read 0x00000004 data 2 --------------------------------------- Output of ALU 0x0000000b --------------------------------------- Zero of ALU 0 (1 if ALU output is 0; 0, otherwise) The result of the add operation is not a 0; so, Zero is 0 (i.e., false) --------------------------------------- Read Data X of memory We don't care what is at this output to memory, and we don't even know what it is. So, it is just X =====Question 2 Now, do the same thing for the instruction sw $t3,-8($t4) assuming that $t3 contains 0x0000000f and $t4 contains 0x1001002c. Answer: The machine code for this instruction is 0xad8bfff8 101011 01100 01011 11111 111 1111 1000 instruction[31-26] (opcode) 101011 instruction[25-21] (rs = $t4) 01100 instruction[20-16] (rt = $t3) 01011 instruction[15-11] (rd = NA) 11111 -- meaningless for an sw instruction[15-0] (imm = -8) 1111 1111 1111 1000 instruction[5-0] (funct = NA) 111000 - meaningless for an sw Signal Value ------ ----- RegDst X The mux controlled by RegDst chooses which register to write to. Since there is no write to a register for a sw instruction, it doesn't matter what this signal is. --------------------------------------- Branch 0 This is not a branch instruction --------------------------------------- MemRead 0 No memory read for a sw --------------------------------------- MemToReg X The mux controlled by MemToReg determines the source of the write data input to the register file. Since there is no write to the register file for a sw, we don't care what this value is. --------------------------------------- (ALUOp - we haven't yet covered enough to answer this) --------------------------------------- MemWrite 1 There is a write to memory for a sw --------------------------------------- ALUSrc 1 The mux controlled by this signal determines the lower input to the ALU. 1 means that the input is the immediate value from the instruction after it has been sign extended. --------------------------------------- RegWrite 0 --------------------------------------- Output of ALU Control add The ALU is used to calculate the effective address -- the address for the memory access. Specifically, in our example, $t4 + -8. --------------------------------------- Output of the And Gate at the top right 0 Since Branch is 0, we know the output of this and gate is 0 --------------------------------------- Input Value ----- ----- Read register 1 01100 --------------------------------------- Read register 2 01011 --------------------------------------- Write register X There is no write to the register file for an sw. Since we don't know/care about the value of the mux pointing to this input, we don't know what the value is, either. --------------------------------------- Write data of register file X --------------------------------------- Top input 0x1001002c to ALU --------------------------------------- Bottom input to ALU 0xfffffff8 --------------------------------------- Address 0x10010024 of memory --------------------------------------- Write data 0x0000000f of memory So, 0x0000000f is written to M[0x10010024] Output Value ------ ----- Read data 1 0x1001002c --------------------------------------- Read 0x0000000f data 2 --------------------------------------- Output of ALU 0x10010024 --------------------------------------- Zero of ALU (1 if ALU 0 output is 0; 0, otherwise) --------------------------------------- Read Data X of memory There is not a memory read for a sw, so we don't care (and we don't even know) what is present at the Read data output of memory.