Hello,

Could someone please look at this code and tell me why it is not working. I am trying to retrieve the number that is stored in the "Hundredths" section of the system time and output it to the screen.

Thanks.

.MODEL  SMALL                           
.286
.STACK  100h                            
.DATA                                 


   Typed     DB  LF,LF,CR,' My answer is "$'
   CharTyped DB ?


.CODE                                
Main:
        call Clock
        mov CharTyped,dl              
        call PutChar
        mov ax,@data
        mov ds,ax
        lea dx,Typed
        call PrintString
        call PutChar


TerminateProg:

        mov  ax,4c00h                 
        int  21h                      


;********************* Near procedure to print a char 
;*****************************************************

PutChar PROC                         
        mov ah,02h                     
        int 21h                       
        ret                           
PutChar ENDP                           

;******************* Near procedure to print a string 
;*****************************************************

PrintString PROC                        ;Define procedure
        mov  ah,9h                      ;DOS print string function #9
        int  21h                        ;display the string
        ret                             ;Return to calling procedure
PrintString ENDP                        ;End of procedure

;********************* Procedure to Read System Clock 
;*****************************************************

Clock PROC
        mov ah,2ch                    
        int 21h                  
        ret                           
Clock ENDP


END Main

Recommended Answers

All 3 Replies

You may want to start with the fact that you are trying to display a binary value in dl. You will need to convert it to ASCII before printing it.
Be advised that the value will probably be in 1/18th of a second increments for standard system clocks.

Here's a quick way to print out the value of DL.

mov al, dl ; value must be in range of 0-99
aam    
add ah, 30h
add al, 30h
push ax
mov dl, ah
mov ah, 2
int 21h
pop ax
mov dl, al
mov ah, 2
int 21h

Here is a routine for printing decimal values in ASCII.
Value is pushed onto stack, routine handles adjusting
stack for parameters.
Value is limited to 65,535

mov ax, 666
push ax
call printdec
mov ax, 123
push ax
call printdec
ret

printdec_val dw 10000 ; divisor
printdec:
push bp
mov bp, sp
push word [printdec_val]
mov ax, [bp+4]

printdec_l:
push ax
xor dx, dx
div word [printdec_val] ; Number / PlaceValue
; Digit in AL

push ax
add al, 30h  ; Turn into ASCI digit
mov dl, al
mov ah, 2
int 21h   ; print character

cmp word [printdec_val], 1 ; check if at end
jz printdec_e

pop ax
xor ah, ah
mul word [printdec_val] ; digit * PlaceValue
pop bx
sub bx, ax ; subtract from number

push bx
mov bx, 10
mov ax, [printdec_val]
div bx  ; PlaceValue / 10 = new divisor
mov [printdec_val], ax

pop ax
jmp printdec_l
printdec_e:
pop ax
pop ax
pop word [printdec_val]
pop bp
ret 2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.