下面的程式中將codesg段的8個資料累加,結果儲存到b處的雙位元組中,補全程式。
assume cs:codesg<br />codesg segment<br /> a dw 1,2,3,4,5,6,7,8<br /> b dd 0 </p><p> start:<br /> mov si,0<br /> mov cx,8<br /> s:<br /> mov ax,__(1)___<br /> add ___(2)___,ax<br /> adc ___(3)___,0<br /> add si,___(4)___<br /> loop s </p><p> mov ax,4c00h<br /> int 21h </p><p>codesg ends<br />end start
解析:在開始之前,一定要看清楚了在定義a、b時,它們的後面並沒有冒號。這一點很關鍵,我就是沒有注意到這一點,導致偵錯工具的時候,用a[si]取得的值並不正確,本來應該是在地址cs:a[si]取得的,但是如果有冒號的話,它則是從地址ds:a[si]取得。所以看書還是要小心仔細啊。接下來的事情就是順利成章了:
(1)處是要填寫a[si]用以取得在a處定義的資料
(2)處時要填寫b[0],因為相加的另一個資料時ax。所以在b[0]前要有word ptr 的限制
(3)與(2)同樣的道理,填寫word ptr b[2]
(4)處要填寫2,應為a處定義的是字。所以加2
原始碼:
assume cs:codesg<br />codesg segment<br /> a db 1,2,3,4,5,6,7,8<br /> b dw 0 </p><p> start: </p><p> mov si,0<br /> mov cx,8 </p><p> s:<br /> mov al,a[si]<br /> mov ah,0<br /> add b,ax<br /> inc si<br /> loop s </p><p> mov ax,4c00h<br /> int 21h </p><p>codesg ends<br />end start