Sun.
Sun.

Reputation: 113

Shift 32 bit Numbers on a 16 bit Datapath

How to Shift 32 Bit Numbers on a 16 Bit Datapath

This is a computer architecture question.


My datapath is only 16 bit wide, meaning my ALU can only process 16 bit operands at a time. My registers are 32 bits wide and are addressable in lower and upper 16 bit portions.

Every time I read the lower half of a register I also read an extra bit telling me weather the upper half contains any 1s at all (ref 1).


So far I implemented the shift left logical. (sll rd, rs1, rs2)

Now if there is no data written in the higher rs1 register (see ref 1) and the bits that are in the temp alu register are all 0, then my shift operation is done.

Otherwise a second cycle for the upper half is needed


Example 1: Lets say rs1 is 0x00001234 and rs2 is 0x00000002 (Perform a left shift by 2)

Example 2: Lets say rs1 is 0x0000D234 and rs2 is 0x00000005 (Perform a left shift by 5)

Example 3: Lets say rs1 is 0x01231234 and rs2 is 0x00000002 (Perform a left shift by 2)

I hope these examples gave a better insight.



Now I want to implement a right shift operation (arithmetical and logical). But how to do that in at most 2 cycles and if I have to read the lower rs1 register first (including the status bit)?


Thanks for reading; this is my first question here, so please don't go to harsh on me :D

Upvotes: 0

Views: 444

Answers (1)

yflelion
yflelion

Reputation: 1746

Start by reading the higher part. The first cycle you will read the high part. Do the right shift, the shifted out bits will be present in the high part of the tmp register and the result of the shift will be written back. The second cycle , you read the low part , you do a shift and an or with the result present in the tmp register. then the result of this part will be written back.

Upvotes: 1

Related Questions