Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

hi i need help in this program its in LC-3 the input is a date mm/dd/yyyy from address x31F0 ,x31F1,x31F2 and output is the day

hi i need help in this program its in LC-3 the input is a date mm/dd/yyyy from address x31F0 ,x31F1,x31F2 and output is the day of the week on that date using zeller's formula it should print it to screen and save it in address x31F3

.ORIG x3000 LDI R3, MONTH ; m LDI R4, DAY ; q (Day) LDI R5, YEAR ; ;COMPUTE M AND R1,R1,#0 AND R2,R2,#0 AND R6,R6,#0 ADD R1,R3,#0 ADD R1,R1,#-2 BRp MONTHIS2 ADD R1,R1,#12 MONTHIS2 ADD R1,R1,#0 STI R1,M ;COMPUTE D AND R1,R1,#0 AND R2,R2,#0 AND R6,R6,#0 ADD R1,R5,#0 LD R2,N_100 JSR MOD LDI R6,X_MOD_Y STI R6,D ;compute c AND R1,R1,#0 AND R2,R2,#0 AND R6,R6,#0 ADD R1,R5,#0 LD R2,N_100 JSR DIV LDI R6,X_DIV_Y STI R6,C ;COMPUTE THE FORMULA AND R1,R1,#0 AND R2,R2,#0 AND R6,R6,#0 ; (13M-1) LDI R1,M ADD R2,R2,#13 JSR MULT LDI R6,X_MUL_Y ADD R6,R6,#-1 AND R1,R1,#0 AND R2,R2,#0 ;(13M-1)/5 ADD R1,R6,#0 ADD R2,R2,#5 AND R6,R6,#0 JSR DIV LDI R6,X_DIV_Y ADD R6,R6,R4 ;K+(13M-1)/5 AND R1,R1,#0 AND R2,R2,#0 LDI R1,D ADD R6,R6,R1 ;K+(13M-1)/5+D AND R1,R1,#0 LDI R1,D ADD R2,R2,#4 ;D/4 JSR DIV AND R1,R1,#0 LDI R1,X_DIV_Y ADD R6,R6,R1 ;K+(13M-1)/5+D +D/4 AND R1,R1,#0 AND R2,R2,#0 LDI R1,C ADD R2,R1,R1 ;2C NOT R2,R2 ADD R2,R2,#1 ADD R2,R2,#4 ;4-2C JSR DIV AND R1,R1,#0 LDI R1,X_DIV_Y ADD R6,R6,R1 ;K+(13M-1)/5+D +D/4+C/4-2C AND R1,R1,#0 AND R2,R2,#0 ADD R1, R6, #0 ADD R2, R2, #7 JSR MOD ; F mod 7 AND R0,R0,#0 AND R6,R6,#0 LDI R6, X_MOD_Y STI R6,DAY_OF_THE_WEEK LEA R0, DAYS ADD R0,R6,#0 PUTS HALT DAYS .STRINGZ " Sunday " .STRINGZ " Monday " .STRINGZ " Tuesday " .STRINGZ " Wendsday" .STRINGZ " Thursday" .STRINGZ " Friday " .STRINGZ " Saturday"

DAY_OF_THE_WEEK .FILL x31F3

MONTH .FILL x31F0 DAY .FILL x31F1 YEAR .FILL x31F2 M .FILL x3100 D .FILL x3101 C .FILL x3102 X_MUL_Y .FILL x3103 X_DIV_Y .FILL x3104 X_MOD_Y .FILL x3105 N_100 .FILL #100

