Question

I am learning MIPS 32 bit. I wanted to ask that why do we Sign Extend the 16 bit offset (in Single Cycle Datapath) before sending it to the ALU in case of Store Word?

Was it helpful?

Solution

Sounds like the 16-bit offset is a signed 2's complement number, i.e. it can be either positive or negative.

When converting it to 32 bits, the most significant bit needs to be copied to the upper 16 bits in order to keep the sign information.

OTHER TIPS

I am not sure if it's helpful for you now, but I am posting it anyway.

Let us consider in a very very general sense, an array of instructions in C++ i.e. A[0],A[1],A[2] ..... The "figurative" distance between any two instructions is 1 UNIT.

Lets take this analogy to MIPS. In MIPS, figuratively every instruction is separated by "1 UNIT", however, 1 UNIT = 4 Bytes in MIPS. Every instruction is 4 Bytes long and this is why when moving from instruction to instruction the PC is incremented by 4 i.e. PC+4. So that way the gap between instruction i and instruction i+2 is "figuratively" 2 but actually 2*4=8 i.e. PC+4+4

Coming back to offsets that are specified in Branch instructions, the offset represents the "figurative" distance from the next instruction(the instruction following the Branch). So to get the "real" distance, the offset is to be multiplied by 4. This is the reason we are instructed to "sign-extend" the offset by 2 bits to the 'LEFT', because, left shifting any binary value by n bits results in multiplying that value by 2^n. In our case 2^2 = 4

So the actual target address of a branch instruction is PC+4+4*Offset.

Hope this helps.

To the best of my knowledge,in load or store instructions the offset value is added to the value in temporary register,as temp. register is 32 bit and addition operation of 16 bit and 32 bit is not possible,the value is sign extended.

I think you are getting your concepts a little wrong here.

The 5 bits that you think are going inside the ALU, actually go inside the register memory to select one of the 32[2^5] registers.

Each register itself is of 32 bits. Hence, to add the offset to the register value, you need to sign extend it to 32 bits.

ALU operation is always between two registers of the same size in the single cycle datapath for MIPS.

In the hardware of a 32-bit machine most ALU's take 32-bit inputs, and all registers are 32-bit registers.

To work with your data it must be 32-bits wide, this why we SIGN-extend, however another approach would be to ZERO-extend, but SIGN-extend is used when you are dealing with immediates and offsets to preserve the sign in 2's complement.

Sign extension happens e.g. in case of M68xxx machines only in case of loading the address registers. Not so in case of data registers.

having e.g.

movea.w addr,a0
move    addr,d0
addr:
dc.w $FFFF

leads in case of data register loading to $0000FFFF, in case of the address register loading however to $FFFFFFFF.

To understand this, build the two complement of the signed negative presentation, $FFFF, extend the number to 32 bit and redo the two- complement, finding the corresponding representation in 32 bit.

Cheers and kind regards, Stephan S.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top