MIPS如何存储用户输入并打印出来 [英] MIPS how to store user input and print it out
本文介绍了MIPS如何存储用户输入并打印出来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我应该为这个问题做的是,我需要存储这些值,并打印出一个矩阵,用户要求输入行数、列数和元素的值,现在我甚至不知道打印/存储部分是否正确,我试图打印输入的单个字符串,但不起作用
.text
.globl main
main:
addi $v0, $0, 4
la $a0, str1
syscall #printing str1
addi $v0, $0, 5
syscall
la $t1, M1_1
sw $v0, 0($t1) #reading and storing the number of rows
addi $v0, $0, 4
la $a0, str2
syscall #printing str2
addi $v0, $0, 5
syscall
la $t2, M1_2
sw $v0, 0($t2) #reading and storing the number of columns
addi $v0, $0, 4
la $a0, str3
syscall #printing str3
addi $v0, $0, 5
syscall
la $t3, M1_3
sw $v0, 0($t3) #reading and storing the value of element
.data
str1:.asciiz ""Please enter the number of rows in the matrix
"
str2:.asciiz ""Please enter the number of columns
"
str3:.asciiz ""Please enter the elements of the matrix
"
.align 2
M1:.space 256
M1_1:.space 4
M1_2:.space 4
M1_3:.space 4
M2:.space 256
M2_2:.space 4
推荐答案
在单步执行代码后,sw $v0, 0($t1)
行似乎有问题。我建议使用move
命令,而不是使用sw
将输入移动到寄存器$t0
。在下面的代码示例中,我修改了您的代码,以演示如何将接收到的值作为输入保存到寄存器$t0
:
.text
.globl main
main:
sub $sp , $sp , 4 # push stack
sw $ra , 0 ( $sp ) # save return address
addi $v0 , $0 , 4
la $a0 , str1
syscall #printing str1
addi $v0 , $0 , 5
syscall #get input
move $t0 , $v0 # save input in $t0
move $a0 , $v0
addi $v0 , $0 , 1
syscall #print first input
...
有关如何使用每条MIPS指令的详细信息,请view this page。
这篇关于MIPS如何存储用户输入并打印出来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文