Why do we sign the extension in the load word instruction?

I am learning MIPS 32 bit. I wanted to ask why we are signing a 16-bit offset extension (in a single Datapath loop) before sending it to ALU if Word is saved?

+7
source share
6 answers

It seems that the 16-bit offset is a signed 2 addition , that is, it can be positive or negative.

When converting it to 32 bits, the most important bit must be copied to the upper 16 bits in order to preserve the sign information.

+8
source

I'm not sure if this is useful to you now, but I post it anyway.

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

Let's look at this analogy with MIPS. In MIPS, figuratively each instruction is separated by "1 UNIT", however 1 UNIT = 4 bytes in MIPS. Each instruction has a length of 4 bytes, and therefore, when switching from a command to a PC command, it increases by 4, that is, on PC + 4. Thus, the gap between instruction I and instruction I + 2 is “figurative” 2, but actually 2 * 4 = 8, i.e. PC + 4 + 4

Returning to the offsets specified in the Branch instructions, the offset is the “shaped" distance from the next command (the instruction following the branch). Thus, in order to get the “real” distance, the offset must be multiplied by 4. This is the reason that we are instructed to “sign-extend” the 2-bit offset by “LEFT”, since the left shift of any binary value by n bits results in by multiplying this value by 2 ^ n. In our case, 2 ^ 2 = 4

Thus, the actual destination address of the jump instruction is PC + 4 + 4 * Offset.

Hope this helps.

+10
source

As far as I know, in load or store instructions, the offset value is added to the value in a temporary register, like temp. the register is 32 bits, and the addition operation of 16 bits and 32 bits is impossible, the value increases.

0
source

I think you are a little mistaken in your concepts.

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

Each register itself has 32 bits. Therefore, to add an offset to the register value, you need to sign it up to 32 bits.

The ALU operation is always between two registers of the same size in a single-point datapath for MIPS.

0
source

In the hardware of a 32-bit machine, most ALUs accept 32-bit inputs, and all registers are 32-bit registers.

To work with your data, it must be 32-bit wide, so we extend SIGN, however, a different approach will be for ZERO-extension, but SIGN-extend is used when you are dealing with immediate and offsets. To save, enter 2 additions.

0
source

Sign expansion occurs, for example. in the case of M68xxx machines, only in the case of loading address registers. Not so in the case of data registers.

eg,

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

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

To understand this, build two additions of the signed negative presentation, $ FFFF, increase the number to 32 bits and repeat twice, addition, finding the corresponding representation in 32 bits.

Greetings and good relations, Stefan S.

0
source

All Articles