darksky
darksky

Reputation: 21049

Input Integers in MIPS Assembly

I am writing a program in MIPS that will read in signed integers from the keyboard.

Is there a way to read input like that, the way we do in higher level languages from a console? If not, I already have an array as follows:

          .data
intdata:  .word  3, 23, -5, 57, -12, 41, 39, -43, 40, 30     # input of integers

Can I operate on the array without knowing its length? So loop until at the end of the array. Or should I put another argument which holds the length of the array?

Upvotes: 0

Views: 789

Answers (1)

m0skit0
m0skit0

Reputation: 25874

This is assembly, you don't have such high level functions. Most simulators do, however, offer some functionality to read/write through I/O. This is done through syscalls. You should read the simulator's documentation, or tell us what simulator you're using (if using any).

You can't operate with an array without knowing its length. You say "loop until the end of the array", but what's the end of the array? How would you know when programming? You have two basic solutions for this: either use another variable that holds array length or you use an end of array marker (a value that will let you know when the array has ended).

Upvotes: 1

Related Questions