王爽课本第十六章实验求助
这个实验我用了一个int 9ch中断,这个中断在测试每个选项的时候都是没等输入就进入选项了,但是测试综合选项的时候就没有反应。按什么都没有反应。程序如下:
assume cs:code
stack segment
db 128 dup (0)
stack ends
code segment
start:
mov ax,stack
mov ss,ax
mov sp,128
push cs
pop ds
mov ax,0
mov es,ax
mov si,offset int9
mov di,204h
mov cx,offset int9end - offset int9
cld
rep movsb
push es:
pop es:
push es:
pop es:
cli
mov word ptr es:,204h
mov word ptr es:,0
sti
mov ax,4c00h
int 21h
int9:
push ax
push bx
push cx
push es
in al,60h
pushf
call dword ptr cs: ;调用这个中断子程序
mov ah,al
; cmp ah,3
; ja sret
setscreen:
sub ah,01H
; mov al,02h
; mov ah,02h
cmp ah,0Ah ;比较,0的扫描码是0Bh,1~3是2~4,因为前面减1。
; cmp ah,0h
je do1
cmp ah,1
je do2
cmp ah,2
je do3
cmp ah,3
je do4
jmp short sret
do1:
call sub1
jmp short sret
do2:
call sub2
jmp short sret
do3:
call sub3
jmp short sret
do4:
call sub4
sret:
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:,' '
add bx,2
loop sub1s
pop es
pop cx
pop bx
ret ;sub1 ends
;设置前景色为绿色
sub2:
push bx
push cx
push es
mov bx,0b800h
mov es,bx
mov bx,1
mov cx,2000
sub2s: mov al,00000010b
and byte ptr es:,11111000b
or es:,al
add bx,2
loop sub2s
pop es
pop cx
pop bx
ret ;sub2 ends
;设置背景色为洋红色
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: mov al,01010000b
and byte ptr es:,10001111b
or es:,al
add bx,2
loop sub3s
pop es
pop cx
pop bx
ret ; sub3 ends
;向上滚动一行
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 es:,' '
;
add si,2
loop sub4s1
pop ds
pop es
pop di
pop si
pop cx
ret ;sub4 ends
int9ret:
pop es
pop cx
pop bx
pop ax
iret
int9end:
nop
code ends
end start 请大家帮我看看什么问题? 测试程序在哪?
可以先描述一下这个程序如何使用吗?
程序先读取60端口,调用中断子程序读0000:0200的本文的子程序,然后用读进来的那个扫描码判断是那个选项。
in al,60h
pushf
call dword ptr cs: ;调用这个中断子程序
测试的话直接设 mov al, 03h,就是选第三项了。也是调用中断子程序读0000:0200的本文的子程序。
比如说这就是一个测试程序,没等输入就直接进入分支运行:
assume cs:code
stack segment
db 128 dup (0)
stack ends
code segment
start:
mov ax,stack
mov ss,ax
mov sp,128
push cs
pop ds
mov ax,0
mov es,ax
mov si,offset int9
mov di,204h
mov cx,offset int9end - offset int9
cld
rep movsb
push es:
pop es:
push es:
pop es:
cli
mov word ptr es:,204h
mov word ptr es:,0
sti
mov ax,4c00h
int 21h
int9:
push ax
push bx
push cx
push es
in al,60h
pushf
call dword ptr cs: ;调用这个中断子程序
mov ah,al
; cmp ah,3
; ja sret
setscreen:
sub ah,01H
mov al,02h
mov ah,02h ;这里把要比较的寄存器内容都设为要进行的分支选项,就能测试一个分支
cmp ah,0Ah ;比较,0的扫描码是0Bh,1~3是2~4,因为前面减1。
; cmp ah,0h
je do1
cmp ah,1
je do2
cmp ah,2
je do3
cmp ah,3
je do4
jmp short sret
do1:
call sub1
jmp short sret
do2:
call sub2
jmp short sret
do3:
call sub3
jmp short sret
do4:
call sub4
sret:
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:,' '
add bx,2
loop sub1s
pop es
pop cx
pop bx
ret ;sub1 ends
;设置前景色为绿色
sub2:
push bx
push cx
push es
mov bx,0b800h
mov es,bx
mov bx,1
mov cx,2000
sub2s: mov al,00000010b
and byte ptr es:,11111000b
or es:,al
add bx,2
loop sub2s
pop es
pop cx
pop bx
ret ;sub2 ends
;设置背景色为洋红色
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: mov al,01010000b
and byte ptr es:,10001111b
or es:,al
add bx,2
loop sub3s
pop es
pop cx
pop bx
ret ; sub3 ends
;向上滚动一行
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 es:,' '
;
add si,2
loop sub4s1
pop ds
pop es
pop di
pop si
pop cx
ret ;sub4 ends
int9ret:
pop es
pop cx
pop bx
pop ax
iret
int9end:
nop
code ends
end start peppapig 发表于 2019-1-24 08:29
比如说这就是一个测试程序,没等输入就直接进入分支运行:
assume cs:code
这不是测试程序,这是安装程序
仅仅只是把int9标号开始的代码安装到int9中断,但是并没有调用int9中断
堆栈不平衡了,进入int9中断时push了那么多寄存器,中断返回时直接iret ???
还有,你能不能给标号取个有意义的名字?
do1 do2 do3 do4 sub1 sub2 sub3
do1是做什么的?
sub3呢?
后面我没看,现在只是中断能够正确返回
安装int9后,进入debug,按数字1 2 3 4屏幕背景会变化
assume cs:code
stack segment
db 128 dup (0)
stack ends
code segment
start:
mov ax, stack
mov ss, ax
mov sp, 128
push cs
pop ds
mov ax, 0
mov es, ax
mov si, offset int9
mov di, 204h
mov cx, offset int9end - offset int9
cld
rep movsb
push es:
pop es:
push es:
pop es:
cli
mov word ptr es:, 204h
mov word ptr es:, 0
sti
mov ax, 4c00h
int 21h
int9:
push ax
push bx
push cx
push es
in al, 60h
pushf
call dword ptr cs: ; 调用这个中断子程序
mov ah, al
setscreen:
sub ah, 01h
cmp ah, 0ah
je do1
cmp ah, 1
je do2
cmp ah, 2
je do3
cmp ah, 3
je do4
jmp short int9ret
do1:
call sub1
jmp short int9ret
do2:
call sub2
jmp short int9ret
do3:
call sub3
jmp short int9ret
do4:
call sub4
int9ret:
pop es
pop cx
pop bx
pop ax
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:,' '
add bx,2
loop sub1s
pop es
pop cx
pop bx
ret ;sub1 ends
;设置前景色为绿色
sub2:
push bx
push cx
push es
mov bx,0b800h
mov es,bx
mov bx,1
mov cx,2000
sub2s: mov al,00000010b
and byte ptr es:,11111000b
or es:,al
add bx,2
loop sub2s
pop es
pop cx
pop bx
ret ;sub2 ends
;设置背景色为洋红色
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: mov al,01010000b
and byte ptr es:,10001111b
or es:,al
add bx,2
loop sub3s
pop es
pop cx
pop bx
ret ; sub3 ends
;向上滚动一行
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 es:,' '
;
add si,2
loop sub4s1
pop ds
pop es
pop di
pop si
pop cx
ret ;sub4 ends
int9end:
nop
code ends
end start
页:
[1]