;==========================================
; A Little Assembly app that shows the current date and time.
; It can be done a lot easier, but this way
Memory manipulation, and how to use ' variables '.
;==========================================
. Model Small
. stack
;===========================
;D ATA Segment Starts here
;===========================
. Data
Date_strdb "Current date Is:yyyy-mm-dd", 0Ah, 0Dh, "$"
Time_strdb "Current Time Is:hh.mm.ss:xx", 0Ah, 0Dh, "$"
Min_sizedw?
Padd_chrdb?
;===========================
; Code segment Starts here
;===========================
. Code
Mainproc
Movax, SEG @data; The segment Address
MOVDS, Ax and store it into DS
Mov[min_size], 02h; Results should always is at least two digits
MOV[PADD_CHR], ' 0 '; Use ' 0 ' as Padding-character
Movah, 2Ah; Then we call int 21h,2ah, which'll give
int21h us the current date
Leadi, Date_str; Then we load the address of the DATE_STR string
Adddi and set Si to point at the ' the ' in the ' the ' in the '-yyyy-...
Movax, CX; Next we mov cx to ax and
Calltodec Call Todec
INCDI; We skip the '-' character ...
Xorax, Ax; Then We empty ax
Moval, DH; and set the low-byte of Ax to DH
Calltodec
INCDI; Skip character in string ...
Xorax, Ax; Empty Ax
Moval, DL; Set Low-byte to DL
Calltodec; Convert it to Base10
Leadi, Time_str; Now we load the TIME_STR string
Adddi, 17; and set the correct pointer offset
Movah, 2Ch; And then we call int 21h,2ch
int21h which would give us the current time
Xorax, Ax; Empty Ax
Moval, ch; Set Low-byte to Ch
Calltodec; Convert it to Base10
INCDI; Skip character
Moval, CL; Set Low-byte to CL
Calltodec; Convert to Base10
INCDI; Skip character
Moval, DH; Set Low-byte to DH
Calltodec; Convert to Base10
INCDI; Skip character
Moval, DL; Set Low-byte to DL
Calltodec; Convert to Base10
MOVDX, offset date_str; Now load offset of the DATE_STR string into DX
Callprint; and print the (modified) string
MOVDX, offset time_str; Load offset of the time_str string into DX
Callprint; and print the (modified) string
Movax, 4c00h;D o a clean exit (Error code=00)
int21h
;===================================================================
; todec-converts the contents of AX into Base10 ASCII character (s)
; of length BX
; Min_size defines minimum length of result, and Padd_char
; Defines the padding character.
; The result (s) are stored at Ds:di
;===================================================================
Todecproc
Pushax; Save All Registers
Pushbx
Pushcx
Pushdx
XORCX,CX; Empty the POP counter
movbx,10; Base Divisor
Decloop:
XORDX,DX; Set the high 16-bits to 0
DIVBX; Preform Division (Dx=remainder, Ax=quotient)
INCCX increase the counter.
PUSHDX and save the remainder
cmpax,0 If the quotient!= 0
Jnzdecloop then get one more
MOVBX, [min_size]; Load min_size value into BX
MOVDL, [PADD_CHR]; Load PADD_CHR value into DL
Padd_result:
CMPCX, BX; is CX >= min_size?
Jgepoploop If So, proceed
Movbyte ptr ds:[di], DL; Else Padd with PADD_CHR
INCDI and increase string pointer
DECBX;d ecrease BX
Jmppadd_result and test for the more padding
Poploop:
POPDX; Get the number of the stack
ADDDL, ' 0 '; and add ' 0 ' to it
Movbyte ptr ds:[di], DL; Modify the string at Ds:di
INCDI increase the string pointer
DECCX;D Ecrease the loop counter
Jnzpoploop
POPDX; Restore All Registers
Popcx
Popbx
Popax
RET; and return to call
Todecendp
;===========================================================
;p Rint-prints The string pointed to by DX using int 21h,09
;===========================================================
Printproc
Pushax; Save Ax
Pushds and DS onto the stack
Movax, @data; Then get the "address of the" data segment
MOVDS, Ax and store it into DS
Movax, 0900h
INT21H and then print the message pointed to by DX
Popds; Retrieve DS
Popax and Ax from stack
Ret
Printendp
Mainendp
Endmain