驗證性實驗:有些匯編指令會影響到標志寄存器中的一個或多個狀態標志位。
在debug環境中,分別實踐、觀察:
① add指令對標志寄存器中的零標志位ZF(Zero Flag)、進位標志位CF(Carry Flag)是否有影響?
② inc指令對標志寄存器中的零標志位ZF(Zero Flag)、進位標志位CF(Carry Flag)是否有影響?
使用任意文本編輯器,錄入8086匯編源碼task1.asm。
task1.asm
assume cs:code, ds:data
data segment
x dw 1020h, 2240h, 9522h, 5060h, 3359h, 6652h, 2530h, 7031h
y dw 3210h, 5510h, 6066h, 5121h, 8801h, 6210h, 7119h, 3912h
data ends
code segment
start:
mov ax, data
mov ds, ax
mov si, offset x
mov di, offset y
call add128
mov ah, 4ch
int 21h
add128:
push ax
push cx
push si
push di
sub ax, ax
mov cx, 8
s: mov ax, [si]
adc ax, [di]
mov [si], ax
inc si
inc si
inc di
inc di
loop s
pop di
pop si
pop cx
pop ax
ret
code ends
end start
其中:
add128是子程序子程序。
功能:實現計算兩位128位數的加法
入口參數:
ds:si指向存儲第一個128位數的存儲空間(因為一個數128位,需要8個字節的連續空間)
ds:di指向存儲第二個128位數的存儲空間
出口參數:
加運算后的結果,保存在第一個數的存儲空間中,即:ds:si開始的連續8個字節空間
在代碼段種,調用add128實現對標號x和y處存儲的兩個128位數據相加,結果保存在x處的連續128個字
節中。
對程序進行匯編、鏈接,得到可執行程序task1.exe。在debug中調試程序,並回答問題。
① line31~line34的4條inc指令,能否替換成如下代碼?你的結論的依據/理由是什么?
add si, 2
add di, 2
② 在debug中調試,觀察數據段中做128位加之前,和,加之后,數據段的值的變化。
不能,add和sub對進位都有影響,替換后進位將無法被處理。
實驗任務2
匯編指令代碼line11-18,實現的功能是?
判斷輸入的字符是否為#,如果是的話跳出s1循環
2.
換行
3.
輸出長為si的字符串
試驗任務3
assume cs:code, ds:data
data segment
x dw 91, 792, 8536, 65521, 2021
len equ $ - x
data ends
stack segment
db 16 dup(0)
stack ends
code segment
start:
mov ax, data
mov ds, ax
mov cx, 5
mov si, offset x
s: mov ax, ds:[si]
call printNumber
call printSpace
inc si
inc si
loop s
mov ah, 4ch
int 21h
printNumber:
mov bx, 0AH ;除數
mov dx, 0 ;高位置為0,記錄余數
mov di, 0
push cx
s1: div bx
push dx ;余數入棧
inc di
mov dx, 0
cmp ax, 0 ;被除數為0時結束
je next
jmp s1
next: mov ah, 2
mov cx, di
s2: pop dx
or dl, 30H ;數字轉字符
int 21h
loop s2
pop cx
ret
printSpace:
mov dl, ' '
mov ah, 2
int 21h
ret
code ends
end start
試驗任務4
data segment
str1 db "assembly language, it's not difficult but tedious"
len equ $ - str1
data ends
stack segment
db 16 dup(0)
stack ends
code segment
assume cs:code,ds:data,ss:stack
start:
mov ax,data
mov ds,ax
mov si,offset str1
mov cx,len
call strupr
mov ah,4ch
int 21h
strupr:
s:
mov al,ds:[si]
cmp al,'a'
jb next
cmp al,'z'
ja next
and al,0dfh;1101 1111
mov ds:[si],al
next:
inc si
loop s
ret
code ends
end start
試驗任務5
試驗任務 6
中斷是指CPU不再接着向下執行,而是轉去處理這個特殊信息。
CPU接受到中斷信息后,可以立即對中斷信息進行處理,用來處理中斷信息的程序被稱為中斷處理程序。
軟中斷是指由軟件本身發給操作系統內核的中斷信號。
中斷過程是先從從中斷信息中取得中斷類型碼,然后令標志寄存器的值入棧(因為在中斷過程中要改變標志寄存器的值,所以先將其保存在棧中),並設置標志寄存器的第8位TF和第9位IF的值為0。CS的內容入棧,IP的內容入棧。最后從內存地址為中斷類型碼4和中斷類型碼4+2的兩個子單元中讀取中斷處理程序的入口地址設置IP和CS。
好文要頂