I'm having difficulty looping through the addresses in the "instructions" array. For some reason it assembles and prompts me with "Error in path\ca.asm line 87: Runtime exception at 0x00400060: address out of range 0x00000000" and points to the syscall for the print message code. Can anybody explain why?
# Description: Parse MIPS instructions based on opcode and print message
.globl main, print_hex_info #decode_instruction, process_instruction, # Do not remove this line
# Data for the program goes here
.data
process: .asciiz "\nNow processing instruction "
opcode_num: .asciiz "\tThe opcode value is: "
newLine: .asciiz "\n"
# number of test cases
CASES: .word 5
# array of pointers (addresses) to the instructions
instructions: .word 0x01095020, # add $t2, $t0, $t1
.word 0x1220002C, # beqz $s1, label
.word 0x3C011001, # lw $a0, label($s0)
.word 0x24020004, # li $v0, 4
.word 0x08100002 # j label
inst_0: .asciiz "\tR-Type Instruction\n"
inst_other: .asciiz "\tUnsupported Instruction\n"
inst_2_3: .asciiz "\tUnconditional Jump\n"
inst_4_5: .asciiz "\tConditional Jump\n"
# You may use this array of labels to print the different instructions type messages
inst_types: .word inst_0, inst_other, inst_2_3, inst_2_3, inst_4_5, inst_4_5
# Code goes here
.text
main:
# Task 1A: Loop over the array of instructions
jal print_hex_info
loop_array:
li $s0, 0
# Set registers and call: print_hex_info
la $a0, instructions
bge $s0, 3, end_main
# Set registers and call: decode_instruction
# Print first return value
# Set registers and call: print_hex_info
# Update branch and index values
j loop_array # end of loop
end_main:
li $v0, 10 # 10 is the exit program syscall
syscall # execute call
###############################################################
## Other procedures here
###############################################################
# Print Message based on opcode type
#
# $a0 - Message to print
# $a1 - Value to print
# Uses $s0: address of string for $a0 (required)
# Uses $s1: value from $a1 (required)
print_hex_info:
##### Begin Save registers to Stack
subi $sp, $sp, 36
sw $ra, 32($sp)
sw $s0, 28($sp)
sw $s1, 24($sp)
sw $s2, 20($sp)
sw $s3, 16($sp)
sw $s4, 12($sp)
sw $s5, 8($sp)
sw $s6, 4($sp)
sw $s7, 0($sp)
##### End Save registers to Stack
# Now your function begins here
move $s0, $a0
move $s1, $a1
li $v0, 4 # print message
move $a0, $s0
syscall
li $v0, 34 # print address in hex value
move $a0, $s1
syscall
li $v0, 4 # print message
la $a0, newLine
syscall
end_print_hex_info:
##### Begin Restore registers from Stack
lw $ra, 32($sp)
lw $s0, 28($sp)
lw $s1, 24($sp)
lw $s2, 20($sp)
lw $s3, 16($sp)
lw $s4, 12($sp)
lw $s5, 8($sp)
lw $s6, 4($sp)
lw $s7, 0($sp)
addi $sp, $sp, 36
##### End Restore registers from Stack
jr $ra
###############################################################
User contributions licensed under CC BY-SA 3.0