装配:打印来自AL,AH和BH的信息

时间:2014-09-30 17:22:32

标签: assembly tasm

需要获取有关当前视频模式的信息。函数0fh会在ALAHBH个寄存器中返回此信息。如何从这个寄存器中打印信息(十进制格式)?

感谢您的回答。

.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

1 个答案:

答案 0 :(得分:1)

网上有很多关于此任务的解释和示例。诀窍是重复将寄存器除以10并存储余数。以下是我的建议,特别是针对您的需求:

.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