Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

User Change the function time 2 string so that DING is shown instead of time, every minute at xx: 0 0 . At xx: 0

User
Change the function time2string so that "DING" is shown instead of time, every minute at xx:00. At xx:01, time should be shown normally again. You are not allowed to change any other function or subroutine.
Example printout:
59:57
59:58
59:59
DING
00:01
00:02
00:03
00:04
...
The code is:
.global time2string, delay
.macro PUSH reg
addi $sp,$sp,-4
sw \reg,0($sp)
.endm
.macro POP reg
lw \reg,0($sp)
addi $sp,$sp,4
.endm
#
# Please add your own code below this line
#
.text
hexasc:
andi $v0, $a0,0xF # Mask out all but the 4 least significant bits
li $t0,9 # Compare with 9 to determine if it's a digit or a letter
blt $v0, $t0, is_digit # Branch if less than 9(it's a digit)
addi $v0, $v0,7 # Adjust for letters (A starts at ASCII 65)
is_digit:
addi $v0, $v0,48 # Adjust for ASCII digits (0 starts at ASCII 48)
jr $ra # Return
delay:
# Save registers
addi $sp, $sp,-12
sw $s0,0($sp)
sw $s1,4($sp)
sw $s2,8($sp)
# Initialize loop counter
li $s0,4711 # The constant 4711(adjust as needed)
# Outer loop: decrement ms
outer_loop:
bnez $a0, inner_loop # if ms is not zero, go to inner loop
j end_delay # if ms is zero, exit the delay
inner_loop:
# Inner loop: decrement inner loop counter
bnez $s0, inner_loop # if counter is not zero, continue inner loop
addi $a0, $a0,-1 # decrement ms
li $s0,4711 # reset inner loop counter
j outer_loop # go to outer loop
# Restore registers and return
end_delay:
lw $s0,0($sp)
lw $s1,4($sp)
lw $s2,8($sp)
addi $sp, $sp,12
jr $ra
time2string:
PUSH $s0
PUSH $s1
PUSH $t0
move $s0, $a0
move $s1, $a1
# x0:00
andi $a0, $s1,0xF000
srl $a0, $a0,12
jal hexasc
sb $v0,5($s0)
# 0x:00
andi $a0, $s1,0xF00
srl $a0, $a0,8
jal hexasc
sb $v0,4($s0)
# colon
li $a0,0x3A
sb $a0,3($s0)
# 00:X0
andi $a0, $s1,0xF0
srl $a0, $a0,4
jal hexasc
sb $v0,2($s0)
# 00:0X
andi $a0, $s1,0xF
jal hexasc
sb $v0,1($s0)
# null-byte
li $a0,0x00
sb $a0,0($s0)
# Restore original s1, s2, and s0 values
POP $t0
POP $s1
POP $s0
jr $ra
nop

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Ai And The Lottery Defying Odds With Intelligent Prediction

Authors: Gary Covella Ph D

1st Edition

B0CND1ZB98, 979-8223302568

More Books

Students also viewed these Databases questions