|
发表于 2011-12-26 10:57:39
|
显示全部楼层
实验4 [bx]和loop的使用
(3)下面的程序功能是将“mov ax,4c00h"之前的指令复制到内存0:200处,补全程序。上机调试,跟踪运行结果。
assume cs:code
code segment
mov ax, code ;或mov ax, cs
mov ds,ax
mov ax,0020h
mov es,ax
mov bx,0
mov cx, 18h ;或mov cx, 17h ;或sub cx,5
s: mov al,[bx]
mov es:[bx],al
inc bx
loop s
mov ax,4c00h
int 21h
code ends
end
此题有多个答案,因为mov用在寄存器之间传送数据的指令是2个字节,用在寄存器和立即数之间是3个字节
答案1:mov ax,cs (占2个字节)
mov cx,17
答案2:mov ax,code (占3个字节)
mov cx,18
答案3:mov ax,cs 或mov ax,code
把mov cx, 改成 sub cx,5
(因为在载入程序时,cx保存程序的长度,减去5是为减去mov ax,4c00h和int 21h的长度)
此题的目的是:
1、理解CS和CODE的关联
2、理解CS保存程序的代码段,即“复制的是什么,从哪里到哪里”
3、理解CX在载入程序后保存程序的长度。
4、理解数据和代码对CPU来说是没区别的,只要CS:IP指向的就是代码
C:\DOCUME~1\ADMINI~1>debug sy4-3.exe
-u
0C79:0000 B8790C MOV AX,0C79
0C79:0003 8ED8 MOV DS,AX
0C79:0005 B82000 MOV AX,0020
0C79:0008 8EC0 MOV ES,AX
0C79:000A BB0000 MOV BX,0000
0C79:000D B91800 MOV CX,0018
0C79:0010 8A07 MOV AL,[BX]
0C79:0012 26 ES:
0C79:0013 8807 MOV [BX],AL
0C79:0015 43 INC BX
0C79:0016 E2F8 LOOP 0010
0C79:0018 B8004C MOV AX,4C00
0C79:001B CD21 INT 21
0C79:001D 50 PUSH AX
0C79:001E 8D4680 LEA AX,[BP-80]
-g
Program terminated normally
-d 0:200
0000:0200 B8 79 0C 8E D8 B8 20 00-8E C0 BB 00 00 B9 18 00 .y.... .........
0000:0210 8A 07 26 88 07 43 E2 F8-00 00 00 00 00 00 00 00 ..&..C..........
0000:0220 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
0000:0230 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
0000:0240 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
0000:0250 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
0000:0260 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
0000:0270 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
-u 0:200
0000:0200 B8790C MOV AX,0C79
0000:0203 8ED8 MOV DS,AX
0000:0205 B82000 MOV AX,0020
0000:0208 8EC0 MOV ES,AX
0000:020A BB0000 MOV BX,0000
0000:020D B91800 MOV CX,0018
0000:0210 8A07 MOV AL,[BX]
0000:0212 26 ES:
0000:0213 8807 MOV [BX],AL
0000:0215 43 INC BX
0000:0216 E2F8 LOOP 0210
0000:0218 0000 ADD [BX+SI],AL
0000:021A 0000 ADD [BX+SI],AL
0000:021C 0000 ADD [BX+SI],AL
0000:021E 0000 ADD [BX+SI],AL
-q
|
|