例9.11 编写清除全屏幕的子程序
 
  ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  ;eg9-11.asm
  ;Purpose: clear the screen
  ;Usage: call clear_screen
  ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  clear_screen   proc   near
  ;save registers

      push ax
        push bx
        push cx
        push dx

  ;clear screen
        mov ah, 6   ;to scroll up screen
        mov al, 0   ;blank screen
        mov bh, 7   ;blank line
        mov ch, 0   ;upper left row
        mov cl, 0   ;upper left column
        mov dh, 24   ;lower right row
        mov dl, 79  ;lower right column
        int 10h    ;call video BIOS


  ;locate cursor
        mov dx, 0
        mov ah, 2   ;to locate cursor
        int 10h    ;call video BIOS


  ;restore registers
        pop dx
        pop cx
        pop bx
        pop ax
        ret
  clear_screen   endp

  ;----------------------------------------------------------------

  10H的功能7和功能6类似,也能使屏幕(或窗口)初始化或使屏幕(或窗口)的内容下卷指定的行,其它参数的设置与功能6一样。请看下面的例9.12。

  例9.12 清除左上角为(0,0),右下角为(24,39)的窗口,初始化为反相显示,该窗口相当于全屏幕的左半部分。
     
MOV   AH,7   ;下卷功能
      MOV   AL,0   ;清屏
      MOV   BH,70H  ;反相显示属性
      MOV   CH,0   ;左上行
      MOV   CL,0   ;左上列
      MOV   DH,24   ;右下行
      MOV   DL,39   ;右下列
      INT   10H    ;BIOS显示调用


  下面我们编写一个完整的程序(例9.13)在PC机上运行。此程序在屏幕的中间建立一个20列宽和9行高的窗口,然后把键盘输入的内容在这个窗口显示出来。键入的字符将被显示在窗口的最下面一行, 每当输入20个字符,该行就向上卷动,9行字符输入完后,顶端行的内容消失。

  例9.13 在屏幕中心的小窗口显示字符。

  ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  ;eg9-13.asm
  ;Purpose: display characters in a window until Esc pressed
  ;* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  .model small
  ;--------------------------------------------------------------
  ;--------------------------------------------------------------
    .code
  Esc_key   equ 1bh    ;ASCII of Esc key
  win_ulc   equ 30    ;window upper left column
  win_ulr   equ 8     ;window upper left row
  win_lrc   equ 50    ;window lower right column
  win_lrr   equ 16    ;window lower right row
  win_width  equ 20    ;width of window

  include cls.inc ;clear the screen

  ; Main program
  main   proc   far
  call   clear_screen   ;clear the screen
  locate:
       mov   ah, 2      ;to locate cursor
       mov   dh, win_lrr   ;dx<=start position
       mov   dl, win_ulc
       mov   bh, 0      ;page# <= 0
       int   10h       ;call video BIOS

  ; get characters from kbd
       mov   cx, win_width  ;cx <= width of window
  get_char:
       mov   ah, 1      ;to accept input
       int   21h       ;call DOS
       cmp   al, Esc_key   ;judge whether Esc pressed
  jz    exit
  loop   get_char          ;get another

  ;scroll up
       mov   ah, 6      ;scroll up function
       mov   al, 1      ;number of scroll lines
       mov   ch, win_ulr   ;upper left row
       mov   cl, win_ulc   ;upper left column
       mov   dh, win_lrr   ;lower right row
       mov   dl, win_lrc   ;lower right column
       mov   bh, 7      ;attribute: normal
       int   10h       ;call video BIOS
       jmp   locate
  exit:
       mov   ax, 4c00h
       int   21h
  main   endp
  ;----------------------------------------------------------------
  end    main

  例9.13的程序使用了几种ROM显示例行程序:清除屏幕,光标定位和上卷。如果在屏幕上同时有几个窗口工作,就要分别清除它们,这可通过设置不同的左上角坐标和右下角坐标来完成。