MULT STI R1, SAVE_R1 ; Save registers STI R2, SAVE_R2 ; STI R3, SAVE_R3 ; STI R4, SAVE_R4 ; ;STI R7, SAVE_R7 AND R4, R4, #0 ; Test the sign of X ADD R1, R1, #0 BRn X_NEG ; If X is negative, change X to positive BR #3 X_NEG NOT R1, R1 ADD R1, R1, #1 NOT R4, R4 ADD R2, R2, #0 BRn Y_NEG ; If Y is negative, change Y to positive BR #3 ; Change Y to positive Y_NEG NOT R2, R2 ADD R2, R2, #1 NOT R4, R4 AND R3, R3, #0 MULT_REPEAT ADD R3, R3, R1 ; Perform addition on X ADD R2, R2, #-1 ; Use R2 as the counter BRnp MULT_REPEAT ; Continue loop while counter not equal to 0 ADD R4, R4, #0 ; Test the sign flag BRn CHANGE_SIGN ; Change the result if sign flag is negative BR #2 CHANGE_SIGN ; Change the sign of the result NOT R3, R3 ADD R3, R3, #1 STI R3, X_MUL_Y ; Save the result LDI R1, SAVE_R1 ; Restore registers LDI R2, SAVE_R2 ; LDI R3, SAVE_R3 ; LDI R4, SAVE_R4 ; RET DIV STI R1, SAVE_R1 ; Save registers STI R2, SAVE_R2 ; STI R3, SAVE_R3 ; STI R4, SAVE_R4 ; STI R5, SAVE_R5 ; AND R3, R3, #0 ; Initialize the whole part counter AND R5, R5, #0 ; Initialize the sign flag ADD R1, R1, #0 BRn X_NEG_2 ; If X is negative, change X to positive BR #3 X_NEG_2 NOT R1, R1 ADD R1, R1, #1 NOT R5, R5 ADD R2, R2, #0 BRn Y_NEG_2 BR #3 Y_NEG_2 NOT R2, R2 ADD R2, R2, #1 NOT R5, R5 NOT R4, R2 ; Initialize the decrement counter ADD R4, R4, #1 ; DIV_REPEAT ADD R1, R1, R4 ; Subtract Y from X BRn #2 ADD R3, R3, #1 ; Increment the whole number counter BR DIV_REPEAT ; Continue loop while X is still greater than Y ADD R5, R5, #0 ; Test the sign flag BRn CHANGE_SIGN_2 ; Change the result if sign flag is negative BR #2 CHANGE_SIGN_2 ; Change the sign of the result NOT R3, R3 ADD R3, R3, #1 STI R3, X_DIV_Y ; Save the result LDI R1, SAVE_R1 ; Restore registers LDI R2, SAVE_R2 ; LDI R3, SAVE_R3 ; LDI R4, SAVE_R4 ; LDI R5, SAVE_R5 RET

MOD STI R1, SAVE_R1 ; Save registors STI R2, SAVE_R2 ; STI R3, SAVE_R3 ; STI R4, SAVE_R4 ; STI R5, SAVE_R5 ; ;STI R7, SAVE_R7

AND R5, R5, #0 ADD R1, R1, #0 BRn X_NEG_3 ; If X is negative, change X to positive BR #3 X_NEG_3 NOT R1, R1 ADD R1, R1, #1 NOT R5, R5 ADD R2, R2, #0 BRn Y_NEG_3 BR #3 Y_NEG_3 ; If Y is negative, change Y to positive NOT R2, R2 ADD R2, R2, #1 NOT R5, R5 NOT R3, R2 ; Initialize the decrement counter ADD R3, R3, #1 ; ADD R4, R1, #0 ; Initialize the modulo counter MOD_REPEAT ADD R1, R1, R3 ; BRnz #2 ; If R3 cannot go into R1 exit loop ADD R4, R4, R3 ; else continue to calculate modulo BR MOD_REPEAT STI R4, X_MOD_Y LDI R1, SAVE_R1 ; Restore registers LDI R2, SAVE_R2 ; LDI R3, SAVE_R3 ; LDI R4, SAVE_R4 ; LDI R5, SAVE_R5 ; ;LDI R7, SAVE_R7 ; RET

; Used to save and restore registers SAVE_R1 .FILL x3500 SAVE_R2 .FILL x3501 SAVE_R3 .FILL x3502 SAVE_R4 .FILL x3503 SAVE_R5 .FILL x3504 SAVE_R6 .FILL x3505 SAVE_R7 .FILL x3506

.END

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

Select Healthcare Classification Systems And Databases

Authors: Katherine S. Rowell, Ann Cutrell

1st Edition

0615909760, 978-0615909769

More Books

Students also viewed these Databases questions

Question

1. Who is responsible for resolving this dilemma?

Answered: 1 week ago