王爽实验16 我不明白!
本帖最后由 yerssa 于 2014-01-16 13:13:16 编辑 assume cs:code
code segment
start:
mov ax,cs
mov ds,ax
mov si,offset setscreen
mov ax,0
mov es,ax
mov di,200h
mov cx,offset setscreenend-offset setscreen
cld
rep movsb
mov ax,0
mov es,ax
mov word ptr es:[7ch*4],200h
mov word ptr es:[7ch*4+2],0
mov ax,4c00h
int 21h
setscreen:
jmp short set
table dw sub1-setscreen+200h,sub2-setscreen+200h,sub3-setscreen+200h,sub4-setscreen+200h
set:
push bx
cmp ah,3
ja sret
mov bl,ah
mov bh,0
add bx,bx ;dw占2个字节,乘2来取得对应位置
sub bx,offset setscreen
add bx,200H
call word ptr table[bx]
sret:
pop bx
iret
sub1:
push bx
push cx
push es
mov bx,0b800h
mov es,bx
mov bx,0
mov cx,2000
sub1s:
mov byte ptr es:[bx],' '
add bx,2
loop sub1s
pop es
pop cx
pop bx
ret
;改变前景色,al中保存了颜色值
sub2:
push bx
push cx
push es
mov bx,0b800h
mov es,bx
mov bx,1
mov cx,2000
sub2s:
add byte ptr es:[bx],11111000b
or es:[bx],al
add bx,2
loop sub2s
pop es
pop cx
pop bx
ret
;改变背景色,al中保存了颜色值
sub3:
push bx
push cx
push es
mov cl,4
shl al,cl
mov bx,0b800h
mov es,bx
mov bx,1
mov cx,2000
sub3s:
add byte ptr es:[bx],10001111b
or es:[bx],al
add bx,2
loop sub3s
pop es
pop cx
pop bx
ret
sub4:
push cx
push si
push di
push es
push ds
mov si,0b800h
mov es,si
mov ds,si
mov si,160
mov di,0
cld
mov cx,24
sub4s:
push cx
mov cx,160
rep movsb
pop cx
loop sub4s
mov cx,80
mov si,0
sub4s1:
mov byte ptr [160*24+si],' '
add si,2
loop sub4s1
pop ds
pop es
pop di
pop si
pop cx
ret
setscreenend:
nop
code ends
end start
红字的地方我不明白,麻烦详细解释下!
[解决办法]
从 setscreen: 开始是要被移到 0000:0200 处的,所以其后代码中对地址的使用,必须要进行地址的调整重定位,(200h-setscreen) 就是这个重定位的调整值,需要对每个引用的地址加上它,红色的地方,都是某个地址加上这个 (200h-setscreen)