简体   繁体   中英

Getting an error when trying to fill an array with Strings and ints in MIPS?

So I need to fill an array in MIPS with 10 "records", which consist of an employee's name, age, and salary. The employee's name is a max of 40 characters and both the age and salary are supposed to be integers. However, when testing this loop I wrote, I always get an "invalid integer input (syscall 5)" for line 18 after I go through the first 5 employees and I type "Emp6" and press enter and I can't seem to figure out why. Any help would be greatly appreciated!

Test Input:

Emp1
1
1
Emp2
2
2
Emp3
3
3
Emp4
4
4
Emp5
5
5
Emp6

Error Code:

Error in line 18: Runtime exception at 0x00400020: invalid integer input (syscall 5)

Go: execution terminated with errors.

Your main problem seems to be that the read_string system call expects the buffer size in $a1 , but you use that for your loop counter. Thus, you eventually run out of space, and there will be unprocessed text left in the input buffer which will then be read by the subsequent read_int and that blows up.

Further problem is that you keep incrementing $a0 but fail to account for that in your addressing. Also sw $v0, 0($a0) doesn't make much sense, the string has been read into memory already, $v0 has nothing interesting in it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM