Skip to content

Instantly share code, notes, and snippets.

@SahilC
Created December 19, 2012 10:31
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save SahilC/4335808 to your computer and use it in GitHub Desktop.
Save SahilC/4335808 to your computer and use it in GitHub Desktop.
A simple assembly code for the 8086 microprocessor to display a digital clock in real time.
.model small
.stack 1024
.data
.code
start:
mov ax,@data
mov ds,ax
extrn writesint:proc
mov ah,2ch
int 21h
mov dl,ch
add dl,48
mov ah,2h
int 21h
mov ah,00h
mov al,cl
mov bl,cl
call writesint
mov dl,dh
mov al,dh
call writesint
add bl,10
looper:
mov ah,2ch
int 21h
mov ah,00h
mov al,ch
call writesint
mov ah,00h
mov al,cl
call writesint
mov dl,dh
mov al,dh
call writesint
mov cx,01
mov dx,00
mov ah,86h
int 15h
mov ax,00h
int 10h
cmp cl,bl
jnz looper
mov ah,4ch
int 21h
end start
end
.MODEL SMALL
.DATA
TempStr db 1,2 ; temporary storage for STDIN input
t2 db 80 dup (0)
t3 db 13,10,'$'
Letters db '0123456789' ; possible characters
CrLf db 13,10,'$' ; carriage return and linefeed
.CODE
PUBLIC readsint,writesint
readsint PROC ; reads an integer into the AX register
push bx ; save all registers used
push cx
push dx
push si
mov TempStr,80 ; read in string using buffered STDIN function
mov ah,0Ah
lea dx,TempStr
int 21h
mov cl,TempStr+1 ; get length of string
xor ch,ch
mov bx,0 ; initialize digit index
mov ax,0 ; initialize running total
mov si,10 ; radix = decimal = 10
startmul:
mul si ; move total one place to the left
xor dh,dh
mov dl,[bx+t2] ; get next digit
sub dl,48 ; ascii --> integer value
add ax,dx ; add digit to total
inc bx ; increment digit index
loop startmul
push ax
mov ah,09h ; output carriage return/linefeed
lea dx,CrLf
int 21h
pop ax
pop si ; restore registers
pop dx
pop cx
pop bx
ret ; return to point of call
readsint ENDP
writesint PROC ; outputs the integer in the AX register
push ax ; save all registers used
push bx
push cx
push dx
push si
mov bx,10 ; radix = decimal = 10
xor si,si ; initialize digit counter
startdiv:
xor dx,dx
div bx ; divide no by 10
push dx ; save remainder
inc si ; increment digit counter
cmp ax,0 ; check for end of divisions
jne startdiv
mov cx,si ; set digit counter
mov bx,0 ; initialize position counter
makeletters:
pop ax ; get digit
add al,48 ; make integer --> ascii value
mov [t2+bx],al ; insert digit into string
inc bx ; increment position counter
loop makeletters
mov [t2+bx],'$' ; put end-of-string marker
mov ah,09h ; output integer as string
lea dx,t2
int 21h
mov ah,09h ; output carriage return/linefeed
lea dx,CrLf
int 21h
pop si ; restore registers
pop dx
pop cx
pop bx
pop ax
ret ; return to point of call
writesint ENDP
END
@namineng
Copy link

How to you connect this two code? I was trying to run it and figuring it out but it seems it won't work?

@ivanderos
Copy link

Does it work?

@hassanfattah
Copy link

extrn writesint:proc
emu8086 tell me that erorr

@Yousefaaa
Copy link

for hassanfattah ...... remove the two dots (:) and call extrn ... because the proc name is extrn not writesint or write as ( extrn far proc )

@khizar-solkar
Copy link

can uh explain how the programme can run?

@d167
Copy link

d167 commented Mar 14, 2020

Circuit diagram please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment