8086 assembly language program to display current date edit button Edit

Murugan Andezuthu Dharmaratnam | calendar 08 September 2020 | 6441

A couple of months back someone had sent me a message on Facebook to help him write an assembly language program to display the current date. He was a beginner in 8086 and wanted the code at the earliest. I spend some time and quickly wrote this sample code. It could have been written in a much better way or even in a much simpler way, But this is the code I came up with at that time.

first, let me show you the code, and then I will give a detailed explanation.

8086 code to display the date

.model tiny
org 100h
main proc near
    mov ah,2ah
    int 21h   
    push dx
    mov ax,cx
    mov si,offset year
    call hexToAsc
    pop dx
    push dx      
    mov ah,00
    mov al,dh
    mov si,offset month
    call hexToAsc
    pop dx
    push dx      
    mov ah,00
    mov al,dl
    mov si,offset day
    call hexToAsc
    pop dx
    mov ah,09h
    mov dx,offset messagecurrentdate
    int 21h
    mov ah,4ch
    mov al,00
    int 21h
    messagecurrentdate db 0ah,0dh,"Current Date : "
    day db '  ' 
    separator1 db '/'
    month db '  '
    separator2 db '/'
    year db "    $"     

hexToAsc proc near        ;AX input , si point result storage addres
        mov cx,00h
        mov bx,0ah
                mov dx,0
                div bx
                add dl,'0'
                push dx
                inc cx
                cmp ax,0ah
                jge hexloop1
                add al,'0'
                mov [si],al
                pop ax
                inc si
                mov [si],al
                loop hexloop2

end main


I am using emu8086 to run the code

Code explained in detail

Since this is 4beginner and since I know it's going to be students who are going to search for this code. I will break down the code into pieces and explain it step by step.