我正在尝试编写与此高级语言代码等效的 MIPS 代码:
i = 0;
n = str2; //supplied by user from console
while(i < n) {
System.out.println(str1); //str1 is supplied by user from console
i++;
}
System.exit(0);
这是我的 MIPS 代码:
.data
str1: .asciiz "Enter the first integer: "
str2: .asciiz "Enter the second integer: "
newline: .asciiz "\n"
.text # instructions follow this line
main: # indicates start of code (first instruction to execute)
add $s0,$zero, $zero # $s0 = 0
add $s1, $zero, str2 # $s1 = 0
slt $t0, $s0, $s1
beq $t0, $zero, Exit
li $v0, 1 # load appropriate system call code into register $v0;
# code for printing integer is 1
move $a0, str1 # move integer to be printed into $a0: $a0 = str1
syscall
addi $s0, $s0, 1 # $s0++
j loop #jump back to loop
Exit: nop
我正在尝试将第一个数字打印为第二个数字的值的次数。示例:第一个数字:2,第二个数字:4,所以打印 2 四次