纨绔僵神txt全集下载:汇编,答的好追加100分,答的一般追加10.

来源:百度文库 编辑:高校问答 时间:2024/05/06 05:00:38
and ax,0fh ;转换ASCII为数值
shl ax,1
mov bx,ax
jmp AddrTbl[bx] ;转入处理程序入口地址
有谁知道这段程序有什么用?
and ax,0fh
shl ax,1 基数时这样不是比对应的ascll码少1?
[bx]里的到底是什么,是bx中的值的大小?还是它的内存地址?
不过好像都不对.完整程序如下:
;Ex506
CR = 0dh
LF = 0ah
dseg segment
Msg db 'Input a function number(0-5):','$'
Msg0 db CR,LF,'Function 0 executed.',CR,LF,'$'
Msg1 db CR,LF,'Function 1 executed.',CR,LF,'$'
Msg2 db CR,LF,'Function 2 executed.',CR,LF,'$'
Msg3 db CR,LF,'Function 3 executed.',CR,LF,'$'
Msg4 db CR,LF,'Function 4 executed.',CR,LF,'$'
Msg5 db CR,LF,'Function 5 executed.',CR,LF,'$'
ErrMsg db CR,LF,'Invalid function number.',CR,LF,'$'
AddrTbl dw Func0,Func1,Func2,Func3,Func4,Func5
dseg ends

cseg segment
assume cs:cseg,ds:dseg
Start:
mov ax,dseg
mov ds,ax

lea dx,Msg
mov ah,9
int 21h

mov ah,1
int 21h

cmp al,'0'
jb Error
cmp al,'5'
ja Error

and ax,0fh
shl ax,1
mov bx,ax
jmp AddrTbl[bx]

Func0: lea dx,Msg0
jmp Output
Func1: lea dx,Msg1
jmp Output
Func2: lea dx,Msg2
jmp Output
Func3: lea dx,Msg3
jmp Output
Func4: lea dx,Msg4
jmp Output
Func5: lea dx,Msg5
jmp Output
Error: lea dx,ErrMsg
jmp Output
Output: mov ah,9
int 21h
mov ah,4ch
int 21h
cseg ends
end Start

了解了。
我把整个程序说说一下子吧。
CR = 0dh ;这就不说了
LF = 0ah
dseg segment ;这个也不说了
Msg db 'Input a function number(0-5):','$'
Msg0 db CR,LF,'Function 0 executed.',CR,LF,'$'
Msg1 db CR,LF,'Function 1 executed.',CR,LF,'$'
Msg2 db CR,LF,'Function 2 executed.',CR,LF,'$'
Msg3 db CR,LF,'Function 3 executed.',CR,LF,'$'
Msg4 db CR,LF,'Function 4 executed.',CR,LF,'$'
Msg5 db CR,LF,'Function 5 executed.',CR,LF,'$'
ErrMsg db CR,LF,'Invalid function number.',CR,LF,'$'
AddrTbl dw Func0,Func1,Func2,Func3,Func4,Func5 ;这个要说,定义了一个数组addrtbl,看清楚了是world类型的。很重要,还有就是func0....什么的都是下边的标号,也就是地址。
dseg ends

cseg segment
assume cs:cseg,ds:dseg
Start:
mov ax,dseg
mov ds,ax

lea dx,Msg
mov ah,9
int 21h

mov ah,1
int 21h

cmp al,'0'
jb Error
cmp al,'5'
ja Error

and ax,0fh ;这里好好说说,将ax高字节清0
shl ax,1 ;ax左移一位,其是就是乘以2的意思,因为func0...的都是双字节。你输入2的时候应该是
AddrTbl+4是吧。
mov bx,ax ;将偏移放入bx
jmp AddrTbl[bx] ;跳转到bx+addrtbl这个地址,也就是下边的func0 func1....标号处。

Func0: lea dx,Msg0 ;下边没有什么好说的了吧。
jmp Output
Func1: lea dx,Msg1
jmp Output
Func2: lea dx,Msg2
jmp Output
Func3: lea dx,Msg3
jmp Output
Func4: lea dx,Msg4
jmp Output
Func5: lea dx,Msg5
jmp Output
Error: lea dx,ErrMsg
jmp Output
Output: mov ah,9
int 21h
mov ah,4ch
int 21h
cseg ends
end Start