Search code examples
dateassemblyx86masm

Assembly printing system date


I have a problem with printing system date because of cx register size. How can it be solved without any big changes?

title casadatum

zas     segment stack
        db      256 dup(?) 
zas ends

strsize EQU 64

dat segment
   print db 'Current System Date is : $'
   date db  'dd:mm:rrrr$'
   nl db 10,13,'$' 
dat ends

code segment
                assume cs:code, ss:zas, ds:dat

get_date proc
          mov ah,2ah
          int 21h
          mov al,dl
          call convert
          mov [bx],ax
          mov al,dh
          call convert
          mov [bx+3],ax
          mov al,cx
          call convert
          mov [bx+6],ax     

        ret
        endp          


convert proc
        push dx
        mov ah,0
        mov dl,10
        div dl
        or ax, 3030h
        pop dx
        ret 
        endp    


start:

        mov ax, seg dat
        mov ds,ax

        LEA BX, date
        CALL GET_date

        lea dx,print
        mov ah,09h
        int 21h

        lea dx,date
        mov ah,09h
        int 21h

koniec:
        mov ah, 4ch
        int 21h

code ends
        end start

Solution

  • Replace this part of your code

    mov al,cx
    call convert
    mov [bx+6],ax
    

    with these instructions

    mov al,100
    xchg ax,cx
    div cl
    mov ch,ah
    call convert
    mov [bx+6],ax
    mov al,ch
    call convert
    mov [bx+8],ax