2016-02-29 56 views
0

由於第一次運行inputLoop之後的某些原因,提示用戶輸入員工姓名的代碼的第一部分不起作用?另外,我在第一次輸入循環中的薪水後打印出爲第一名僱員填寫的名稱,然後我必須按Enter鍵以再次詢問年齡。這裏是代碼,下面是我迄今爲止的樣例輸出。MIPS在循環的第二次運行時沒有打印提示

.data 
employees: .space 480 
prompt1: .asciiz "\n Please input the name of the employee: " 
prompt2: .asciiz "\n Please input the age of the employee: " 
prompt3: .asciiz "\n Please input the salary of the employee: " 
newline: .asciiz "\n" 
display1: .asciiz "\n Employee Name" 
display2: .asciiz "    Age" 
display3: .asciiz "    Salary" 
.text 
.globl main 
main: 
    li $t0, 5 
    li $t1, 0 
    jal employeeInfo 
    li $v0, 10 
    syscall 
employeeInfo: 
    inputLoop: 
     beqz $t0, printEmployeesPre 
     la  $a0, prompt1 
     li  $v0, 4 
     syscall 
     li $v0, 8 
     syscall 
     sw $v0, employees($t1) 
     add  $t1, $t1, 40 
     la  $a0, prompt2  
     li  $v0, 4 
     syscall 
     li $v0, 5 
     syscall 
     sw $v0, employees($t1) 
     add  $t1, $t1, 4 
     la  $a0, prompt3  
     li  $v0, 4 
     syscall 
     li $v0, 5 
     syscall 
     sw $v0, employees($t1) 
     add  $t1, $t1, 4 
     addi $t0, $t0, -1 
     b inputLoop 

這裏是輸出樣本:

請輸入員工的名:杆

請輸入員工的年齡:6

請輸入工資的僱員:4

請輸入僱員的年齡:6

請輸入僱員的薪水:7

回答

1

你似乎誤解系統調用8(read_string)是如何工作的。
如您所知can see here它需要兩個參數:$a0應該包含應該存儲字符串的緩衝區的地址,並且應該包含要讀取的最大字符數。 $v0中沒有返回任何內容。

相關問題