This isn't possible with MARS, as far as I can tell. The toy system calls it provides don't allow you to even move the cursor position or enable/disable terminal echo.
(It does have a "bitmap graphics" mode, so I guess you could hand-draw *
glyphs on that display while reading keyboard input. But it has no functions for drawing text in the bitmap.)
In POSIX on a text terminal you'd do that by disabling TTY echo and putting the terminal in raw mode (with an ioctl
system call).
Then read()
system calls will return as soon as any input is ready instead of a full line, so you'd have your program print *
after reading a character. (And you'd have to manually support backspace line-editing).
I don't see MARS support for any of that in its list of system calls.
http://courses.missouristate.edu/KenVollmar/mars/Help/SyscallHelp.html
You'd have to add new system calls: http://courses.missouristate.edu/KenVollmar/mars/Help/MarsHelpTools.html documents how you can write a Java class to handle a new system call and hook it into MARS.
SPIM does have MMIO access to a "terminal" device where you can read keyboard input separately from it being echoed on the screen, but MARS doesn't document anything like that. I think MARS keyboard / screen I/O is only available through system calls, and the complete set covered by the documentation doesn't allow it.
It appears that printing a '\b'
(ASCII backspace) character doesn't work to move the cursor backward over something the user typed. You just get a white box with a black outline.
Maybe if you run MARS in non-GUI mode from the command line inside XTerm (or Gnome-terminal or Konsole) on a Linux desktop, or a MacOS X terminal window,
you could get MARS output going to a terminal that does process cursor-movement escape sequences and codes.
The last hope (that I haven't tried) is if carriage-return (\r
) moves the character to the start of the line without advancing to the next line. In that case, you could maybe print over what the user typed by re-printing the whole line of enough *
characters.
But even if that works, it will probably flash on screen as its typed, at least momentarily before your program overwrites it.