Hackathon Challenge Objective: Write code to display the number of days, given t
ID: 3726312 • Letter: H
Question
Hackathon Challenge Objective: Write code to display the number of days, given the month The problem is broken into phases. Phase 1 earns up to 3 points. Phase 2 earns an additional 2 points. Points will be added to Exam 3 Phase 1 (3 points): Implement the following program in MIPS: * In the main program switch(month) o get month from the user o if the user enters 0, exit the program o if the month is not 1-12, print an error message and repeat print the month and number of days as shown in the sample run case 4: case 6: case 9: case 11: o Write a function to determine the number of days by implementing the switch statement shown in the box irn MIPS days 30; break; . case 1: case 3: case 5: case 7: case 8: case 10: case 12: Sample Phase 1 run Please enter the month 1 12, enter to quit: Number of days in month 1 is: 31 Please enter the month 1- 12, enter 0 to quit: 5 Number of days in month 5 is: 31 Please enter the month 1 12, enter 0 to quit: 12 Number of days in month 12 is: 31 Please enter the month 1-12, enter to quit: 13 Month must be between 1 and 12 Please enter the month 1 12, enter 0 to quit: -5 Month must be between 1 and 12 Please enter the month 1 12, enter to quit: 0 days 31; break; case 2: days 28; break; Phase 2 (2 additional points): Instead of printing the number of the month, print the 3 character abbreviation as shown in this sample run Please enter the month 1 12, enter 0 to quit: 2 Number of days in Feb is: 28 Please enter the month 1 12, enter 0 to quit: 4 Number of days in Apr is: 30 Please enter the month 1 12, enter to quit: 8 Number of days in Aug is: 31 Please enter the month 1- 12, enter 0 to quit: 0 -program is finished running Upload your.asm file to eLearning This is an individual task, programs will be checked for similarity across sections.Explanation / Answer
Here is the code,
.LC0:
.string "Enter month number (1-12): "
.LC1:
.string "%d"
.LC2:
.string "31 days"
.LC3:
.string "28 or 29 days"
.LC4:
.string "30 days"
.LC5:
.string "Invalid input! Please enter month number between (1-12)."
main:
push rbp
mov rbp, rsp
sub rsp, 16
mov edi, OFFSET FLAT:.LC0
mov eax, 0
call printf
lea rax, [rbp-4]
mov rsi, rax
mov edi, OFFSET FLAT:.LC1
mov eax, 0
call scanf
mov eax, DWORD PTR [rbp-4]
cmp eax, 1
jne .L2
mov edi, OFFSET FLAT:.LC2
mov eax, 0
call printf
jmp .L3
.L2:
mov eax, DWORD PTR [rbp-4]
cmp eax, 2
jne .L4
mov edi, OFFSET FLAT:.LC3
mov eax, 0
call printf
jmp .L3
.L4:
mov eax, DWORD PTR [rbp-4]
cmp eax, 3
jne .L5
mov edi, OFFSET FLAT:.LC2
mov eax, 0
call printf
jmp .L3
.L5:
mov eax, DWORD PTR [rbp-4]
cmp eax, 4
jne .L6
mov edi, OFFSET FLAT:.LC4
mov eax, 0
call printf
jmp .L3
.L6:
mov eax, DWORD PTR [rbp-4]
cmp eax, 5
jne .L7
mov edi, OFFSET FLAT:.LC2
mov eax, 0
call printf
jmp .L3
.L7:
mov eax, DWORD PTR [rbp-4]
cmp eax, 6
jne .L8
mov edi, OFFSET FLAT:.LC4
mov eax, 0
call printf
jmp .L3
.L8:
mov eax, DWORD PTR [rbp-4]
cmp eax, 7
jne .L9
mov edi, OFFSET FLAT:.LC2
mov eax, 0
call printf
jmp .L3
.L9:
mov eax, DWORD PTR [rbp-4]
cmp eax, 8
jne .L10
mov edi, OFFSET FLAT:.LC2
mov eax, 0
call printf
jmp .L3
.L10:
mov eax, DWORD PTR [rbp-4]
cmp eax, 9
jne .L11
mov edi, OFFSET FLAT:.LC4
mov eax, 0
call printf
jmp .L3
.L11:
mov eax, DWORD PTR [rbp-4]
cmp eax, 10
jne .L12
mov edi, OFFSET FLAT:.LC2
mov eax, 0
call printf
jmp .L3
.L12:
mov eax, DWORD PTR [rbp-4]
cmp eax, 11
jne .L13
mov edi, OFFSET FLAT:.LC4
mov eax, 0
call printf
jmp .L3
.L13:
mov eax, DWORD PTR [rbp-4]
cmp eax, 12
jne .L14
mov edi, OFFSET FLAT:.LC2
mov eax, 0
call printf
jmp .L3
.L14:
mov edi, OFFSET FLAT:.LC5
mov eax, 0
call printf
.L3:
mov eax, 0
leave
ret
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.