1

I've been learning a bit about MIPS and I'm required to write a Factorial program that takes in input and prints out nth Factorial. Positive integers are not a problem, and their spec requires me to print 1 for negative input which is fine since branch operation blez does the job.

The twist here is that I'm also required to accept text as input as well in which case I'd also print 1 instead of the usual factorial. Is there any way I can simultaneously read something then process it depending on the data type, or perhaps I can do something about the Invalid Integer Input exception I get when I type in "first" instead of an int. I'm kind of lost here so any advice would be greatly appreciated.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Calahan
  • 35
  • 6
  • You can read characters, and check if they're digits. If so, convert ASCII -> integer yourself. I assume you're using MARS or SPIM, because Linux (or other real OSes) running on MIPS doesn't have integer-input system calls in the first place, just text. – Peter Cordes Aug 13 '18 at 10:12
  • Yeah, I'm currently using QtSpim and MARS. – Calahan Aug 13 '18 at 10:19

0 Answers0