我如何读取字符数组,然后以MIPS格式输出

时间:2017-06-28 07:12:11

标签: mips

我无法弄明白,我得到的唯一输出是一个小方,我不确定哪一方我做错了bc theres无法检查,任何帮助将不胜感激:]

#######practice with char arrays

.data
chararray: .space 500
msg:.asciiz "enter in 5 chars, separated by enter:\n"
sdg:.asciiz "printing...\n"
.text
.globl main

main:
    addi $t3, $zero, 0
    addi $t2, $zero, 0
    addi $t1, $zero, 0
    addi $t0, $zero, 0


    la $t7, chararray   #puts char array first address in t7
    lb $t1, 0($t7)  #puts first char in t1

    li $v0,12           #reads in char
    syscall
    move $t4, $v0       #moves char into $t4

    sw $t4, chararray($t0)  #moves t4 into array first location



    lb $t6, chararray($t0)          #puts current array location's value into t6
    li $v0,11           #prepares to print char
    syscall             #prints current array char

    jr $ra

1 个答案:

答案 0 :(得分:1)

请尝试以下程序执行您所需的操作。它从控制台读取一个char数组,并将数组打印到控制台。

.data
chararray: .space 500
msg:.asciiz "enter in 5 chars, separated by enter:\n""
sdg:.asciiz "printing...\n"

.text
.globl main
main:
    la $a0,msg #Load and print string asking for string
    li $v0,4
    syscall

    li $v0,8 #take in input
    la $a0, chararray #load byte space into address
    li $a1, 20 # allot the byte space for string
    move $t0,$a0 #save string to t0
    syscall

    la $a0,sdg #load and print "you wrote" string
    li $v0,4
    syscall

    la $a0, chararray #reload byte space to primary address
    move $a0,$t0 # primary address = t0 address (load pointer)
    li $v0,4 # print string
    syscall
    li $v0,10 #end program
    syscall