Digital Clock in assembly language is developed as an educational project to learn assembly language in more detail and have practical experience.
- The clock shows the time of the computer system.
- It shows hours, minutes and seconds.
- It uses 12 hour format.
- It is developed in VGA graphics with 320x200 resolution.
- It is displayed in a classy, stylish and attractive font.
- The interface is simplistic with white text on black background.
How to use
- Download TASM for windows and install.
- Build the program and run it.
How it works
- First we define two macros for later uses. One for drawing rows and another for drawing columns. We send the row, column and color values as parameters for the macros.
- We then set the video mode for our display operation.
- Since we are going to use 1CH in order to continuously refresh the screen, we set the interrupt vector for 1CH.
- The routine which will be executed each time the 1CH interrupt is generated, is defined.
- In the routine, we first generate interrupt to get the current time from the system.
- As the time is returned into the registers, we use those values to convert that time to a string for ease in later tasks.
- We define ten functions each for displaying each digit from 0 to 9.
- Each digit is created using the macros defined earlier. We draw rows and columns for the digits accordingly.
- Before a digit is printed on the screen, we first clear the screen since it will have the previously displayed digit on the screen.
- As the screen keeps getting refreshed continuously, the program waits for a key to be pressed in order to terminate the program.
- As a key is pressed the display is set back to text mode and the program terminates and returns control to DOS.
Interrupts used in the program
This interrupt is used to execute graphics based routines.
AH = 00H; set graphics mode
AL = 13H; graphics mode VGA 320 x 200 256 color
AH = 0CH; draw pixel
AL = color
BH = page
CX = column
DX = row
The bios interrupt 16H routine is the key-board driver. In order to take an input from the keyboard we have used this interrupt where the function value 00H was stored in AH.
AH = 00H; wait for a key press
This is a DOS interrupt. It is used to request different DOS function. The function value is stored in AH. In our program we have used three functions.
AL = interrupt number
AH = 35H; gets interrupt vector stored in AL
INT 21H; returns the address to ES:BX
AL = interrupt number
AH = 25H; sets interrupt vector stored in AL
INT 21H; sets the vector to DS:DX
AH = 2CH; gets the current time, CH = hour, CL = minute, DH = second
AH = 4CH; returns program to DOS
The 1CH interrupt is automatically generated by an internal clock circuit. It is generated about 18.2 times per second on an average. We can define a routine for this interrupt which will be executed every time the interrupt is generated. Since we need to continuously refresh the display, we simply define a routine to refresh the display.