我正在尝试创建一个指向字符串的指针数组,但它的行为不符合预期。该数组包含字符串的内容,而不是地址。这是源代码:
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
当它运行时,这是输出:
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.
如您所见,helpar: 包含所有连接的字符串,而不是地址。另外,"la $a0, ($t1)" 中的间接寻址是加载$t1 的内容,而不是$t1 包含的地址处的内容。
我有什么误解?
谢谢,凯文