Ranjit S. Mann Exam 1 CSE-670 Day OF Week
Day OF Week int dayofweek (int year, int month, int day) { int a = (14 - month)/12; int y = year - a; int m = month + 12*a -2; return (day + y + y/4 - y/100 + y/400 + (31*m)/12) % 7; } /* 0 = Sunday, 1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday */ Ranjit S. Mann
DATA PATH SW(1 to 8) 8 demux4g regb dayrega monthregc year aloadbloadcload yearin monthin dayin rege yregf dayfloadeloadregg moutgloadregh monthhload a = (14 - month)/12 m= month+12*a-2 (31*m)/12 mout (day + y/4 - y/100 + y/400 + m) % 7 mux4g m1sel d1msel binbcd x7seg a monthcalc m mout month day year dayOFweek r d y Note: century value is fixed at 2000 m
Controller controller datapath Sw1… Sw8 aload bload cload eload fload gload hload d1msel month day year dayOFweek mux4g binbcd x7seg
State Machine sA sB sC sD sE sF sG s0 s1 s2 s3 1 Wait for BTN4 down month <= SW display month 0 Wait for BTN4 up Wait for BTN4 down day <= SW display day Wait for BTN4 up 1 Wait for BTN4 down year<= SW display year Wait for BTN4 up a = (14 - month)/12 m= month+12*a-2 mout =(31*m)/12 (day + y/4 - y/100 + y/400 + mout) % 7 0/1 display dayOFweek