Write a MIPS assembly program that simulates a clock that prints out hour, minut
ID: 3829324 • Letter: W
Question
Write a MIPS assembly program that simulates a clock that prints out hour, minutes, and seconds on the screen. Here's what i have so far
Please put some comments on the parts you've edit
.data
newline:.asciiz " "
minutes:.asciiz "min: "
hours:.asciiz "hour: "
.text
#setup a variable as a counter,
#loop until appropriate count is reached
#increment seconds counter
li $a0, 0
li $t2, 30
li $t0, 0
li $t1, 0
counter:
addi $t1, $t1, 1
beq $t1, $t2, counter
addi $t0, $t0, 1
addi $a0, $t0, 0
li $v0, 1
syscall
li $t1, 0
la $a0, newline
li $v0, 4
syscall
j counter
Explanation / Answer
data
newline:.asciiz " "
seconds:.asciiz "sec"
minutes:.asciiz "min: "
hours:.asciiz "hour: "
.text
#setup a variable as a counter,
#loop until appropriate count is reached
#increment seconds counter
start:
li $t0, 0 #register to store value for hours.
li $t1, 0 #register to store value for minutes.
li $t2, -1 #register to store value for seconds.
Seconds:
addi $t2, $t2, 1
blt $t2, 60, Minutes
li $t2 ,0 #special when secs= 60
addi $t1, $t1, 1
Minutes:
blt $t1, 60, Hours
li $t1, 0 #special when minutes=60
addi $t0, $t0, 1
beq $t0 , 24, start #again timer starts from the begining.
Hours:
li $v0, 4
la $a0, seconds
syscall
li $v0, 1
move $a0, $t2 #print seconds.
syscall
li $v0, 4
la $a0, minutes
syscall
li $v0, 1
move $a0, $t1 #print minutes.
syscall
li $v0, 4
la $a0, hours
syscall
li $v0, 1 #print hours.
move $a0, $t0
syscall
li $v0, 4 #print newline.
la $a0, newline
syscall
j Seconds #jump back to Seconds.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.