【任务】设在内存单元SQTAB首址开始存放了0~15的平方数表。要求用直接查表法编一程序,求出A单元中给定数(<=15)的平方值送B单元保存。
【参考解答1】
assume cs: code, ds: data
data segment
sqtab db 0, 1, 4, 9, 16, 25, 36, 49, 64, 81
db 100, 121, 144, 169, 196, 225
a db 12
b db ?
data ends
code segment
start:
mov ax, data
mov ds, ax
mov bl, a ;以a中值作为索引值
mov bh, 0
mov al, sqtab[bx] ;在table中查找
mov b, al
mov ax, 4c00h
int 21h
code ends
end start
【参考解答2】(用专门的查表指令xlat)
assume cs: code, ds: data
data segment
sqtab db 0, 1, 4, 9, 16, 25, 36, 49, 64, 81
db 100, 121, 144, 169, 196, 225
a db 12
b db ?
data ends
code segment
start:
mov ax, data
mov ds, ax
mov bx, offset sqtab
mov al, a
xlat
mov b, al
mov ax, 4c00h
int 21h
code ends
end start