(1) 代码段中使用数据
编程计算8个数据的和,结果保存在ax中。代码如下:
code segment
assume cs:code
dw 0123H,0456H,0789H,00bcH,00efh,0667h,072fh,0990H
mov bx,0
mov ax,0
mov cx,8
s: add ax,cs:[bx]
add bx,2
loop s
mov ax,4c00h
int 21h
code ends
end
assume cs:code
dw 0123H,0456H,0789H,00bcH,00efh,0667h,072fh,0990H
mov bx,0
mov ax,0
mov cx,8
s: add ax,cs:[bx]
add bx,2
loop s
mov ax,4c00h
int 21h
code ends
end
用debug调试跟踪如下:
Debug跟踪,修改ip指向代码,让程序合法运行:
修改源代码,指明程序入口,使程序合法化:
code segment
assume cs:code
dw 0123H,0456H,0789H,00bcH,00efh,0667h,072fh,0990H
start: mov bx,0
mov ax,0
mov cx,8
s: add ax,cs:[bx]
add bx,2
loop s
mov ax,4c00h
int 21h
code ends
end start
assume cs:code
dw 0123H,0456H,0789H,00bcH,00efh,0667h,072fh,0990H
start: mov bx,0
mov ax,0
mov cx,8
s: add ax,cs:[bx]
add bx,2
loop s
mov ax,4c00h
int 21h
code ends
end start
(2) 代码段中使用栈
利用栈将程序中定义的数据逆序存放:
code segment
assume cs:code
dw 0123H,0456H,0789H,00bcH,00efh,0667h,072fh,0990H
dw 0,0,0,0,0,0,0,0
start: mov ax,cs
mov ss,ax
mov sp,32; 设置栈顶ss:sp指向cs:32
mov bx,0
mov cx,8
s: push cs:[bx]
add bx,2
loop s
mov bx,0
mov cx,8
s0: pop cs:[bx]
add bx,2
loop s0
mov ax,4c00h
int 21h
code ends
end start; 指明程序的入口在start处
assume cs:code
dw 0123H,0456H,0789H,00bcH,00efh,0667h,072fh,0990H
dw 0,0,0,0,0,0,0,0
start: mov ax,cs
mov ss,ax
mov sp,32; 设置栈顶ss:sp指向cs:32
mov bx,0
mov cx,8
s: push cs:[bx]
add bx,2
loop s
mov bx,0
mov cx,8
s0: pop cs:[bx]
add bx,2
loop s0
mov ax,4c00h
int 21h
code ends
end start; 指明程序的入口在start处