Getting String Array Value to Display On Screen

Started by shagywashere, October 27, 2011, 08:33:48 PM

Previous topic - Next topic

shagywashere

Program where you enter month, day and year and it will tell you which day that was (Sunday-Saturday)

Has a range of Jan 1, 1901 (Tuesday, which is why it's first in the array) and Dec 3, 2099. Currenty I can enter in a date, and it will display partially what day it is (ranging from "esday" to "day" to "ay")

I cannot for the life of me figure out how to display this.

;===================================================================
         EXTERN  GETDEC$:FAR
         EXTERN  NEWLINE:FAR
         EXTERN  PUTSTRNG:FAR
         EXTERN  PUTDEC$:FAR
         EXTERN  PUTSTRNG:FAR
;===================================================================
INCLUDE PCMAC.INC
.MODEL  SMALL
.586
        .STACK  512
        .DATA
GETMONTH    DB 'Enter the month number '
GETDAY DB 'Enter the day     '
GETYEAR DB 'Enter the year      '
ERRORMESSAGE DB 'Invalid! Please re-enter      '
DAYSINMONTHS DW 31,28,31,30,31,30,31,31,30,31,30,31
DAYSINLEAPMONTHS DW 31,29,31,30,31,30,31,31,30,31,30,31
MONTHSOFFSET DB 0,3,3,6,1,4,6,2,5,0,3,5
LEAPMONTHSOFFSET DB 0,3,4,0,2,5,0,3,6,1,4,6
MONTH DW ?
DAY DW ?
YEAR DW ?
TEMP DW ?
JAN1901 DW 2
DIFYEARS DW 0
LEAPYEARS DW 0
TOTYEARS DW 0
TOTMOD DW 0
DAYS DW 0
X DB 0
MONTHS  DB 'January$February$March$April$May$June$July$August$September$October$November$December'
DAYSOFWEEK DB 'Tuesday$Wednesday$Thursday$Friday$Saturday$Sunday$Monday$'
SPACES DB '       '
WAS DB 'was a '       
;---------------------------------
...........
...........
........... (left out input and validation, assume YEAR is populated with a random year)

MOV AX,   YEAR
SUB AX, 1901
MOV DIFYEARS, AX
SUB DX, DX
MOV BX, 4
DIV BX
MOV LEAPYEARS, AX
ADD AX, DIFYEARS
MOV TOTYEARS, AX
SUB DX, DX
MOV BX, 7
DIV BX
MOV TOTMOD, DX
MOV AX, TOTMOD
SHL AX, 1
SHL AX, 1
ADD AX, OFFSET DAYSOFWEEK
CALL NEWLINE
_putstr ax
_PUTCH 13, 10

.EXIT
                MOV     AX, 4C00H
                INT     21H

ERROR:
LEA DI, ERRORMESSAGE
                MOV     CX, SIZEOF ERRORMESSAGE
CALL NEWLINE
                CALL    PUTSTRNG
MOV CX, 0
CALL NEWLINE
RET

ARREX   ENDP
        END     ARREX

shagywashere

when I put the year 1901, in the day "Tuesday" displays however (my algorithm is obviously incomplete)

FORTRANS

Hi,

   Perhaps store DX to LEAPYEARS not AX?

HTH,

Steve

shagywashere

I don't need the remainder for leap years, I need the quotient (40/4 = 10 leap years, 0 remainder).

dedndave

don't forget.....

every 100 years, we skip a leap year (i.e. years divisable by 100)
however, if that 100th year is also divisable by 400, we do not skip the leap year
unless it is also divisable by 1000 - we do skip it - lol
the year 2000 was one of these special years   :bg

this may not be important for "modern" or near-future dates
but if you want to derive the day of the week in the years 1599 or 1601, it makes a difference
none of us are likely to survive into the year 2400, but you may want a program that can handle it
for example, if you were making a Terminator model T-1000, you'd want to get it right
imagine how screwed up Arnold would be if you sent him back to 1592 because Chris Columbus
was John Connor's great great great granddaddy - he could miss the boat entirely
and - before the year 1582, we didn't use the Gregorian Calendar   :P
it's very hard to figure the day of the week before that   :bg
you'd have to learn Latin and....
"Render unto Ceasar that which is Ceaser's"
before that, they didn't even get the moons per year right
Ceaser added the months July (after Julius) and August (after Augustus)
that explains why September (sept- 7), October (octo- 8), November (novem- 9), and December (dec- 10) are all off by 2

shagywashere

Yeah, we talked about that in class, but thankfully are dates are Jan 1, 1901 to Dec 3, 2099

dedndave

that makes it easy, then
you have a nice instructor   :P