Basic syntax of assembler syscalls for reading and printing integers and strings Some basic instructions and pseudo ops: li,la,move,add,sub,lb,sb,syscall,j,ble,bgt,etc. Understanding of the basic assembler directives: .data, .text, .asciiz, etc. An understanding of the basic concepts involved in creating functions in assembly: argument registers ($a0-$a3), return value registers ($v0-$v1), and the stack/stack pointer. Correct Usage of Registers and the Stack (As described in the handout from the MIPS Programmer's Handbook)
- Program written in any high level language you choose (C, C++, Pascal, Fortran, Cobol, Lisp, Java, etc.) Be sure to comment and fully test this version.
- A revised version of the program with comments and notes indicating how each part will be converted into assembly language.
Relevant info would include: where labels will be created (and label names) and which registers will be used and for what purposes. (Do this prior to writting the MIPS version of the program)- Program written in MIPS Assembly - This should be well commented
- "Test Cases" - What test cases did you use to verify that you're program worked?
This time your should compare your functions (m_atoi, ...) to the real C library version (atoi) to ensure that they work identically.
- Sample Runs: Show me the test cases for BOTH your high level language program and the Assembly version.
Use your test cases and comment the output to demonstrate that it worked as expected.
Your test cases should show that the program did work correctly.- Match the structure of the generated output as closely as possible
- Answer the following questions:
- What test cases did you use and why? (What was each case meant to test?)
(My advice is to write test cases BEFORE programming)
- What mistakes did you make in writing the program?
- How might you revise/improve the program?
- How long did this assignment take you?
- How long did you spend debugging?
- Were there any special debugging techniques that you used?
- Were there any special development techniques that you used?
Write the following functions for working with strings.
They must be proper functions in assembly language that follow the register and stack usage conventions.
m_isspace:
Function: Determines if a character is considered "whitespace" (I.e. should be ignored)
argument 0: a character
return value: non-zero if the character is white-space (space (' '),
form-feed ('\f'), newline ('\n'), carriage return ('\r'),
horizontal tab ('\t'), and vertical tab ('\v').
From the C man page:
int isspace(int C);isspace checks for white-space characters. In the "C" and "POSIX" locales, these are:
space (' '), form-feed ('\f'), newline ('\n'), carriage return ('\r'), horizontal tab ('\t'), and vertical tab ('\v')RETURN VALUEThe values returned are nonzero if the character C falls into the tested class, and a zero value if not.
m_toupper:
Function: Makes all letters uppercase and leaves non-letters alone.m_atoi:
argument 0: a character
return value: if the character is a lower case letter, the uppercase letter is returned. Otherwise, the original character is returned.
Hint: Remember the ASCII properties.
From the C man page:
int toupper(int c);toupper() converts the letter c to upper case, if possible.
If c is not an unsigned char value, or EOF, the behaviour of these functions is undefined.RETURN VALUEThe value returned is that of the converted letter, or c if the conversion was not possible.
Function: Converts ASCII characters into an integer.
NOTES: This function uses a "powers of 10" trick similiar to the powers of 2 trick.
This function ignores initial white space and MUST call m_isspace.
The number may have a '+' or a '-' as the 1st character (after the whitespace).
argument 0: a pointer to the character array to convert into an integer.
return value: an integer representing the value of the entered number.
Hint: Don't forget the ASCII properties of '0'-'9'.
From the C man page:
int atoi(char *nptr);The atoi() function converts the initial portion of the string pointed to by nptr to int.
The behaviour is the same as:
strtol(nptr, NULL, 10);
except that atoi() does not detect errors.RETURN VALUEThe converted value.Some Examples of Valid Inputs:
"\t \n+123" = 123
" " = 0
" -123" = -123
" -123" = -123
" - 123" = 0
For Extra credit you can implement strtol and also implement atoi differently. Click here for details
SPIM Setup:For this program you SHOULD load the trap file
You need to be sure that you are NOT emulating a bare machine