Search code examples
assemblytasm

Assembly: Print information from AL, AH and BH


Need to get information about the current video mode. Function 0fh returns this info in AL, AH and BH registers. How to print information (in decimal format) from this registers?

Thanks for answer.

.model tiny
.code

org 100h 
start:
    mov ah,9
    lea dx, select_video_mode_msg 
    int 21h
    call readsymb

change_video_mode:
    mov ah,00h
    int 10h 

change_video_page_msg:
    mov ah,9
    lea dx, select_video_page_msg 
    int 21h
    call readsymb

change_video_page:
    mov ah,05h
    int 10h 

print_info:
    mov ah,0fh
    int 10h 
    ; print info from AL, AH, BH

endprog:
    ret


readsymb:
    mov ah,01h
    int 21h 
    cmp al,2fH 
    jz endprog
    cmp al,'0'
    jz endprog 
    cmp al,'9'
    ja endprog 
    xor ah,ah 
    sub al,30h 
    ret

.data
select_video_mode_msg   db  'Select video mode (0-7): ','$'
select_video_page_msg   db  'Select video page: ','$'
info_msg_cols           db  'Symbs cols: ','$' 
info_msg_mode           db  'Current mode: ','$' 
info_msg_page           db  'Current page: ','$' 
md                      db  '$'


end start

Solution

  • There are sooo many explanations and examples for this task in the net. The trick is to repeatedly divide the register by 10 and store the remainder. Here is my suggestion especially for your needs:

    .MODEL tiny
    .CODE
    ORG 100h
    
    start:
    
        call print_info
    
        mov ax, 4C00h                   ; Exit(0)
        int 21h
    
    
    print_info:
        mov ah,0fh                      ; GET CURRENT VIDEO MODE
        int 10h                         ; Call Video-BIOS
        mov WORD PTR HOLD_AL, ax        ; This affects also HOLD_AH
        mov HOLD_BH, bh
    
        ; AL
        mov ah, 09h                     ; WRITE STRING TO STANDARD OUTPUT
        lea dx, INFO1                   ; Pointer to string
        int 21h                         ; Call MS-DOS
        mov al, HOLD_AL                 ; Argument for al2dec
        call al2dec                     ; Convert AL to decimal-string
        mov ah, 09h                     ; WRITE STRING TO STANDARD OUTPUT
        mov dx, di                      ; Result of al2dec
        int 21h                         ; Call MS-DOS
    
        ; AH
        mov ah, 09h                     ; WRITE STRING TO STANDARD OUTPUT
        lea dx, INFO2                   ; Pointer to string
        int 21h                         ; Call MS-DOS
        mov al, HOLD_AH                 ; Argument for al2dec
        call al2dec                     ; Convert AL to decimal-string
        mov ah, 09h                     ; WRITE STRING TO STANDARD OUTPUT
        mov dx, di                      ; Result of al2dec
        int 21h                         ; Call MS-DOS
    
        ; BH
        mov ah, 09h                     ; WRITE STRING TO STANDARD OUTPUT
        lea dx, INFO3                   ; Pointer to string
        int 21h                         ; Call MS-DOS
        mov al, HOLD_BH                 ; Argument for al2dec
        call al2dec                     ; Convert AL to decimal-string
        mov ah, 09h                     ; WRITE STRING TO STANDARD OUTPUT
        mov dx, di                      ; Result of al2dec
        int 21h                         ; Call MS-DOS
    
        ret
    
    al2dec:
        mov bl, 10                      ; Base 10 -> divisor
        lea di, DEC_END
      L1:
        dec di                          ; fill the decimal-string in reverse order
        xor ah, ah                      ; Clear AH for division
        div bl                          ; AL = AX / BL   Remainder AH
        or ah, 30h                      ; Convert AH to ASCII
        mov BYTE PTR [di], ah           ; Save AH in the decimal-string
        test al, al                     ; AL == 0?
        jnz L1                          ; No: once more
        ret                             ; Return DS:DI Pointer to the decimal-string
    
    
                DB  "000"               ; String
        DEC_End EQU $                   ;   with label pointing to its end (+1)
                DB 13, 10, '$'          ;   and line feed and '$'-terminator
        INFO1   DB "AL (display mode): $"
        INFO2   DB "AH (number of character columns): $"
        INFO3   DB "BH (active page): $"
        HOLD_AL DB ?                    ; Uninitialized space for saving AL
        HOLD_AH DB ?                    ; Uninitialized space for saving AH
        HOLD_BH DB ?                    ; Uninitialized space for saving BH
    
    END start