我的书是第二版,16.4里面的3号函数好像有点问题,答案也感觉不太简洁
把自己写的分享出来,欢迎讨论~
assume cs:code
code segment
start: mov ax, cs
mov ds, ax
mov si, offset f
mov ax, 0
mov es, ax
mov di, 200h
mov cx, offset fend - offset f
cld
rep movsb
mov word ptr es:[7ch*4], 200h
mov word ptr es:[7ch*4+2], 0
call input ;这个input代码段是我自己加的,可以主动控制函数的输出
;答案里是mov ah, 2 mov al, 5
int 7ch
mov ax, 4c00h
int 21h
org 200h
f: jmp short fb
table dw f1, f2, f3, f4
fb: push bx
push cx
push es
push di
mov bx, 0b800h
mov es, bx
mov di, 0
cmp ah, 3
ja fe
mov bl, ah
mov bh, 0
add bx, bx
jmp word ptr table[bx]
f1: mov cx, 2000
s1: mov byte ptr es:[di], ' '
add di, 2
loop s1
jmp near ptr fe
f2: mov cx, 2000
s2: and byte ptr es:[di+1], 11111000b
or es:[di+1], al
add di, 2
loop s2
jmp near ptr fe
f3: mov cl, 4
shl al, cl
mov cx, 2000
s3: and byte ptr es:[di+1], 10001111b
or es:[di+1], al
add di, 2
loop s3
jmp near ptr fe
f4: mov bx, 160
mov cx, 24*80
s4: push cx
mov cx, es:[bx]
mov es:[di], cx
add di, 2
add bx, 2
pop cx
loop s4
mov cx, 80
s40: mov byte ptr es:[di], ' '
add di, 2
loop s40
fe: pop di
pop es
pop cx
pop bx
iret
fend: nop
;这个input代码段是我自己加的,可以主动控制函数的输出
input: jmp short ib
str db 'please input the num of operation:', '$'
str2 db 'please input the num of color:', '$'
ib: push bx
push ds
push dx
mov ax, seg input
mov ds, ax
mov dx, offset str
mov ah, 9
int 21h
mov ah, 1
int 21h
sub al, '0'
mov ah, al
cmp ah, 1
je deal
cmp ah, 2
jne ie
deal: push ax
mov ax, seg input
mov ds, ax
mov dx, offset str2
mov ah, 9
int 21h
mov ah, 1
int 21h
mov bl, al
sub bl, '0'
pop ax
mov al, bl
ie: pop dx
pop ds
pop bx
ret
code ends
end start