I want to realize following steps:
unsigned c = 5
c=c*5
I must do this by using this architecture and using 3 instructions at MOST:
Sample instructions for the cpu are like:
Extra info about the problem:
Suppose that the program is stored in instruction memory starting at address 0, and that each address in the memory holds a single 16-bit instruction. Assume that each CPU register has a starting value of 0xFF and is 8 bits wide. Assume that variable "a" is mapped to the R0 register in the program below and that R1 is used as a temporary register for calculations.
I tried many ways but in all ways i used more than 3 instructions.
extra: datapath
Let's do some analysis of what we can see.
Let's analyze the
ADIinstruction. If, say, a 5 bit unsigned immediate is allowed we could simply add 26 to the pre-existing -1 to get the 25 in one instruction.So, our question is what are the possible immediate values allowed? To answer this, we can look at the definition in RTL of
ADI, which isR[RD] = R[RS] + zf I(2:0). This says that there is an immediate field encoded in the low three bits of the instruction. The RTL also suggests that the 3-bit immediate field is zero filled or zero extended, suggesting that field encoded values 0 to 7 mean operand values of the same. (If it hinted toward sign extension of the 3-bit immediate, that would imply a range of -4 to 3.)In one diagram there's a shifter near the ALU. It takes an
Hinput of 2 bits, which I take as an encoding for the shift amount. (This is almost certainly encoded in the low 2 bits of the instruction for shifting, similar to how the immediate is encoded in theADI' instruction.)(Given such a small field, 2 bits, it is silly to waste an encoding with a meaning of shift by 0 bits.)
For the 2-bit field, we have the possible encodings and their meaning that we're guessing at.
Either way, with an educated guess, it looks like it can shift left by either 1 or 2 bits. (In fact shifting left by 1 bit is potentially a silly encoding choice since that can be accomplished with addition to self.)
So, armed with that analysis of the potential instructions, can you try some more alternatives?