地址超出范围-从数组存储和加载字符串

时间:2019-05-05 04:19:09

标签: arrays assembly mips

我有2个数组:1个用于存储所有名称,2个用于存储其标记> = 4的名称 我的目标是打印标记大于或等于4的人员列表 但是,系统调用有一些地址超出范围的问题,这可能是由于我在2个数组之间存储和加载字符串引起的。我认同。 希望有人可以帮助我指出代码中的原因。 非常感谢!

我正在使用火星练习Mips。

.data  
    array:      .align 2
            .space  80
    array_pass: .align 2
            .space  80
    string:     .space  20000
        enter_name:     .asciiz "Enter a name:"
        enter_num:  .asciiz "Enter number of names:"
        enter_mark:     .asciiz "Enter his/her Math mark:"
        list_pass:  .asciiz "List of students passing Math:"    
    newline:    .asciiz "\n"
.text
main:
    li  $v0,4           # print sentence: Enter number of name
        la  $a0,enter_num
        syscall                         
        li  $v0,5           # read number of name
        syscall

        add     $s0,$v0,$zero           # store number of name from v0 to s0    
    la  $t0,array       # t0 = arrdess of array 
    la  $t6,array_pass      # t6 = address of array_pass
        addi    $t1,$zero,1         # count_of_array = 1    
        add     $t7,$zero,$zero         # pass_count = 0
        li  $t3,4           # the MARK TO PASS
        la  $s2,string              # s2 = address of string
read_string:
        bgt $t1,$s0,printName   # if counter > number of names then go to printName
        nop     
        li  $v0,4           # print sentence: Enter a name
        la  $a0,enter_name
        syscall
    move    $a0,$s2                 # copy content from s2 to a0, s2 = first element of string
        li  $a1,20          # size = 20 in decimal = 14 in hexa
        li  $v0,8           # read that name 
        syscall 
        sw  $a0,0($t0)      # store that name to array, $a0 = pointer to 0(t0)
        move    $s4,$a0         # copy content of a0 to s4

        li  $v0,4           # print sentence: Enter his/her mark
        la  $a0,enter_mark
        syscall                 
        li  $v0,5           # read that mark
        syscall
        add     $t2,$v0,$zero       # current mark stored in t2
        bge     $t2,$t3,storeName
        j   update 
storeName:
    sw  $s4,0($t6)          
    addi    $t6,$t6,4
    addi    $t7,$t7,1
update: 
    addi    $t0,$t0,4   
        addi    $t1,$t1,1
        addi    $s2,$s2,20 
        j   read_string      
printName:
    add     $t0,$zero,$zero         # index of array
        addi    $t1,$zero,1             # counter = 1
    la      $a0,list_pass       # print sentence: List student passing Math
    li      $v0,4
        syscall
while:
    bge     $t1,$t7,done    
        lw  $s3,0($t6)
        li      $v0,4
        move    $a0,$s3
        syscall
        jal     new_line    
        addi    $t6,$t6,4               # advance array index
        addi    $t1,$t1,1               # advance count
        j       while
new_line:
        la      $a0,newline
        li      $v0,4
        syscall
        jr      $ra
done:
        li      $v0,10
        syscall


0 个答案:

没有答案