×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Printing Date to Screen

Printing Date to Screen

Printing Date to Screen

(OP)
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 ..."

RE: Printing Date to Screen

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.

RE: Printing Date to Screen

(OP)
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 ..."

RE: Printing Date to Screen

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.

RE: Printing Date to Screen

I forgot one step, it comes right after step A:

  Add 30h to remainder.
  Or as you said, OR it with 30h.

RE: Printing Date to Screen

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)
          .
          .
          .

RE: Printing Date to Screen

(OP)
Zeitghost:

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

Thanks!

Tom

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

RE: Printing Date to Screen

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


RE: Printing Date to Screen

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close