Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing Date to Screen 1

Status
Not open for further replies.

tbohon

Programmer
Apr 20, 2000
293
US
I'm trying to retrieve the current (system) date and print it out as a formatted string: mm/dd/yyyy.

Here's what I have:

Code:
push	ax
mov	ax,2c00h
int	21h

mov	al,dh
mov	ah,0eh
int	10h

...

I'm thinking I need to use an offset as I'm getting the graphics characters instead of the ASCII printable numbers ... but it's been a long, long time since I did assembler so thought I'd check before heading down the garden path.

Thanks in advance!

Tom

"My mind is like a steel whatchamacallit ...
 
Um.

It returns numbers in the registers...

Function 2CH (44)
Get time

Obtains the time of day from the system real-time clock driver, converted
to hours, minutes, seconds, and hundredths of seconds.

Call with:

AH = 2CH

Returns:

CH = hours (0 through 23)
CL = minutes (0 through 59)
DH = seconds (0 through 59)
DL = hundredths of seconds (0 through 99)

So you have to convert the data from binary to ascii before you print the string out on the screen.

 
Understand ... it's the binary-to-ascii I'm struggling with. From my cloudy memory I recall it takes an OR to do this ... but I'm not sure.

Tnx.

"My mind is like a steel whatchamacallit ...
 
use the following steps if ax contains the binary number you
want to convert to ascii:

1. divide ax by 10.
2. push the remainder on the stack.
3. increment counter variable.
4. if ax != 0 goto 1.

A. pop current remainder off of the stack.
B. output remainder to screen (=byte).
C. decrement counter variable.
D. if counter variable != 0 goto A.

good luck.
 
I forgot one step, it comes right after step A:

Add 30h to remainder.
Or as you said, OR it with 30h.
 
Int 21h Function 2C returns the time of day...

What you want is:

Int 21H [1.0]
Function 2AH (42)
Get date

Obtains the system day of the month, day of the week, month, and year.

Call with:

AH = 2AH

Returns:

CX = year (1980 through 2099)
DH = month (1 through 12)
DL = day (1 through 31)

Under MS-DOS versions 1.1 and later

AL = day of the week (0 = Sunday, 1 = Monday, etc.)

Notes:

þ This function's register format is the same as that required for Int 21H
Function 2BH (Set Date).

þ This function can be used together with Int 21H Function 2BH to find
the day of the week for an arbitrary date. The current date is first
obtained with Function 2AH and saved. The date of interest is then set
with Function 2BH, and the day of the week for that date is obtained
with a subsequent call to Function 2AH. Finally, the current date is
restored with an additional call to Function 2BH, using the values
obtained with the original Function 2AH call.

Example:

Obtain the current date and save its components in the variables year,
day, and month.

year dw 0
month db 0
day db 0
.
.
.
mov ah,2ah ; function number
int 21h ; transfer to MS-DOS
mov year,cx ; save year (word)
mov month,dh ; save month (byte)
mov day,dl ; save day (byte)
.
.
.
 
Zeitghost:

Great explanation - it's all coming back (slowly, I'm older now :))

Thanks!

Tom

"My mind is like a steel whatchamacallit ...
 
And this does more or less what you asked, except that I've used int 21h function 2 for screen output.

It assembles & links under TASM ver 2.0

DOSSEG
.MODEL SMALL
.STACK 100h
.DATA
HelloMessage DB 'Hello, world',13,10,'$'
.CODE

time proc near
mov ax,2c00h ;get time from dos
int 21h


;CH HOURS
;CL MINS
;DH SECS
;DL CENTISECS

PUSH dX
PUSH cX

mov ah,0
mov al,ch ;dividend
mov cl,10 ;divisor
div cl ;quotient in al, remainder in ah

push ax ;save quotient & remainder

or al,30h ;tens of hours to ascii


mov dl,al
mov ah,02h
int 21h

pop ax ;restore quotient & remainder
or ah,30h ;units of hours to ascii numeric

