我正在尝试编写一个 MIPS 汇编程序来从用户那里获取两个整数,将其保存到数组中的内存中并打印出来。这就是我到目前为止所拥有的。我的程序打印了一些我没有输入的大数字。我对这个游戏很陌生。请有人帮忙!
这是我的代码:
.text
.globl main
main:
li $v0, 4
la $a0, prompt
syscall
li $t0, 0 #count for the loop to get two integers
getnum:
li $v0, 5 #read integer
syscall
sw $v0, num($s0) #save the integer from user input into num and $s0 has address for num, I'm not sure if i did this right
addi $s0, $s0, 4 # increment $s0 by 4 to save another integer
addi $t0, $t0, 1 #increment the counter
ble $t0, 1, getnum #if counter $t0, is less then or equal to 1, it will go through the loop again
printnum:
la $a0, num($s0) #load address of num to print
li $v0, 1 #print int
syscall
addi $s0, $s0, 4
addi $t1, $t1, 1
ble $t1, 1, printnum #does it twice
li $v0, 10
syscall
.data
num:
.word 0, 0 # i want to store my two numbers here
prompt:
.asciiz "Enter 2 positive integers: "