Answered step by step
Verified Expert Solution
Question
1 Approved Answer
# timetemplate.asm a ) Rewrite the following C function as an assembly - language subroutine with the same behavior. void delay ( int ms )
# timetemplate.asm
a Rewrite the following function as an assemblylanguage subroutine with the same behavior.
void delay int ms Wait a number of milliseconds, specified by the parameter value.
int ;
while
;
Executing the following for loop should take
for ;; The constant must be easy to change!
Do nothing.
Important note for all subroutines reprise: When a subroutine returns, registers $$$ $sp
$ 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 $ and $ may not be modified at all; these
registers are reserved for interrupthandling code. All other register contents may be modified by
any subroutine.
b Replace the threeline delay subroutine from the previous Assignment, with your own
assemblylanguage subroutine de lay in file timetemplate.asm.
c Test your program using MARS. Adjust the constant in the for loop to get a delay of
when de lay is called with a parameter value of and a delay of when de lay is called
with a parameter value of macro PUSH reg
addi $sp$sp
sw reg,$sp
endmacro
macro POP reg
lw reg,$sp
addi $sp$sp
endmacro
data
align
mytime: word x
timstr: ascii "text more text lots of text
text
main:
# print timstr
la $atimstr
li $v
syscall
nop
# wait a little
li $a
jal delay
nop
# call tick
la $amytime
jal tick
nop
# call your function timestring
la $atimstr
la $tmytime
lw $a$t
jal timestring
nop
# print a newline
li $a
li $v
syscall
nop
# go back and do it all again
j main
nop
# tick: update time pointed to by $a
tick: lw $t$a # get time
addiu $t$t # increase
andi $t$txf # check lowest digit
sltiu $t$txa # if digit a okay
bnez $ttiend
nop
addiu $t$tx # adjust lowest digit
andi $t$txf # check next digit
sltiu $t$tx # if digit okay
bnez $ttiend
nop
addiu $t$txa # adjust digit
andi $t$txf # check minute digit
sltiu $t$txa # if digit a okay
bnez $ttiend
nop
addiu $t$tx # adjust digit
andi $t$txf # check last digit
sltiu $t$tx # if digit okay
bnez $ttiend
nop
addiu $t$txa # adjust last digit
tiend: sw $t$a # save updated result
jr $ra # return
nop
# you can write your code for subroutine "hexasc" below this line
#
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started