Decode Unit¶
Read time: 5 minutes (1311 words)
The Fetch Unit
delivers three data items to the Decode Unit
.: The
current instruction PC
address value, the 16-bit instruction found at the
address in the Instruction Memory component (IM
), and the 16-bit data found
at PC+1
, in case this is a two word instruction. In other words, everything
we need to decode this instruction.
Our job in this unit is to break out all the individual data items from that 16-bit or 32-bit instruction. By the way, we also have to figure out what size this instruction really is.
We have examined the C++ code we might use to decode these bits, so we will just wrap up that logic in a decoding component that receives the two 16-bit incoming data, and delivers all the possible pieces of an instruction. Based on our previous work, that means we need to deliver these items:
For simplicity (and since there is only one constant per instruction possible), we will set up our decoder to produce a correct 16-bit data constant value, even for smaller constants. To do that, we will need to “sign extend” those constants that are really small signed numbers. When we stick that bit pattern in a normal C++ integer container, C++ will deal with the sign properly when we do the simple math needed to find a new address.
Here is the unit diagram we will build for this part of our machine: