實驗目的
- 掌握xlat指令查表方法
- 通過不同的儲存器定址方式實現查表操作
參考:課本68頁
windows掛載
mount c e:\masm
複製程式碼
xlat每個單元項在記憶體中只能佔用一個位元組
1.使用xlat指令進行查表
【1】.使用xlat指令條件
(1)要求給出的數,與 你要查詢的內容在 表中的偏移位置 是相等關係
(2)xlat指令要求你查詢的表中的內容不能超過8個二進位制位的表示範圍

【2】.使用xlat指令的步驟-al <- bx + al
- bx中放置表的首地址值
- al裡放你給出的數,你給出來的是 你要查詢的內容在表中的偏移位置
- xlat
- 你要查詢的內容會放在我們的al裡面
題目
1.獲取給定位置(hex)中的數
(al) <—(bx)+(al)
- bx中放置表的首地址值,得到mess[0]
- al裡放你給出的數,hex為第15個
- xlat
- 需要查詢的內容會放在al裡


data segment
sentence db 'qwqwqwqw'
mess db '0123456789abcdef'
hex db 0fh ;hex為我想取出mess中的 mess[hex]位置,此處指 mess[15]=f
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
;把mess的偏移地址賦給BX,即BX指向mess[0]
;lea bx,mess
mov bx,offset mess
;[hex] 預設為 ds:[hex]
mov al,[hex]
xlat
mov dl,al
mov ah,2
int 21h
mov ah,4ch
int 21h
code ends
end start
複製程式碼
【收穫⚠️】
1.給出的數(hex) == 所要查詢的內容在 表中的偏移位置
2.ds暫存器不一定是從0開始,要注意不是每一次取ds:[0]都是所要獲取的數

2.獲取成績單


data segment
table db '99$','98$','97$'
db '89$','88$','87$'
db '79$','78$','77$'
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov bl,1 ;想獲取第二行第二個資料--88
mov al,bl
mov bh,0
mov bl,9 ;一行裡面包括了9個位元組的資料(一行九個位元組的記憶體單元)
mul bl ;ax=al*1--已經而已到第二行的開頭資料
mov si,3
mov bx,ax
;mov dl,table[bx+si] 是把所在偏移地址的內容放到dl中方
;但是我們是想輸出是 88$ 那個字串,應該是它的偏移地址給dx
mov dx,offset table
add bx,si
add dx,bx
mov ah,9
int 21h
mov ah,4ch
int 21h
code ends
end start
複製程式碼
【收穫⚠️】
【1】db位元組型別-一個位元組資料佔一個位元組單元,讀完以後位移量加1
我原本想去除的是成績 89 ,但是輸出的是 8 ,是我理解錯誤了

【2】dx(dh、dl)是暫存器,ds是資料段
【3】error A2048:Must be index or base register
錯誤原因:使用暫存器間接定址時,只可以使用 BX, BP, SI, DI 這四個暫存器中的一個,不可以使用其它暫存器。

【4】運算元是字串在儲存單元中的放置

注意看 db 型別的 ‘hello’ 中在
【5】mov指令是將實體地址XXX儲存單元中的儲存內容送入暫存器中
將AX中的值寫入資料段的4000H單元
MOV DS:[4000H],AX
複製程式碼


【6】字串中偏移地址的獲取需用offset,而且末尾需要 結束,不可以直接mov dl,table[bx+si] 而是需要先mov dx,offset table ,然後通過add 將si和bx併入到dx中
- table[si+bx]--是將儲存單元中的內容給了出去
- offset--將偏移地址給了出去
3.使用空格補全姓名進行查詢學生姓名的操作

- 通過對不同長度名字後方新增空格使得每一個字串的總長度一致(本例項中長度為16)


data segment
mess db 'Please Input student number:$'
table db 0ah,0dh,'heaijia $'
db 0ah,0dh,'huangxuechun $'
db 0ah,0dh,'zhanghao $'
db 0ah,0dh,'zhangshuo $'
db 0ah,0dh,'liujinyi $'
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov dx,offset mess
mov ah,9
int 21h
mov ah,1
int 21h
sub al,30h
mov bl,16
mul bl ;ax=al*bl
;mov dx,offset table
;add dx,ax
mov bx,offset table
add ax,bx
mov dx,ax
mov ah,9
int 21h
mov ah,4ch
int 21h
code ends
end start
複製程式碼
【收穫⚠️】
【1】長度的計算--串結束符也算做一位,計算錯誤就出不來了
4.使用dw存t0,t1,t2,t3,t4,t5的形式進行查表,t0,t1,t2,t3,t4,t5指向db新內容


data segment
mess db 'Please Input student number:$'
sign dw q1,q2,q3,q4,q5
;db 1 2 3 4 5
;dw 2 4 6 8 10
q1 db 0ah,0dh,'heaijia$'
q2 db 0ah,0dh,'huangxuechun $'
q3 db 0ah,0dh,'zhangha$'
q4 db 0ah,0dh,'z$'
q5 db 0ah,0dh,'buxiwangongzuoshizongfuzerenheaijia$'
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov dx,offset mess
mov ah,9l
int 21h
mov ah,1
int 21h
sub al,30h
mov ah,0
add ax,ax
mov bx,ax
mov dx,sign[bx]
mov ah,9
int 21h
mov ah,4ch
int 21h
code ends
end start
複製程式碼
六大定址方式
