|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
实验4 [bx]和loop的使用
(1) 编程,向内存0:200~0:23f依次传递数据0~63(3fh)。
这是个比较另类的做法,传统做法请参考实验4(2)
assume cs:code
code segment
mov bx,20h
mov ss,bx
mov sp,40h
mov bx,3f3eh
mov cx,32
s: push bx
sub bx,202h
loop s
mov ax,4c00h
int 21h
code ends
end
C:DOCUME~1ADMINI~1>debug sy4-2.exe
-d 0:200 23f
0000:0200 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
0000:0210 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
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 ................
-u
0C79:0000 BB2000 MOV BX,0020
0C79:0003 8ED3 MOV SS,BX
0C79:0005 BC4000 MOV SP,0040
0C79:0008 BB3E3F MOV BX,3F3E
0C79:000B B92000 MOV CX,0020
0C79:000E 53 PUSH BX
0C79:000F 81EB0202 SUB BX,0202
0C79:0013 E2F9 LOOP 000E
0C79:0015 B8004C MOV AX,4C00
0C79:0018 CD21 INT 21
0C79:001A 8600 XCHG AL,[BX+SI]
0C79:001C FF508D CALL [BX+SI-73]
0C79:001F 46 INC SI
-g 0015
AX=0000 BX=FEFE CX=0000 DX=0000 SP=0000 BP=0000 SI=0000 DI=0000
DS=0C69 ES=0C69 SS=0020 CS=0C79 IP=0015 NV UP EI NG NZ AC PO CY
0C79:0015 B8004C MOV AX,4C00
-d 0:200 23f
0000:0200 00 01 02 03 04 05 06 07-08 09 0A 0B 0C 0D 0E 0F ................
0000:0210 10 11 12 13 14 15 16 17-18 19 1A 1B 1C 1D 1E 1F ................
0000:0220 20 21 22 23 24 25 26 27-28 29 2A 2B 2C 2D 2E 2F !"#$%&'()*+,-./
0000:0230 30 31 32 33 34 35 36 37-38 39 3A 3B 3C 3D 3E 3F 0123456789:;<=>?
-t
AX=4C00 BX=FEFE CX=0000 DX=0000 SP=0000 BP=0000 SI=0000 DI=0000
DS=0C69 ES=0C69 SS=0020 CS=0C79 IP=0018 NV UP EI NG NZ AC PO CY
0C79:0018 CD21 INT 21
-p
Program terminated normally
-q
C:DOCUME~1ADMINI~1>
实验4 [bx]和loop的使用
(2)编程,向内存0:200~0:23f依次传递数据0~63(3fh),程序中只能使用9条指令,9条指中包括“mov ax,4c00h”和“int 21h”。
assume cs:code
code segment
mov ax,20h
mov ds,ax
mov bx,0
mov cx,40h ;或mov cx,64
s: mov [bx],bl
inc bx
loop s
mov ax,4c00h
int 21h
code ends
end
C:DOCUME~1ADMINI~1>debug sy4-1.exe
-d 0:200 23f
0000:0200 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
0000:0210 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................
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 ................
-u
0C79:0000 B82000 MOV AX,0020
0C79:0003 8ED8 MOV DS,AX
0C79:0005 BB0000 MOV BX,0000
0C79:0008 B94000 MOV CX,0040
0C79:000B 881F MOV [BX],BL
0C79:000D 43 INC BX
0C79:000E E2FB LOOP 000B
0C79:0010 B8004C MOV AX,4C00
0C79:0013 CD21 INT 21
0C79:0015 CC INT 3
0C79:0016 FFFF ??? DI
0C79:0018 50 PUSH AX
0C79:0019 8D8600FF LEA AX,[BP+FF00]
0C79:001D 50 PUSH AX
0C79:001E 8D4680 LEA AX,[BP-80]
-g 0010
AX=0020 BX=0040 CX=0000 DX=0000 SP=0000 BP=0000 SI=0000 DI=0000
DS=0020 ES=0C69 SS=0C79 CS=0C79 IP=0010 NV UP EI PL NZ AC PO NC
0C79:0010 B8004C MOV AX,4C00
-d 0:200 23f
0000:0200 00 01 02 03 04 05 06 07-08 09 0A 0B 0C 0D 0E 0F ................
0000:0210 10 11 12 13 14 15 16 17-18 19 1A 1B 1C 1D 1E 1F ................
0000:0220 20 21 22 23 24 25 26 27-28 29 2A 2B 2C 2D 2E 2F !"#$%&'()*+,-./
0000:0230 30 31 32 33 34 35 36 37-38 39 3A 3B 3C 3D 3E 3F 0123456789:;<=>?
-t
AX=4C00 BX=0040 CX=0000 DX=0000 SP=0000 BP=0000 SI=0000 DI=0000
DS=0020 ES=0C69 SS=0C79 CS=0C79 IP=0013 NV UP EI PL NZ AC PO NC
0C79:0013 CD21 INT 21
-p
Program terminated normally
-q
实验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~1ADMINI~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
|
|