Search code examples
assembly32-bitmips32qtspim

Using MIPS 32 assembly language, how can I use the addu and ori commands to load and add 4 integers?


This is what I have, however it doesn't want to do the last addu, which attempts to add together registers 10 and 13 into register 14. The last addu command puts the the letter 'e' into register 14.

        .text
        .globl  main

main:
        ori     $8,$0,0x2       # put two's comp. two into register 8
        ori     $9,$0,0x3       # put two's comp. three into register 9
        ori     $11,$0,0x4      # put two's comp. four into register 11
        ori     $12,$0,0x5      # put two's comp. five into register 12
        addu    $10,$8,$9       # add register 8 and 9, put result in 10
        addu    $13,$11,$12     # add register 11 and 12, put result in 13
        addu    $14,$10,$13     # add register 10 and 13, put result in 14

## End of file

Solution

  • It's hex E, aka 0xe, aka 14(dec), not the letter 'e'.

    You're looking at the debugger showing you content in hex.  This is not "output" but it is an interpretation of the values in the registers, done by the debugger.  The debugger has modes to show the registers in binary, hex, or decimal — use the QtSpim menu item "Registers".  The bugger doesn't really know what you want to show but it can switch all registers displayed from binary to hex to decimal.

    The actual values held in the register are the same regardless of the chosen display form by the debugger.  While the hardware uses binary to store the register values, the value stored in the register is just a number, no matter how we display it — and to be clear any character sequence for a number (like 100) is a display format using a number base.  The registers do not know about display format and number bases, they just store numbers using binary — that's the debugger interpreting the number in a number base for display.  That they use binary only means that they cannot store numbers larger than 32 bits, but otherwise storing 100 decimal or hex 64 is all the same number in the register (same exact bit pattern).

    If you want actual output you need an instruction sequence to print numbers as character sequences, using a syscall of some sort — load a value to display into $a0 and use syscall #1 to print in decimal.  I don't know a print hex in QtSpim, but MARS (its cousin in MIPS simulation territory) has syscall #34 to print hex.