Blogger news

Followers

Friday, February 21, 2014


ASSUME DS:DATA,CS:CODE     

DATA SEGMENT                           ; data segment starts
MSG DB 0AH, 0DH,'SYSTEM TIME IS : ','$'
DATA ENDS
                 
DISP MACRO NUM                                  ; DISP macro definition starts here, to display the time on the monitor
PUSH AX                                           ; push the AX content to stack
MOV DL, NUM
MOV AH, 02H                                   ; using 02H service no. with DOS 21H interrupt
INT 21H
POP AX                                              ; pop the AX content
ENDM                                                ; end of macro definition

HEXTOBCD MACRO                    ; HEXTOBCD macro definition starts here, to covert hex value
AAM                                                   ; to BCD ( ie: to convert hr and minute value in hex to BCD)
ADD AX, 3030H                               ; using AAM instruction and then add 3030H to AX to get the ASCII value.
ENDM                                                ; end of macro definition.

CODE SEGMENT                           ; code segment starts
START: MOV AX, DATA                 ; data segment initialization
       MOV DS, AX
       MOV DX, OFFSET MSG              ; get the offset address of string stored in array MSG                          
       MOV AH, 09H               
       INT 21H                                      ; display MSG on the screen using 09H with DOS 21H interrupt
       MOV AH, 2CH                           ; read the system time using 2CH service number with
       INT 21H                                      ; 21H DOS interrupt.
       PUSH CX                                    ; push the system time information stored in CX to stack
       CMP CH, 0CH                            ; compare the hour information stored in CH with 0CH (12hr)
       JB HRDISP                                    ; if the current hour is < 12, then jump to label NEXT and display.
       SUB CH, 0CH                             ; otherwise subtract 12 from the current hr stored in CH
HRDISP: MOV AL, CH                      ;  copy the hr information in CH (Hex value)  to AL.
                                                            ; in order to use AAM instruction. 
      HEXTOBCD                                ; invoke HEXTOBCD macro to convert hr (Hex) to unpacked
; BCD format.
      DISP AH                                      ; invoke DISP macro to display the upper digit of hr information on the screen
      DISP AL                                       ; invoke DISP macro to display the lower digit of hr information on the screen
      DISP ':'                                         ; colon (:) is printed on the screen
      MOV AL, CL                               ; copy the minute information (Hex) in CL to AL to use AAM
      HEXTOBCD                                ; invoke HEXTOBCD macro to convert minute (Hex) to
; unpacked BCD format.
     DISP AH                                       ; invoke DISP macro to display the upper digit of minute information on the screen
      DISP AL                                       ; invoke DISP macro to display the lower digit of minute information on the screen        
       DISP '-'                                          ; hyphen (-) is printed on the screen
      POP CX                                        ; pop the system time information stored in stack to CX
      CMP CH, 0CH                             ; compare again the hr information in CH with 12
      JAE AGAIN                                    ; if hr is > = to 12 then jump to label AGAIN.  
      DISP 'A'                                        ; otherwise display the current time as AM, by invoking DISP macro
      DISP 'M'                                       ; display the character A , M on the screen.
      JMP EXIT                                      ; jump to label EXIT and terminate
AGAIN: CMP CH, 0CH                      ; again compare the hr value with 12 and see whether it is equal to 12 or not
      JA NEXT                                       ; if it is > 12 then go to NEXT and display the time as PM
      CMP CL, 00                                 ; otherwise if hr =12 then again compare minute in CL with 00
      JNE NEXT                                     ; if minute in CL is not equal to 00, then display the time as PM
      DISP 'N'                                        ; otherwise minute in CL=00 then display the time as NOON (12:00)
      DISP 'O'                                        ; by invoking the DISP macro, display the character N, O, O, N on the         
      DISP 'O'                                        ; screen
      DISP 'N'
      JMP EXIT                                      ; jump to label EXIT to terminate
NEXT: DISP 'P'
      DISP 'M'                                       ; invoke the DISP macro to display the characters P, M on the screen.
EXIT:  MOV AH, 4CH                    ; terminate the program
      INT 21H
CODE ENDS                                     ; end of code segment
      END START                                  ; end of program
      


Output:
D:\MASM> Masm 9a.asm;
D:\MASM> Link 9a.obj;

0 comments: