This program reads a valid date (3 integers being date (d), month (m), year
using the Zeller's algorithm described below:
.data
day: .asciiz "Please enter the date: "
dayA: .word day
month: .asciiz "Please enter the month: "
monthA: .word month
year: .asciiz "Please enter the year: "
yearA: .word year
.text
main: #-------------------------------------------------------
# Write a program that reads a valid date (3 integers being date (d), month (m), year
# the week (Sun, Mon, Tue, etc.) using the Zeller's algorithm described below:
#
# if (m <= 2){
# m = m + 12;
# y = y - 1;
# }
# tmp1 = (26 * (m + 1)) / 10;
# tmp2 = (125 * y) / 100;
# tmp3 = d + tmp1 + tmp2 – (y / 100) + (y / 400) - 1;
# dow = tmp3 % 7;
#
# The resulting integer in dow (day-of-week) denotes the day. If dow equals 0, then the day is Sunday. If dow
# equals 1 then the day is Monday, and so on for the rest of the days in a week. Your program should output the
# day in words depending on the value of dow.
#-------------------------------------------------------
lw $a0, dayA($0)
addi $v0, $0, 4
syscall
addi $v0, $0, 5
syscall
add $s0, $0, $v0
lw $a0, monthA($0)
addi $v0, $0, 4
syscall
addi $v0, $0, 5
syscall
add $s1, $0, $v0
lw $a0, yearA($0)
addi $v0, $0, 4
syscall
addi $v0, $0, 5
syscall
add $s2, $0, $v0
#----------------------
addi $t4, $0, 2
sgt $t0, $s1, $t4
bne $t0, $0, skip
addi $s1, $s1, 12
addi $t4, $0, 1
sub $s2, $s2, $t4
skip: addi $s1, $s1, 1
sll $t0, $s1, 4
add $t1, $0, $t0
sll $t0, $s1, 1
add $t1, $t1, $t0
sll $t0, $s1, 3
add $t1, $t1, $t0
addi $t0, $0, 10
div $t1, $t0
mflo $a0
add $t1, $0, $a0
sll $t0, $s2, 6
add $t2, $0, $t0
sll $t0, $s2, 5
add $t2, $t2, $t0
sll $t0, $s2, 4
add $t2, $t2, $t0
sll $t0, $s2, 3
add $t2, $t2, $t0
sll $t0, $s2, 2
add $t2, $t2, $t0
add $t2, $t2, $s2
addi $t0, $0, 100
div $t2, $t0
mflo $a0
add $t2, $0, $a0
add $t3, $s0, $t1
add $t3, $t3, $t2
addi $t0, $0, 100
div $s2, $t0
mflo $a0
sub $t3, $t3, $a0
addi $t0, $0, 400
div $s2, $t0
mflo $a0
add $t3, $t3, $a0
addi $t4, $0, 1
sub $t3, $t3, $t4
addi $t0, $0, 7
div $t3, $t0
mfhi $a0
add $t2, $0, $a0
addi $v0, $0, 1
syscall
#-----------------------
jr $ra
浙公网安备 33010602011771号