I am running QtSpim 9.1.7 on 64-bit Windows 7. Under Simulator / Settings / MIPS I have all options ticked ("Bare Machine", "Accept Pseudo Instructions", "Enable Delayed Branches", "Enabled Delayed Loads", "Enable Mapped IO", "Load Exception Handler").
I am able to run basic code to add values in QtSpim if I store hard-coded values using ori
as follows: ori $t0,$0,4
. Now I want to load and store data from memory, but lw
isn't working.
.text
.globl main
main:
lw $t0,num1
.data
num1: .word 4
When I Reinitialise and load the above file, I get the following error message: "Immediate value is too large for field:"
If I then try to step through the code, I get as far as line [00400024]. Stepping over that line, I get these error messages: "Exception occurred at PC=0x00400024" / "Bad address in data/stack read: 0x00000000"
For reference, my code is parsed as:
User Text Segment [00400000]..[00440000]
[00400000] 8fa40000 lw $4, 0($29) ; 183: lw $a0 0($sp) # argc
[00400004] 27a50004 addiu $5, $29, 4 ; 184: addiu $a1 $sp 4 # argv
[00400008] 24a60004 addiu $6, $5, 4 ; 185: addiu $a2 $a1 4 # envp
[0040000c] 00041080 sll $2, $4, 2 ; 186: sll $v0 $a0 2
[00400010] 00c23021 addu $6, $6, $2 ; 187: addu $a2 $a2 $v0
[00400014] 0c100009 jal 0x00400024 [main] ; 188: jal main
[00400018] 00000000 nop ; 189: nop
[0040001c] 3402000a ori $2, $0, 10 ; 191: li $v0 10
[00400020] 0000000c syscall ; 192: syscall # syscall 10 (exit)
[00400024] 8c080000 lw $8, 0($0) [num1] ; 4: lw $t0,num1
The first thing that occurs to me is that 0($0)
is surely not the address of num1
. Is my data declaration incorrect? If so, what have I done wrong?
I don't know if it's related, but I got syntax errors for the following la
and li
commands (when I was trying to find an alternative to lw
):
la $a0,num1
li $t0,4
This appears to be a bug in QtSpim. The same code works in two other environments (with slightly different versions of QtSpim, so I'm not sure if it's a regression in 9.1.7 or the environment)...
Environment 1: EE380 CGI SPIM
Accessible at http://cgi.aggregate.org/cgi-bin/cgispim.cgi and running SPIM 6.3a. It runs the code without returning an error and generates the following execution trace:
SPIM Version 6.3a of January 14, 2001
Copyright 1990-2000 by James R. Larus (larus@cs.wisc.edu).
All Rights Reserved.
[0x00400000] 0x8fa40000 lw $4, 0($29) ; 102: lw $a0, 0($sp) # argc
[0x00400004] 0x27a50004 addiu $5, $29, 4 ; 103: addiu $a1, $sp, 4 # argv
[0x00400008] 0x24a60004 addiu $6, $5, 4 ; 104: addiu $a2, $a1, 4 # envp
[0x0040000c] 0x00041080 sll $2, $4, 2 ; 105: sll $v0, $a0, 2
[0x00400010] 0x00c23021 addu $6, $6, $2 ; 106: addu $a2, $a2, $v0
[0x00400014] 0x0c100008 jal 0x00400020 [main] ; 107: jal main
[0x00400020] 0x3c011001 lui $1, 4097 [num1] ; 4: lw $t0,num1
[0x00400024] 0x8c280000 lw $8, 0($1) [num1]
Environment 2: Ubuntu
The same code executes without error on QtSpim 9.1.6 on 32-bit Ubuntu 11.10 and generates the following:
User Text Segment [00400000]..[00440000]
[00400000] 8fa40000 lw $4, 0($29) ; 183: lw $a0 0($sp) # argc
[00400004] 27a50004 addiu $5, $29, 4 ; 184: addiu $a1 $sp 4 # argv
[00400008] 24a60004 addiu $6, $5, 4 ; 185: addiu $a2 $a1 4 # envp
[0040000c] 00041080 sll $2, $4, 2 ; 186: sll $v0 $a0 2
[00400010] 00c23021 addu $6, $6, $2 ; 187: addu $a2 $a2 $v0
[00400014] 0c100009 jal 0x00400024 [main] ; 188: jal main
[00400018] 00000000 nop ; 189: nop
[0040001c] 3402000a ori $2, $0, 10 ; 191: li $v0 10
[00400020] 0000000c syscall ; 192: syscall # syscall 10 (exit)
[00400024] 3c011001 lui $1, 4097 [num1] ; 4: lw $t0,num1
[00400028] 8c280000 lw $8, 0($1) [num1]