Site hosted by Angelfire.com: Build your free website today!
logo    
murpheeOnline (section)
DeveloperZone (active section)
Nachos (active section)
Nachos stdio (active)
 
Webbuilder
JEdit SML Plugin
Langmixer stuff
 
OtherStuff (section)
About murphee (section)

Nachos Stdio

Well... not really. Actually it's only the beginning. It currently only contains the functions

  • vsprintf
  • printf (using vsprintf).
But if you are currently sweating to complete your Nachos assignement(s), you might like to use this, instead of using some primitive Write syscall. I tested this with the "%d" and the "%s" format specifiers (Note: with %s, don't use the dereference operator * in the parameter list, this does not seem to work).

I had intended to make this more complete, but getting the (vs)printf to work took more time than I had intended. The whole thing was trivial (the vsprintf code taken from Linux kernel v0.0.1 with some modifications eg. recoding some Intel Assembler code in C), but the devil is (as always) in the detail: printf uses variable arguments... which are one of the most platform dependant things in the whole C language. Using varargs means basically manually examining the stack and finding the desired args. After some heavy googling I finally found some the va-mips.h that implemented some necessary varargs macros, that do the stack examination for you. (These are normally part of the C standard library, but try finding that for Nachos...).

The rest of the time was spent fretting about weird false behaviours, that I thought were caused by a faulty or wrong macro, but were actually just some bug I had caused by commenting out some line (And if I *ever* catch someone writing one-liner if-statements without braces in my code, I will personally [censored] their [censored] and jump up and down on it............. ).

Oh yeah... you need at least a Write syscall, looking like "Write(char * buffer, int length, int fileHandle)". An identifier STDOUT must be defined to represent the stdout filehandle; ie. an example invocation of Write would be "Write(buf, 20, STDOUT)", which should write the first 20 contents of buf to the stdout.

Download Nachos Stdio

murpheeOnline