c) Write a small function, like this, at the end of file timetemplate.asm.
delay:
jr $ra
nop
This is a temporary version of the delay function. You will soon write a more useful version.
d) You will now write a function that converts time-info into a string of printable characters, with a
null-byte as an end-of-string-marker.
At the end of file timetemplate.asm, add an assembly-language subroutine with the following
specification.
Name: The subroutine must be called time2string.
Parameters (two): Register $a0 contains the address of an area in memory, suitably large for the
output from time2string. The 16 least significant bits of register $a1 contains time-info, organized
as four NBCD-coded digits of 4 bits each. All other bits in register $a1 can have any value and
must be ignored. Example: register $a0 can contain the address 0x10010004, and register $a1 can
contain the value 0x00001653.
Return value: None.
Required action: The following sequence of six characters must be written to the area in memory
pointed to by register $a0.
1. Two ASCII-coded digits showing the number of minutes, according to the two more
significant NBCD-coded digits of the input parameter. Example: '1', '6' (ASCII 0x31, 0x36).
2. A colon character (ASCII :, code 0x3A).
3. Two ASCII-coded digits showing the number of seconds, according to the two less
significant NBCD-coded digits of the input parameter. Example: '5', '3' (ASCII 0x35, 0x33).
4. A null byte (ASCII NUL, code 0x00).
Note: You must use the function hexasc to convert each NBCD-coded digit into the corresponding
ASCII code. Test your program using the MARS simulator.
Hint: The macros PUSH and POP are useful for saving and restoring registers.
Pitfall: Even when calling your own subroutine hexasc, you must save and restore registers just as
if you didn't know anything about the internals of hexasc.
Important note for all subroutines (reprise): When a subroutine returns, registers $s0–$s7, $gp, $sp,
$fp, and $ra must have the same contents as when the subroutine was called. If a subroutine uses
any of these registers, the original contents must be saved, and restored before the subroutine
returns. As a special case, the contents of registers $k0 and $k1 may not be modified at all; these
registers are reserved for interrupt-handling code. All other register contents may be modified by
any subroutine.
e) When testing your function, insert a breakpoint at the instruction j main. The breakpoint will
cause MARS to pause your program at the breakpoint, just before jumping back for the next
iteration. To insert a breakpoint, check the box in the Bkpt column for the instruction j main. See
the screenshow below.
IS1200/IS1500 – Lab 1 – Assembly Programming Page 7