【任务】用查表法输出16进制数的各个符号
(本任务旨在演示lodsb、stosb串传送指令,以及xlat查表指令)
【参考解答】
assume cs:coseg,ds:table,ss:stack,es:table
table segment
tab_da db 30h,31h,32h,33h,34h,35h,36h,37h,38h,39h
db 41h,42h,43h,44h,45h,46h
hextab db 0,1,2,3,4,5,6,7,8,9,0ah,0bh,0ch,0dh,0eh,0fh
asibuf db 16 dup(?)
eol db '$'
table ends
stack segment para stack 'stack'
stapn db 100 dup(?)
stack ends
coseg segment
start:
mov ax,table
mov ds,ax
mov es,ax
mov si,offset hextab ;根据si
mov bx,offset tab_da ;表的基址必须放在bx中(必须的)
mov di,offset asibuf ;结果放进di
mov cx,16 ;循环计数器
next:
lodsb ;从[si] 装入一个字节 --> al
xlat tab_da ;xlat以al为索引,查tab_da表,结果还是放在al中
stosb ;再将al存入[di]
loop next ;cx--,if cx<> 进入下一循环
mov cx,16
mov ah,2 ;显示字符的功能号
xor si,si
again:
mov dl,asibuf[si]
int 21h
inc si
loop again
mov ax,4c00h
int 21h
coseg ends
end start