0

我正在做我的作业,它说我必须询问用户他们希望在阵列中出现多少个成员。然后用户应该在他们的数组中输入数字,然后程序打印数组。我无法在控制台窗口中打印阵列中的内容。

这是我的代码:

    .data

max:        .word -9999
array:      .space 12
message1:   .asciiz "Enter an integer:\n"
message2:   .asciiz "Specify how many numbers should be stored in the array (atmost 8): \n"
message3:   .asciiz "The array content is: \n"
message4:   .asciiz "The maximum is: \n"
message5:   .asciiz "They have the same maximum.\n"
message6:   .asciiz "The first array has a larger maximum.\n"
message7:   .asciiz "The second array has a larger maximum.\n"

.text
        .globl main

main:
    lw  $s1, max
    la  $s3, array
    li  $s2, 3
    la  $a0, message2
    li  $v0, 4
    syscall
    li  $v0, 5
    syscall
    move    $t0, $v0
    blt $t0, $s2, Read

Read:
    la  $a0, message1
    li  $v0, 4
    syscall
    li  $v0, 5
    syscall
    move    $t1, $v0
    sw  $t1, 0($s3)
    addi    $s3, $s3, 4  
    addi    $t0, $t0, -1 
    bgt $t0, $zero, Read
    j   Print

    #blt    $t0, $s2, Print

Print:
    la  $a0, message3,
    li  $v0, 4
    syscall
    jr  $ra     

谢谢您的帮助。

4

1 回答 1

1

当您输入Print时,数组的末尾加上 4 in $s3,因此您可以执行以下操作:

$s2 = ADDRESSOF(array)
while ($s2 != $s3) do
    print_int($s2[0])      // syscall 1
    print_character(' ')   // syscall 11
    $s2 += 4
end while

这是用于说明逻辑的伪代码;我将把实际的汇编实现留给你,因为这是你的任务。


(顺便说一句,this:la $a0, message3,是一个错字。该行的末尾不应该有逗号)

于 2013-09-20T08:28:23.330 回答