user2243125
user2243125

Reputation: 5

MIPS not printing prompt on second run of loop

For some reason after the first run of the inputLoop the first part of the code that prompts the user for the name of the employee is not working? Also, the name I put for the first employee is printed out after I finish entering the salary of the first time in the loop and then I have to press enter for it to ask for the age again. Here is the code and below is a sample output that I have so far.

.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

Here is the output sample:

Please input the name of the employee: rod

Please input the age of the employee: 6

Please input the salary of the employee: 4

rod

Please input the age of the employee: 6

Please input the salary of the employee: 7

Upvotes: 0

Views: 189

Answers (1)

Michael
Michael

Reputation: 58427

You seem to have misunderstood how system call 8 (read_string) works.
As you can see here it expects two arguments: $a0 should contain the address of the buffer where the string should be stored, and $a1 should contain the maximum number of characters to read. Nothing is returned in $v0.

Upvotes: 1

Related Questions