在阵列MIPS中的条目之间打印空间

时间:2013-04-03 14:40:57

标签: assembly mips

我正在用MIPS编写一个程序,它将两个数组的所有元素成对地相乘,并将结果存储在第三个数组中。但是,当我在结果数组中打印元素并且我想在元素之间有空格时,结果会像这样显示

7862845

这是完整的代码

.data

A:  .word 1,2,3,4,5
B:  .word 7,4,2,7,9
C:  .word
n:  .word 5
space:  .asciiz " "

.text
.globl main

main:
    la  $t0, n          # load address of n into $t0
    lw  $s0, ($t0)      # load value of n into $s0

    la  $t1, A          # load base address of array A into $t1
    la  $t2, B          # load base address of array B into $t2
    la  $t3, C          # load base address of array C into $t3

    add $t4, $zero, $zero   # i = 0 
loop:
    slt $t5, $t4, $s0
    beq $t5, $zero, finish

    lw  $s1, ($t1)      # load value A[0] into $s1
    lw  $s2, ($t2)      # load value B[0] into $s2

    mult    $s1, $s2
    mflo    $s3

    sw  $s3, ($t3)      # store result into array C

    addi    $t4, $t4, 1
    addi    $t1, $t1, 4
    addi    $t2, $t2, 4
    addi    $t3, $t3, 4

    j   loop

finish:
    la  $t3, C          # load base address of array C into $t3
    add $t4, $zero, $zero   # i = 0 

print:
    slt $t5, $t4, $s0
    beq $t5, $zero, Exit

    lw  $a0, ($t3)

    li  $v0, 1          # print C[i]
    syscall

    la  $a0, space      # print space
    li  $v0, 4          
    syscall

    addi    $t4, $t4, 1
    addi    $t3, $t3, 4

    j   print

Exit:
    li  $v0, 10
    syscall

0 个答案:

没有答案