TITLE PGM12: SCORE 
        EXTRN SCORE : BYTE
        PUBLIC SCORING

.MODEL SMALL

IF1
        INCLUDE macro.ASM
ENDIF

.CODE

SCORING PROC
;this procedure displays a score according to the byte variable SCORE
;converting ASCII to decimal digits

        SAVE_REGS <AX, BX, CX, DX>
        MOV AH, 02     ;set cursor
        MOV BH, 0      ;page 0
        MOV DH, 1      ;row 1
        MOV DL, 66     ;column 66
        INT 10h
        MOV AH, 0Eh    ;write character function
        MOV BL, 1111b  ;white color
;type 'SCORE: '
        MOV AL, 'S'
        INT 10h
        MOV AL, 'C'
        INT 10h
        MOV AL, 'O'
        INT 10h
        MOV AL, 'R'
        INT 10h
        MOV AL, 'E'
        INT 10h
        MOV AL, ':'
        INT 10h
        MOV AL, ' '
        INT 10h

        MOV CX, 2      ;prepare for GET_DIGIT_LOOP
        MOV BL, 10     ;prepare for division by 10
        MOV AL, SCORE  
GET_DIGIT_LOOP:
        XOR AH, AH
        DIV BL         ;AH gets the decimal digit
        PUSH AX        ;push the remainder on the stack
        LOOP GET_DIGIT_LOOP

        MOV CX, 2      ;prepare for DISPLAY_LOOP
        MOV BH, 0      ;page 0
        MOV BL, 1111b  ;white color
DISPLAY_LOOP:
        POP AX         ;AH gets the decimal digit
        MOV AL, AH     ;AL gets the decimal digit
        ADD AL, 30h    ;change the decimal number to ASCII digit
        MOV AH, 0Eh    ;write character function
        INT 10h
        LOOP DISPLAY_LOOP

        RESTORE_REGS <DX, CX, BX, AX> 
        RET
SCORING ENDP
        END
