包含多个段的程序
在代码段中使用数据
问题:编程计算以下8个数据的和,结果存在ax寄存器中:
0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h
assume cs:code
code segment
dw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h
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
dw
:即“define word”,定义字型数据
因为dw定义的数据处于代码段的最开始,所以偏移地址为0,用bx加2得到下个数据的偏移地址
用标号如start可以在源程序中指明程序的入口所在,即编译,连接后直接运行的部分
end
:除了通知编译器程序结束,还可以通知编译器程序的入口所在,如上程序中,mov bx,0
为第一条指令
程序框架的安排
assume cs:code
code segment
数据
start: 代码
code ends
end start
在代码段中使用栈
问题:利用栈将程序中定义的数据逆序存放
assume cs:code
code segment
dw 012