8086汇编学习小记王爽汇编语言实验16

编写int 7ch中断例程,实现:

  1. 清屏
  2. 设置前景色
  3. 设置背景色
  4. 向前滚动一行

要求ah寄存器传递功能号:0, 1, 2, 3对应上述功能;al传递颜色值,al->[0, 7].

  1. 中断程序中的call,jmp都应该选择偏移类型的指令,因为标号地址是编译器在汇编或者连接时期计算的,用偏移量才能保证指令安装在别的地址也能正常运行。
  2. 标号后无冒号只能出现在代码段,无冒号可以代表数据类型和地址,有冒号的标号只能代表偏移。
  1 ;中断时的入栈顺序是pushf,push cs, push ip
  2 assume cs : codesg, ss : stacksg
  3 
  4 stacksg SEGMENT
  5      dw 16 dup (0)
  6 stacksg ENDS
  7 
  8 
  9 
 10 codesg SEGMENT
 11 
 12 start:    mov ax, 0
 13     mov es, ax
 14     mov di, 0200h
 15     mov ax, codesg
 16     mov ds, ax
 17     mov si, offset screen
 18 
 19     mov cx, offset scend - offset screen
 20     cld
 21     rep movsb
 22     
 23     mov word ptr es : [7ch * 4], 0200h
 24     mov word ptr es : [7ch * 4 + 2], 0
 25 
 26     mov ax, 4c00h
 27     int 21h
 28 
 29 
 30 screen:    jmp short begin
 31     table dw f0 - screen + 200h, f1 - screen + 200h, f2 - screen + 200h, f3 - screen + 200h
 32     begin:    push bx
 33         push ds
 34         mov bx, 0
 35         mov ds, bx
 36         cmp ah, 3
 37         ja sret
 38         mov bl, ah
 39         mov bh, 0
 40         add bx, bx
 41         call word ptr [table + bx - screen + 200h]
 42 
 43     sret:    pop ds
 44         pop bx
 45         iret
 46 
 47 f0:        push bx
 48         push es
 49         push cx
 50         mov bx, 0b800h
 51         mov es, bx
 52         mov bx, 0
 53         mov cx, 2000
 54     f0s:    mov byte ptr es : [bx], ' '
 55         add bx, 2
 56         loop f0s
 57         pop cx
 58         pop es
 59         pop bx
 60         ret
 61 
 62 f1:        push bx
 63         push es
 64         push cx
 65         mov bx, 0b800h
 66         mov es, bx
 67         mov bx, 0
 68         mov cx, 2000
 69     f1s:    and byte ptr es : [bx + 1], 11111000b
 70         or es : [bx + 1], al
 71         add bx, 2
 72         loop f1s
 73         pop cx
 74         pop es
 75         pop bx
 76         ret
 77 
 78 f2:        push bx
 79         push es
 80         push cx
 81         mov cl, 4
 82         shl al, cl
 83         mov bx, 0b800h
 84         mov es, bx
 85         mov bx, 0
 86         mov cx, 2000
 87     f2s:    and byte ptr es : [bx + 1], 10001111b
 88         or es : [bx + 1], al
 89         add bx, 2
 90         loop f2s
 91         pop cx
 92         pop es
 93         pop bx
 94         ret
 95 
 96 f3:        push di
 97         push es
 98         push si
 99         push cx
100         mov di, 0b800h
101         mov es, di
102         mov ds, di
103         mov si, 160
104         mov cx, 2000 - 80
105         cld
106         rep movsw
107         mov di, 1920
108         mov cx, 80
109     f3s:    mov byte ptr es : [di], ' '
110         add di, 2
111         loop f3s
112         pop cx
113         pop si
114         pop es
115         pop di
116         ret
117 
118 scend:    nop
119 codesg ENDS
120 END start

不上图了~

原文地址:https://www.cnblogs.com/ACystalMoon/p/2763743.html