實驗5 編寫 除錯具有多個段的程式

2021-09-29 18:53:10 字數 3837 閱讀 7424

assume cs:code, ds:data, ss:stack

data segment

dw 0123h, 0456h, 0789h, 0abch, 0defh, 0fedh, 0cbah, 0987h

data ends

stack segment

dw 0, 0, 0, 0, 0, 0, 0, 0

stack ends

code segment

start: mov ax, stack

mov ss, ax

mov sp, 16 ;ss:sp stack

mov ax, data

mov ds, ax ;ds data

push ds:[0]

push ds:[2]

pop ds:[2]

pop ds:[0]

mov ax, 4c00h

int 21h

code ends

end start

(1)cpu執行程式,程式返回前,data段中的資料是多少?

(2)cpu執行程式,程式返回前,cs=1458h, ss=1457h, ds=1456h

(3)設程式載入後,code段的位址為x,則data段的位址x-2,stack段為x-1

assume cs:code, ds:data, ss:stack

data segment

dw 0123h, 0456h

data ends

stack segment

dw 0, 0

stack ends

code segment

start:

mov ax, stack

mov ss, ax

mov sp, 16 ;ss:sp stack

mov ax, data

mov ds, ax

push ds:[0]

push ds:[2]

pop ds:[2]

pop ds:[0]

mov ax, 4c00h

int 21h

code ends

end start

(1)cpu執行程式,程式返回前,data段中的資料是多少?

(2)cpu執行程式,程式返回前,cs=1458h, ss=1457h, ds=1456h

(3)設程式載入後,code段的位址為x,則data段的位址x-2,stack段為x-1

(4)如果段中的資料佔n個位元組,則程式載入後,該段實際占有的空間為:[(n/16)+1]*16 位元組

邊追蹤邊檢視記憶體的資料:

push ds:[0] (因為sp=10h,所以一開始ss:sp指向10h,即在1456:0020最開始的位置),可以發現另起了一行,無論你的段申請夠不夠16個位元組,計算機都會幫你直接申請夠一行,也就是16個位元組。

出棧後,1456:0010的資料就發生了改變。

(2)cpu執行程式,程式返回前,cs=1456h, ss=145ah, ds=1459h

(3)設程式載入後,code段的位址為x,則data段的位址x+3,stack段為x+4

第3個。「end start」改為"end"會使1、2無法從start處開始執行,不能正確的設定cs:ip指向程式的第一條要執行的指令。

assume cs:code

a segment

db 1,2,3,4,5,6,7,8

a ends

b segment

db 1,2,3,4,5,6,7,8

b ends

c segment

db 0,0,0,0,0,0,0,0

c ends

code segment

start:

mov ax,a

mov ds,ax ;將ds指向a資料段

mov ax,b

mov ss,ax ;將ss指向b資料段

mov ax,c

mov es,ax ;es指向c的資料段

mov bx,0

mov cx,8

s: mov al,ds:[bx]

add al,ss:[bx]

mov es:[bx],al

inc bx

loop s

mov ax,4c00h

int 21h

code ends

end start

db 定義位元組型資料,所以用al就夠了。

assume cs:code

a segment

dw 1,2,3,4,5,6,7,8,9,0ah,0bh,0ch,0dh,0eh,0fh,0ffh

a ends

b segment

dw 0,0,0,0,0,0,0,0

b ends

code segment

start:

mov ax,a

mov ds,ax

mov ax,b

mov ss,ax

mov sp,10h

mov bx,0

mov cx,8

s: push [bx]

add bx,2

loop s

mov ax,4c00h

int 21h

code ends

end start

8個字型資料=16個位元組,0~f為棧空間,則最開始sp為f+1=10h。

dw定義字型資料,所以程式中dw 1,2,3,4,5,6,7,8,9,0ah,0bh,0ch,0dh,0eh,0fh,0ffh為16個字,佔32個位元組,可以發現,

計算機會將 01 處理為 00 01。

追蹤程式:

實驗 5 編寫 除錯具有多個段的程式

一 實驗任務 完成教材133實驗5 1 將下面的程式編譯 連線,用debug載入 跟蹤,然後回答問題。用u指令反彙編,g指令執行到001d前,得到程式返回前。1 cpu執行程式,程式返回前,data段中的資料為多少?2 cpu執行程式,程式返回前,cs 076c ss 076b ds 076a。3 ...

實驗 5 編寫 除錯具有多個段的

實驗任務 4 若將最後一條指令 end start 改為 end 3 中的程式仍然可以正常執行。原因 如果不指明程式的入口,程式的cs ip值沒有被設定為指向該入口,就會以程式段的第一條指令為預設入口了,然後程式會在end處結束,無法執行到 段。5 實驗 assume cs code a segme...

實驗五 編寫除錯具有多個段的程式

實驗一 將下面的程式編譯,連線,用debug載入,跟蹤,然後回答問題 執行程式截圖如下 總結 cpu執行程式,程式返回前,data段中的資料不變 cpu執行程式,程式返回前,cs 076c,ss 076b,ds 076a 設程式載入後,code段的段位址為x,則data段的段位址為x 2,stack...