为shr dx, 4这条语句报错?
;--------------------------------------
;这是Intel汇编语言程序设计这本书第16章的一个例子,它是一个简单的内存驻留程序,作用是阻止按Ctrl-Alt-Delete重启系统.它生成的是.COM程序,安装到内存中,系统只能通过特殊的组合键重启.(Ctrl-Alt-RightShift-Del)
;
;我的问题见程序(MASM6.15+WIN98SE 程序是运行在MS-DOS下):
;--------------------------------------
.model tiny
.code
rt_shift EQU 01h; Right shift key: bit 0
ctrl_key EQU 04h; CTRL key: bit 2
alt_key EQU 08h; ALT key: bit 3
del_key EQU 53h; scan code for DEL key
kybd_port EQU 60h; keyboard input port
org 100h; this is a COM program
start:
jmp setup
msgCtrl BYTE "Ctrl-Alt-Del no run ", 0dh, 0ah, '$ '
; Memory-resident code begins here
int9_handler PROC FAR
sti ; enable hardware interrupts
pushf ; save regs & flags
push es
push ax
push di
;Point ES:DI to the DOS keyboard flag byte:
L1:
mov ax, 40h; DOS data segment is at 40h
mov es, ax
mov di, 17h; location of keyboard flag
mov ah, es:[di]; copy keyboard flag into AH
;Test for the CTRL and ALT keys:
L2:
test ah, ctrl_key; CTRL key held down?
jz L5; no: exit
test ah, alt_key; ALT key held down?
jz L5; no: exit
;Test for the DEL and Right-shift keys:
L3:
in al, kybd_port; read keyboard port
cmp al, del_key; DEL key pressed?
jne L5; no: exit
test ah, rt_shift; right shift key pressed?
jnz L5; yes: allow system reset
L4: ;-----------------------------
;问题1、我想在这时输出一些提示字符,可是执行后程序输出一堆乱码,然后就死机,按任何键都没用.只能冷启动.(是不是msgCtrl定义的位置不对?).
mov ah, 9
mov dx, OFFSET msgCtrl
int 21h
;-----------------------------
and ah, NOT ctrl_key ; no: turn off bit for CTRL
mov es:[di], ah; store keyboard_flag
L5:
pop di
pop ax
pop es
popf
jmp cs:[old_interrupt9];jump to INT 9 routine
old_interrupt9 DWORD ?
int9_handler ENDP
end_ISR label BYTE
setup:
mov ax, 3509h;get INT 9 vector
int 21h
mov word ptr old_interrupt9, bx ;save INT 9 vector
mov word ptr old_interrupt9 + 2, es
mov ax, 2509h;set INT 9 vector
mov dx, OFFSET int9_handler
int 21h
mov ax, 3100h;terminate and stay resident
;-----------------------------------------
;问题4:下面end_ISR的值是不是标号setup的值?
;-----------------------------------------
mov dx,OFFSET end_ISR;point to end of resident code
;-----------------------------
;问题2、这里书上的源代码是shr dx, 4, 可是编译时报错说:invalid instruction operands. 改成如下代码后就不报错?
;-----------------------------
shr dx, 1;divide by 16
shr dx, 1
shr dx, 1
shr dx, 1
inc dx;round upward to next paragraph
int 21h
;-----------------------------
;问题3、我执行这个程序后,是和书上说的一样,要按(Ctrl-Alt-RightShift-Del)才能重启,书上还说卸载该程序的唯一方法是关闭计算机并重新启动.我重新启动后,按(Ctrl-Alt-RightShift-Del)还是能重启,为什么?(按书上说的该程序不是被卸载了吗?)
;-----------------------------
END start
[解决办法]
8086 下移位指令要想移多位必须放到cl中:
mov cl,4
shr dx,cl
[解决办法]
楼上的,是放在CL上面
如果非要用立即数移动多位,这样用:
shl EXX,4