Understanding Immediates in ADDI and similar NIOS II instructions

 

As we discussed in the lecture, ADDI takes two source operands, one being a register and the second being a 16-bit immediate (number). That immediate get’s sign-extended into 32-bits before participating in the addition.

 

Let’s look at a couple of examples:

What is the result of:

 

1.       addi r10, r0, 0x8000?

a.       R10 = 0xFFFF8000

2.       Addi r10, r0, 0xAAAA?

a.       R10 = 0xFFFFAAAA

3.       Addi r10, r0, 0x9000?

a.       R10 = 0xFFFF9000

4.       Addi r10, r0, 0x7AAA?

a.       R10 = 0x00007AAA?

5.       Addi r10, r0, -2?

a.       -2 = 0xFFFE in hexadecimal and in 16 bits

b.      R10 = 0xFFFFFFFE, this is -2 in hexadecimal in 32 bits

c.       Note: 0x0000FFFE is not -2, it’s 65534

6.       Addi, r10, r0, 32769?

a.       Got to convert 32769 in binary. Turns out it’s 1000 0000 0000 0001, or 0x8001 in hexadecimal

b.      So, r10 = 0xFFFF8001

7.       What will be r10 after these two instructions execute?

a.       Addi r10, r0, 0xFFFF

b.      Addi, r10, r10, 1

                                                                           i.      You should get r10 = 0

8.       How about these two?

a.       Addi r10, r0, 3

b.      Addi r10, r10, 0xFFFE

                                                                           i.      You should get r10=1

9.       These two?

a.       Movhi r10, 0xFFFF

b.      Addi r10, r10, 0xFFFF

                                                                           i.      You should get r10 = 0xFFFEFFFF

                                                                         ii.      Try everything in binary and see what you get

10.   These?

a.       Movhi r10, 0x1234

b.      Addi r10, r10, 0x5678

                                                                           i.      You should get r10=0x12345678

11.   Finally, these two:

a.       Movhi r10, 0x1234

b.      Addi r10, r10, 0x89ab

                                                                           i.      You should get r10=0x123389AB

 

Please double-check these and let me know of any errors.