程序取得所需空间的方法有两种:

  1. 在加载程序的时候为程序分配
  2. 在程序执行的过程中向系统申请

dw定义字型数据

assume cs:code
code segment
	dw 0123h,0456h,0789h,0defh,0fedh,0987h,0654h,0123h ;此时程序的前16个字节被占用,也就是cs:[0],cs:[2],...cs:[e]

	start: mov bx,0        ;指定程序入口位置
	       mov ax,0
				 mov cx,8

		s:   add ax,cs:[bx]
				 add bx,2
				 add bx,2
				 loop s

code ends
end start                ;end还指明了程序入口位置

dw的作用,不仅可以用来初始化字型数据,也可以用来开创内存空间。(一个字型数据=开辟2B)

cs
36或者24H
pop cs:[bx]
assume cs:code, ds:data, ss:stack

data segment
	dw 0123h,0456h,0789h,0abch,0defh,0cbah,0987h
data ends

stack segment
	dw 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0     ;16个字的字型空间
stack ends

code segment
start: mov ax,**stack**
			 mov ss,ax
			 mov sp,20H                        ;20H只到stack的中间

			 mov ax,**data                       ;data是一个数据,不能直接传入ds,要注意**
			 mov ds,ax                         ;ds指向data段
			 mov bx,0
			 mov cx,8
		s: push [bx]
			 add bx,2
			 loop s

			 mov bx,0
			 mov cs,8
		s0:pop cs:[bx]
			 add bx,2
			 loop s0

			 mov ax,4c00h
			 int 21h
		
code ends

end start