Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly MIPS/MARS是否在指令中使用符号?_Assembly_Mips - Fatal编程技术网

Assembly MIPS/MARS是否在指令中使用符号?

Assembly MIPS/MARS是否在指令中使用符号?,assembly,mips,Assembly,Mips,我试图创建一个指向字符串的指针数组,但它的行为与预期不符。数组包含字符串的内容,而不是地址。以下是源代码: 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" h

我试图创建一个指向字符串的指针数组,但它的行为与预期不符。数组包含字符串的内容,而不是地址。以下是源代码:

    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中包含的地址的内容

我误解了什么

谢谢, 凯文

问题出在这里:

        lw          $t0, helpsiz
        lw          $t1, helpar     # load address of 1st string
nxthlp: la          $a0, ($t1)      # NOT SURE IF THIS IS EVEN VALID
        li          $v0, 4
        syscall
        addi        $t1, $t1, 4     # skip 4 chars in string; must be unsigned add!
        subi        $t0, $t0, 1
        bgtz        $t0, nxthlp
以下是您应该做的:

    lw      $t0, helpsiz
    la      $t1, helpar # t1 points to element 0 of helpar
nxthlp:
    lw      $a0, 0($t1) # fetch element of helpar that t1 points to
    li      $v0, 4
    syscall
    addu    $t1, $t1, 4 # t1 points to next element of helpar
    subi    $t0, $t0, 1
    bgtz    $t0, nxthlp
问题是:

        lw          $t0, helpsiz
        lw          $t1, helpar     # load address of 1st string
nxthlp: la          $a0, ($t1)      # NOT SURE IF THIS IS EVEN VALID
        li          $v0, 4
        syscall
        addi        $t1, $t1, 4     # skip 4 chars in string; must be unsigned add!
        subi        $t0, $t0, 1
        bgtz        $t0, nxthlp
以下是您应该做的:

    lw      $t0, helpsiz
    la      $t1, helpar # t1 points to element 0 of helpar
nxthlp:
    lw      $a0, 0($t1) # fetch element of helpar that t1 points to
    li      $v0, 4
    syscall
    addu    $t1, $t1, 4 # t1 points to next element of helpar
    subi    $t0, $t0, 1
    bgtz    $t0, nxthlp