Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need to write a program in mips assembly that will create a mini calendar with inputs for month and year. The code I have

I need to write a program in mips assembly that will create a mini calendar with inputs for month and year. The code I have so far is below, but I am having trouble moving the first day to align correclty as well as printing the rest of the days as the example shows in the picture:
.data
text1: .asciiz "Mini Calendar by A. Palacios
"
mprompt: .asciiz "
Enter the month? "
yprompt: .asciiz "Enter the year? "
space: .asciiz ""
newline: .asciiz "
"
days: .word 31,28,31,30,31,30,31,31,30,31,30,31
dOfWeek: .asciiz "Sun Mon Tue Wed Thu Fri Sat
"
daySpace: .asciiz ""
oneSpace: .asciiz ""
twoSpaces: .asciiz ""
.text
.globl main
main:
li $v0,4
la $a0, text1
syscall
li $v0,4
la $a0, mprompt
syscall
li $v0,5
syscall
move $t1, $v0
li $v0,4
la $a0, yprompt
syscall
li $v0,5
syscall
move $t0, $v0
blt $t1,3, adjust_month
b calculate_day
adjust_month:
addi $t1, $t1,12
addi $t0, $t0,-1
b calculate_day
calculate_day:
li $t5,1
li $t6,13
addi $t7, $t1,1
mul $t6, $t6, $t7
div $t6, $t6,5
mflo $t6
andi $t7, $t0,0x63
srl $t8, $t0,2
add $t5, $t5, $t6
add $t5, $t5, $t7
srl $t6, $t7,2
add $t5, $t5, $t6
srl $t6, $t8,2
add $t5, $t5, $t6
li $t6,2
mul $t6, $t8, $t6
sub $t5, $t5, $t6
andi $t2, $t5,0x07
addi $t2, $t2,1
rem $t2, $t0,4
bnez $t2, not_leap
rem $t2, $t0,100
bnez $t2, leap
rem $t2, $t0,400
beqz $t2, leap
b not_leap
not_leap:
li $t2,0
b continue
leap:
li $t2,1
continue:
addi $t1, $t1,-1
sll $t1, $t1,2
lw $t3, days($t1)
beq $t1,1, check_leap
b print_calendar
check_leap:
beq $t2,1, feb_leap_year
b print_calendar
feb_leap_year:
addi $t3, $t3,1
b print_calendar
print_calendar:
li $v0,4
la $a0, dOfWeek
syscall
move $t4, $t2
li $t5,0
blt $t5, $t4, print_initial_spaces
b print_days
print_initial_spaces:
li $v0,4
la $a0, daySpace
syscall
addi $t5, $t5,1
blt $t5, $t4, print_initial_spaces
print_days:
li $t5,1
move $t6, $t4
print_days_loop:
ble $t5, $t3, print_day_number
b end_printing_days
print_day_number:
beqz $t6, print_newline
li $v0,1
move $a0, $t5
syscall
blt $t5,10, print_one_space
b update_day
print_one_space:
li $v0,4
la $a0, oneSpace
syscall
b update_day
print_newline:
li $v0,4
la $a0, newline
syscall
li $t6,0
li $v0,1
move $a0, $t5
syscall
blt $t5,10, print_one_space
b update_day
update_day:
addi $t5, $t5,1
addi $t6, $t6,1
rem $t6, $t6,7
b print_days_loop
end_printing_days:
li $v0,10
syscall
example:
Mini Calendar by F. Last
Enter the month? 3
Enter the year? 2024
March.2024 n
Sun.Mon.Tue.Wed.Thu.Fri.Sat.Sun N
......................1...2N
..3...4...5...6...7...8...9N
.10..11..12..13..14..15..16N
.17..18..19..20..21..22..23N
.24..25..26..27..28..29..30N
.31N
. are spaces, N is new line character.
must be written in MIPS Assembly.
image text in transcribed

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

Graph Databases New Opportunities For Connected Data

Authors: Ian Robinson, Jim Webber, Emil Eifrem

2nd Edition

1491930896, 978-1491930892

Students also viewed these Databases questions

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago