我为什么要获得的记忆是出于界限的?它是否试图将字符串与数字混合?如果那是问题,我该如何插入一个空白



该程序试图从用户中获取整数,然后从1个计数到达到该数字。这些数字应彼此对齐,因此我制作了空间:子负责在数字之前插入空格。我不确定为什么要从限制错误中获得内存,第一个可能性是我将其加载到$ A0中,但我不知道这是否是问题。如果有人可以把我朝正确的方向放置,我会很感激。

###### Begin Text Section ######
    .text
    .globl __start
__start:                        # execution starts here

la $0, prompt       #load address of prompt into $a0
li $v0, 4       #load call code number for printing string
syscall         #call to system to display prompt
li $v0, 5       #load call code number for reading Integer
syscall         #call to system to read integer
move $t0, $v0       #move the input to $t0 for savekeeping
add $t1, 1      #initialize $t1 = 1 as the counter
add $t2, 1      #initialize $t2 = 1 as the line counter
add $t3, 10     #initialize $t3 = 10 as the sentinel
add $t4, 1      #initialize $t4 = 1 as the space
la $a0, endl        #load address of endl into a0
li $v0, 4       #load call code for printing string
syscall         #call to system to display endl
WHILE:  bge $t1, $t0, ENDWHILE  #if $t1 >= $t0, branch to ENDWHILE
        addi $t1, $t1, 1    #increment $t1 =+1
SPACE:  bgt $t1, $t0, ESPACE    #if $t1 > $t0, branch to ESPACE
        mul $t4, $t1, 10    #$t4 = $t1 * 10
        bgt $t4, $t0, ESPACE    #if $t4 > $t0, branch to ESPACE
        la $a0, spac        #load address of space into a0
        li $v0, 4       #load call code number for printing string
        syscall         #call to system to print space
        j SPACE         #jump back to SPACE to loop again
ESPACE: move $a0, $t1       #move $t1 to $a0 for display
        li $v0, 1       #load call code number for printing integer
        syscall         #call to system to display integer
       la $a0, tab      #load address of tab into a0
       li $v0, 4        #load call code number to print string
       syscall          #call to system to Display tab

       add $t2, 1       
       beq $t2, $t3, NEWLIN 
       j WHILE          #jump back to WHILE to loop again
NEWLIN:la $a0, endl     #load address of endl into a0
       li $v0, 4        #load call code number to print string
       syscall          #call to system to Display endl
       add $t2, -10     #reinitializer $t2 = 1
       j WHILE          #jump back to WHILE to loop again
ENDWHILE:
       la $a0, endl     #load address of endl into a0
       li $v0, 4        #load call code number to print string
       syscall          #call to system to Display endl
       li $v0, 10       #load call code number for ending the program
       syscall          #call to system to end the program

###### Begin Data Section ######
    .data
prompt: .asciiz "Please enter a number to trigger Count: "  #Prompt the user 
spac: .asciiz " "       #The space that will help Align numbers
tab: .asciiz "    "     #To separate numbers from each other
endl: .asciiz "n"      #insert new line

是firs la $ 0,提示。应该是$ a0。$ 0用于汇编器。谢谢你们

最新更新