题目:用程序实现依次用内存0:0~0:15单元中的内容改写程序中的数据,数据的传说用栈来进行。栈空间设置在程序内。 解答: 源代码: assume cs:codesg codesg segment dw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h dw 0,0,0,0,0,0,0,0,0,0 start: mov ax,cs mov ss,ax mov sp,24h;这里的关键是24h从哪里得来的?由代码的开始我们可以得知,开始程序定义了18个字,所占用的内存空间为0~23h,栈顶值为23h。而栈一开始是空的,所以sp的值要加1。所以就是24h了。 mov ax,0 mov ds,ax;这里设置数据段是0000h mov bx,0 mov cx,8 s: push [bx] pop cs:[bx];把ds:[bx]的数据送到栈中,又马上出栈到 ;cs:[bx]处,完全符合题意。 add bx,2 loop s mov ax,4c00h int 21h codesg ends end start 调试过程: -r AX=0000 BX=0000 CX=0045 DX=0000 SP=0000 BP=0000 SI=0000 DI=0000 DS=143C ES=143C SS=144C CS=144C IP=0024 NV UP EI PL NZ NA PO NC 144C:0024 8CC8 MOV AX,CS -u 144C:0024 8CC8 MOV AX,CS 144C:0026 8ED0 MOV SS,AX 144C:0028 BC2400 MOV SP,0024 144C:002B B80000 MOV AX,0000 144C:002E 8ED8 MOV DS,AX 144C:0030 BB0000 MOV BX,0000 144C:0033 B90800 MOV CX,0008 144C:0036 FF37 PUSH [BX] 144C:0038 2E CS: 144C:0039 8F07 POP [BX] 144C:003B 83C302 ADD BX,+02 144C:003E E2F6 LOOP 0036 144C:0040 B8004C MOV AX,4C00 144C:0043 CD21 INT 21 -d cs:0 144C:0000 23 01 56 04 89 07 BC 0A-EF 0D ED 0F BA 0C 87 09 #.V............. 144C:0010 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 ................ 144C:0020 00 00 00 00 8C C8 8E D0-BC 24 00 B8 00 00 8E D8 .........$...... 144C:0030 BB 00 00 B9 08 00 FF 37-2E 8F 07 83 C3 02 E2 F6 .......7........ 144C:0040 B8 00 4C CD 21 74 FF 50-E8 E7 6D 83 C4 06 C4 5E ..L.!t.P..m....^ 144C:0050 F8 26 8B 47 06 26 8B 57-08 89 46 FC 89 56 FE C4 .&.G.&.W..F..V.. 144C:0060 5E FC 26 80 7F 04 00 75-03 E9 84 00 26 8B 07 26 ^.&....u....&..& 144C:0070 8B 57 02 89 46 F4 89 56-F6 8A 46 08 26 38 47 04 .W..F..V..F.&8G. -d 0:0 f 0000:0000 68 10 A7 00 8B 01 70 00-16 00 AD 03 8B 01 70 00 h.....p.......p. -r AX=0000 BX=0000 CX=0045 DX=0000 SP=0000 BP=0000 SI=0000 DI=0000 DS=143C ES=143C SS=144C CS=144C IP=0024 NV UP EI PL NZ NA PO NC 144C:0024 8CC8 MOV AX,CS -t AX=144C BX=0000 CX=0045 DX=0000 SP=0000 BP=0000 SI=0000 DI=0000 DS=143C ES=143C SS=144C CS=144C IP=0026 NV UP EI PL NZ NA PO NC 144C:0026 8ED0 MOV SS,AX -t AX=144C BX=0000 CX=0045 DX=0000 SP=0024 BP=0000 SI=0000 DI=0000 DS=143C ES=143C SS=144C CS=144C IP=002B NV UP EI PL NZ NA PO NC 144C:002B B80000 MOV AX,0000 -t AX=0000 BX=0000 CX=0045 DX=0000 SP=0024 BP=0000 SI=0000 DI=0000 DS=143C ES=143C SS=144C CS=144C IP=002E NV UP EI PL NZ NA PO NC 144C:002E 8ED8 MOV DS,AX -t AX=0000 BX=0000 CX=0045 DX=0000 SP=0024 BP=0000 SI=0000 DI=0000 DS=0000 ES=143C SS=144C CS=144C IP=0030 NV UP EI PL NZ NA PO NC 144C:0030 BB0000 MOV BX,0000 -t AX=0000 BX=0000 CX=0045 DX=0000 SP=0024 BP=0000 SI=0000 DI=0000 DS=0000 ES=143C SS=144C CS=144C IP=0033 NV UP EI PL NZ NA PO NC 144C:0033 B90800 MOV CX,0008 -t AX=0000 BX=0000 CX=0008 DX=0000 SP=0024 BP=0000 SI=0000 DI=0000 DS=0000 ES=143C SS=144C CS=144C IP=0036 NV UP EI PL NZ NA PO NC 144C:0036 FF37 PUSH [BX] DS:0000=1068 -t AX=0000 BX=0000 CX=0008 DX=0000 SP=0022 BP=0000 SI=0000 DI=0000 DS=0000 ES=143C SS=144C CS=144C IP=0038 NV UP EI PL NZ NA PO NC 144C:0038 2E CS: 144C:0039 8F07 POP [BX] CS:0000=0123 -d cs:0 144C:0000 23 01 56 04 89 07 BC 0A-EF 0D ED 0F BA 0C 87 09 #.V............. 144C:0010 00 00 00 00 00 00 00 00-00 00 00 00 38 00 4C 14 ............8.L. 144C:0020 30 0E 68 10 8C C8 8E D0-BC 24 00 B8 00 00 8E D8 0.h......$...... 144C:0030 BB 00 00 B9 08 00 FF 37-2E 8F 07 83 C3 02 E2 F6 .......7........ 144C:0040 B8 00 4C CD 21 74 FF 50-E8 E7 6D 83 C4 06 C4 5E ..L.!t.P..m....^ 144C:0050 F8 26 8B 47 06 26 8B 57-08 89 46 FC 89 56 FE C4 .&.G.&.W..F..V.. 144C:0060 5E FC 26 80 7F 04 00 75-03 E9 84 00 26 8B 07 26 ^.&....u....&..& 144C:0070 8B 57 02 89 46 F4 89 56-F6 8A 46 08 26 38 47 04 .W..F..V..F.&8G. -r AX=0000 BX=0000 CX=0008 DX=0000 SP=0022 BP=0000 SI=0000 DI=0000 DS=0000 ES=143C SS=144C CS=144C IP=0038 NV UP EI PL NZ NA PO NC 144C:0038 2E CS: 144C:0039 8F07 POP [BX] CS:0000=0123 -p AX=0000 BX=0000 CX=0008 DX=0000 SP=0024 BP=0000 SI=0000 DI=0000 DS=0000 ES=143C SS=144C CS=144C IP=003B NV UP EI PL NZ NA PO NC 144C:003B 83C302 ADD BX,+02 -p AX=0000 BX=0002 CX=0008 DX=0000 SP=0024 BP=0000 SI=0000 DI=0000 DS=0000 ES=143C SS=144C CS=144C IP=003E NV UP EI PL NZ NA PO NC 144C:003E E2F6 LOOP 0036 -p AX=0000 BX=0010 CX=0000 DX=0000 SP=0024 BP=0000 SI=0000 DI=0000 DS=0000 ES=143C SS=144C CS=144C IP=0040 NV UP EI PL NZ AC PO NC 144C:0040 B8004C MOV AX,4C00 -d cs:0 144C:0000 68 10 A7 00 BB 13 30 0E-16 00 AD 03 B1 13 30 0E h.....0.......0. 144C:0010 00 00 00 00 00 00 00 00-00 00 00 00 00 00 40 00 ..............@. 144C:0020 4C 14 30 0E 8C C8 8E D0-BC 24 00 B8 00 00 8E D8 L.0......$...... 144C:0030 BB 00 00 B9 08 00 FF 37-2E 8F 07 83 C3 02 E2 F6 .......7........ 144C:0040 B8 00 4C CD 21 74 FF 50-E8 E7 6D 83 C4 06 C4 5E ..L.!t.P..m....^ 144C:0050 F8 26 8B 47 06 26 8B 57-08 89 46 FC 89 56 FE C4 .&.G.&.W..F..V.. 144C:0060 5E FC 26 80 7F 04 00 75-03 E9 84 00 26 8B 07 26 ^.&....u....&..& 144C:0070 8B 57 02 89 46 F4 89 56-F6 8A 46 08 26 38 47 04 .W..F..V..F.&8G. -p AX=4C00 BX=0010 CX=0000 DX=0000 SP=0024 BP=0000 SI=0000 DI=0000 DS=0000 ES=143C SS=144C CS=144C IP=0043 NV UP EI PL NZ AC PO NC 144C:0043 CD21 INT 21 -p Program terminated normally -q