Saturday 15 March 2014

Clock to display current time Assembly Language Complete Source Code

Here I have posted the complete code for a Clock which displays the current system time .
The clock is implemented using assembly language .
Below is a screen shot taken for the current time .


The clock displays the Current time in 24 hours format.
Its displays


  • Hours
  • Minutes
  • Seconds

Complete code for this Clock in assembly x86 is shown below. Copy and paste the code below and run it on DOSBOX or NASM .


---------------------  Code Starts from Here ------------------------------


[org 0x100]
jmp start
;///////////
oldtm: dd 0
oldkb: dd 0
nointcount: dw 0
srnsv: dw 0
reserv: times 4000*1 db 0 
;////////////////////////////////////





;  Copyright ::  Farhan Maqsood
;   Phone         (+923084245492)
;   Email           farhangdon009@gmail.com
;  This is for learning Purpose
;  All code given is tested on DOSBOX




tmIsr:
push ax
cmp word[cs:nointcount],182
jb incr
call screenSaver
jmp ex 
incr:
add word[cs:nointcount],1
ex:
mov al,0x20
out 0x20,al
pop ax
jmp far [cs:oldtm]
;////////////////////////////////////
kbIsr:
push ax
mov word[cs:nointcount],0
cmp word[cs:srnsv],1
jne doNothing
call clear
call storScreen
mov word[cs:srnsv],0
doNothing:
mov al,0x20
out 0x20,al
pop ax
jmp far [cs:oldkb]
;///////////////////////////////////////////////
storScreen:
push ax
push bx
mov ax,0xb800
mov es,ax
xor bx,bx
again:
mov ax,[cs:reserv+bx]
mov [es:bx],ax
add bx,2
cmp bx,4000
jb again
pop bx
pop ax
ret
;///////////////////////////
screenSaver:
push ax
push cx
push dx
push bx
cmp word[cs:srnsv],1
je noAd
call Sav
mov word[cs:srnsv],1
noAd:
;call clear
call lite
call PrintTime
pop bx
pop dx
pop cx
pop ax
ret
;//////////////////
lite:
push ax
push bx
push es
push 0xb800
pop es
mov ah,0x0f
xor bx,bx
mov al,' '
tre: mov [es:bx],ax
add bx,2
cmp bx,4000
jb tre
pop es
pop bx
pop ax
ret
;/////////////////
PrintTime:
push ax
push bx
push cx
push dx
push es
mov ah,02
int 0x1a
push 0xb800
pop es
mov bx,1990
mov ah,0x0f
mov al,ch
shr al,4
add al,0x30
mov [es:bx],ax
add bx,2
mov al,ch
and al,0x0f
add al,0x30
mov [es:bx],ax
add bx,2
mov byte[es:bx],':'
add bx,2
mov al,cl
shr al,4
add al,0x30
mov [es:bx],ax
add bx,2
mov al,cl
and al,0x0f
add al,0x30
mov [es:bx],ax
add bx,2
mov byte[es:bx],':'
add bx,2
mov al,dh
shr al,4
add al,0x30
mov [es:bx],ax
add bx,2
mov al,dh
and al,0x0f
add al,0x30
mov [es:bx],ax
pop es
pop dx
pop cx
pop bx
pop ax
ret
;////////////////////////
Sav: push ax
push bx
push es
mov  ax,0xb800
mov es,ax
xor bx,bx
nextItr:mov ax,[es:bx]
mov [cs:reserv+bx],ax
add bx,2
cmp bx,4000
jb nextItr
pop es
pop bx
pop ax
ret
;////////////////
clear:
push es
push bx
mov ax,0xb800
mov es,ax
xor bx,bx
spac: mov word[es:bx],0x0720
add bx,2
cmp bx,4000
jb spac
pop bx
pop es
ret
;//////////////////////////////
start:
xor ax,ax
mov es,ax
mov ax,[es:9*4]
mov [oldkb],ax
mov ax,[es:9*4+2]
mov [oldkb+2],ax
mov ax,[es:8*4]
mov [oldtm],ax
mov ax,[es:8*4+2]
mov [oldtm+2],ax
cli
mov word[es:8*4],tmIsr
mov [es:8*4+2],cs
mov word[es:9*4],kbIsr
mov [es:9*4+2],cs
sti
mov dx,start
mov cl,4
add dx,15
shr dx,cl
mov ax,0x3100
int 0x21



------------------------------  Code Ends Here ---------------------------------------


You can compile the program using NASM and can test on DOSBOX. If you have any question regarding this question the comment here or let me know via email . Thanks





No comments:

Post a Comment