mov dl,ah
mov ah,02h
int 21h

call do_colon

pop cx ;restore minutes

mov ah,0
mov al,cl
mov cl,10
div cl

push ax ;save quotient & remainder

or al,30h ;tens of minutes to ascii

mov dl,al
mov ah,02h
int 21h

pop ax ;restore quotient & remainder

or ah,30h ;units of minutes to ascii

mov dl,ah
mov ah,02h
int 21h

call do_colon

pop dx ;restore secs & cent-secs
push dx ;& save it again

mov ah,0
mov al,dh ;secs
mov cl,10
div cl

push ax ;save tens & units of secs

or al,30h ;tens of secs to ascii

mov dl,al
mov ah,02h
int 21h

pop ax

or ah,30h ;units of secs to ascii
mov dl,ah
mov ah,02h
int 21h

call do_colon

pop dx ;restore secs & centi-secs

mov ah,0
mov al,dl ;centi-secs
mov cl,10
div cl

push ax ;save tens & units of centisecs

or al,30h ;tens of centi-secs to ascii

mov dl,al
mov ah,02h
int 21h

pop ax

or ah,30h ;units of centi-secs to ascii
mov dl,ah
mov ah,02h
int 21h

call do_space

mov ax,2a00h ;get date from dos
int 21h


;Cx year (1980 - 2099)
;DH month
;DL day
;al day of week 0 == sun

push cx ;save year
push dx ;save month & day


mov ah,0
mov al,dl ;day
mov cl,10
div cl

push ax ;save tens (al) & units (ah) of day

or al,30h ;tens of day to ascii

mov dl,al
mov ah,02h
int 21h

pop ax

or ah,30h ;units of day to ascii
mov dl,ah
mov ah,02h
int 21h

call do_slash

pop dx ;restore month (dh)

mov ah,0
mov al,dh ;month
mov cl,10
div cl

push ax ;save tens (al) & units (ah) of month

or al,30h ;tens of month to ascii

mov dl,al
mov ah,02h
int 21h

pop ax

or ah,30h ;units of month to ascii
mov dl,ah
mov ah,02h
int 21h

call do_slash

pop ax ;year
mov dx,0 ;clr ms byte of dividend
mov cx,1000 ;and divide by 1000 to get thousands
div cx ;quotient in ax, remainder in dx

push dx ;save remainder

or al,30h ;into ascii
mov ah,02h
mov dl,al
int 21h

pop ax ;restore remainder

mov dx,0 ;clr msb
mov cx,100 ;get hundreds
div cx ;quotient in ax, remainder in dx

push dx ;save remainder

or al,30h ;into ascii
mov ah,02h
mov dl,al
int 21h

pop ax ;restore remainder

mov dx,0 ;clr msb
mov cx,10 ;get tens
div cx ;quotient in ax, remainder in dx

push dx ;save remainder

or al,30h ;into ascii
mov ah,02h
mov dl,al
int 21h

pop ax ;restore remainder (units)

or al,30h ;into ascii
mov ah,02h
mov dl,al
int 21h

mov ax,@data
mov ds,ax ;set DS to point to the data segment
mov ah,9 ;DOS print string function
mov dx,OFFSET HelloMessage ;point to "Hello, world"
int 21h ;display "Hello, world"


mov aX,4c00h ;DOS terminate program function
int 21h ;terminate the program
endp

do_space proc near
push ax
push dx
mov ah,02
mov dl,' '
int 21h
pop dx
pop ax
ret
endp

do_colon proc near
push ax
push dx
mov ah,02
mov dl,':'
int 21h
pop dx
pop ax
ret
endp

do_slash proc near
push ax
push dx
mov ah,02
mov dl,'/'
int 21h
pop dx
pop ax
ret
endp




END


 
That bit about Int21h function 2Ah is from a file I found on the web.

It's from Ray Duncan's Advanced Dos Programming book as scanned in by someone or other.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top