一个字符串本身占用一个字节,而指到字符串的指针则占用两个字节,如果有128个字符需要扩充时,则总共需要284个字节.另外原先的程序大约需要增加50个字节.因此整个程序的大小就变成大约半K字节.假设每一个扩充字符串占用20个字节,那么128个扩充键就需2.5K字节,这和程序代码的0.5K字节加起来,总共也不过3K字节,还比前一种方法少10K字节.
上面的单键扩充程序转换成多键扩充程序时,只要修改其中的KeyRead这个程序以及数据区的内容即可.以下就是修改后的内容:
;Read a character from the keyboard input queue,
;if not expanding or the expansion string.
;if expansion is in progress
KeyRead proc
cmp cs:current,0
jne ExpandChar
ReadChar:
mov cs:current,0 ;Slightly peculiar
pushf ;Let original routine
call Old_Keyboard_IO ;Get keyboard status
cmp al,0
je Extended
jmp ReadDone
Extended:
cmp byte ptr cs:[si],0 ;Is this end of table?
je ReadDone
cmp ah,cs:[si]
je StartExpand
add si,3
jmp NextExt
StartExtend:
push bx
add si,1
mov bx,cs:[si]
mov cs:current,bx ;If so,start expanding
ExpandChar:
mov si,cs:current
mov al,cs:[si]
inc cs:current
cmp al,0 ;Is this end of string?
je ReadChar ;If so,then read a real char?
ReadDone:
pop si
ret
KeyRead endp
current dw 0
KeyTab db 59
dw dir_cmd
db 60
dw dir_wide
db 61
dw dir_asm
db 62
dw dir_com
db 63
dw dir_exe
db 50
dw make_macro
db 0 ;This must be last in key table
dir_cmp db ''DIR'',0dh,0
dir_wide db ''DIR/W'',0dh,0
dir_asm db ''DIR *.ASM'',0dh,0
dir_com db ''DIR *.COM'',0dh,0
dir_exe db ''DIR *.EXE'',0dh,0
make_macro db ''MASM MACRO;'',0dh,0
db ''LINK MACRO;'',0dh,0
db ''EXE2BIN MACRO.EXE MACRO.COM'',0dh,0
&nb