Question: Change the function time 2 string so that every hour at 0 0 : 0 0 , time is shown as HOUR. At 0 0
Change the function timestring so that every hour at : time is shown as HOUR. At : time should be shown normally again. You are not allowed to change any other function or subroutine. Note: the tick function supplied in mipslabfunc.c counts days, hours, minutes, and seconds. When mytime is : calling tick will increment mytime to ::one hour, zero minutes, zero seconds
Example printout:
:
:
:
DING
:
:
:
:
The code is:
global timestring, delay
macro PUSH reg
addi $sp$sp
sw reg$sp
endm
macro POP reg
lw reg$sp
addi $sp$sp
endm
#
# Please add your own code below this line
#
text
hexasc:
andi $v $axF # Mask out all but the least significant bits
li $t # Compare with to determine if it's a digit or a letter
blt $v $t isdigit # Branch if less than its a digit
addi $v $v # Adjust for letters A starts at ASCII
isdigit:
addi $v $v # Adjust for ASCII digits starts at ASCII
jr $ra # Return
delay:
# Save registers
addi $sp $sp
sw $s$sp
sw $s$sp
sw $s$sp
# Initialize loop counter
li $s # The constant adjust as needed
# Outer loop: decrement ms
outerloop:
bnez $a innerloop # if ms is not zero, go to inner loop
j enddelay # if ms is zero, exit the delay
innerloop:
# Inner loop: decrement inner loop counter
bnez $s innerloop # if counter is not zero, continue inner loop
addi $a $a # decrement ms
li $s # reset inner loop counter
j outerloop # go to outer loop
# Restore registers and return
enddelay:
lw $s$sp
lw $s$sp
lw $s$sp
addi $sp $sp
jr $ra
timestring:
PUSH $s
PUSH $s
PUSH $t
move $s $a
move $s $a
# x:
andi $a $sxF
srl $a $a
jal hexasc
sb $v$s
# x:
andi $a $sxF
srl $a $a
jal hexasc
sb $v$s
# colon
li $axA
sb $a$s
# :X
andi $a $sxF
srl $a $a
jal hexasc
sb $v$s
# :X
andi $a $sxF
jal hexasc
sb $v$s
# nullbyte
li $ax
sb $a$s
# Restore original s s and s values
POP $t
POP $s
POP $s
jr $ra
nop
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
