I’m trying to create an array of pointers to strings, but it’s not behaving as expected. The array has the contents of the strings, not the addresses. Here’s the source code:
showhelp:
.data
help1: .asciiz "\nHELP FOR HW4_2b\n"
help2: .asciiz "Purpose: Displays the output from a one-bit full adder with inputs provided on the command line.\n"
help3: .asciiz "HW4_2b c a b\n"
help4: .asciiz "c\t\tThe carry in bit: 0|1\n"
help5: .asciiz "a\t\tOne of the bits to be added: 0|1\n"
help6: .asciiz "c\t\tThe other bit to be added: 0|1\n"
helpar: .word help1, help2, help3, help4, help6
helpsiz:.word 6
.text
lw $t0, helpsiz # load size of help array
lw $t1, helpar # load address of address of first help string
nxthlp: la $a0, ($t1) # specify string to print
li $v0, 4 # specify print string
syscall # print it
addi $t1, $t1, 4 # increment pointer to next string
subi $t0, $t0, 1 # decrement counter
bgtz $t0, nxthlp # if not last string loop
jr $ra # return
When this runs, this is the output:
HELP FOR HW4_2b
P FOR HW4_2b
R HW4_2b
4_2b
rpose: Displays the output from a one-bit full adder with inputs provided on the command line.
As you can see, the helpar: contains all the strings concatenated, rather than the addresses. Also, the indirect addressing in the “la $a0, ($t1)” is loading the contents of $t1, rather than the contents at the address contained in $t1.
What am I misunderstanding?
Thanks,
Kevin
Here’s the problem:
Here’s what you should do instead: