实验五
1
assume cs:code,ds:data,ss:stack data segment dw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h data ends stack segment dw 0,0,0,0,0,0,0,0 stack ends code segment start: mov ax,stack mov ss,ax mov sp,16 mov ax,data mov ds,ax push ds:[0] push ds:[2] pop ds:[2] pop ds:[0] mov ax,4c00h int 21h code ends end start
CPU执行任务,程序返回前,data段中的数据为多少?
CPU执行任务后,程序返回前,cs=076C,ss=076B,ds=076A.
程序加载后,code段的段地址为X,则data段的段地址为X-2,stack段的段地址为X-1
2
代码:
assume cs:code,ds:data,ss:stack data segment dw 0123H,0456H data ends stack segment dw 0,0 stack ends code segment start: mov ax,stack mov ss,ax mov sp,16 mov ax,data mov ds,ax push ds:[0] push ds:[2] pop ds:[2] pop ds:[0] mov ax,4c00h int 21h code ends end start
CPU执行程序,程序返回前,data段中的数据为多少?
data段的数据如上图
程序反悔前,cs=076C,ss=076B,ds=076A
code=x则data=x-2,stack=x-1
对于如下定义的段:
name segment
...
name ends
若数据占N个字节,则程序加载后,该段实际占有的空间为:
每个段固定16个字节,若超过16个字节,则另外再分配整数倍的段,直至全部存放下
(3)
assume cs:code,ds:data,ss:stack code segment start: mov ax,stack mov ss,ax mov sp,16 mov ax,data mov ds,ax push ds:[0] push ds:[2] pop ds:[2] pop ds:[0] mov ax,4c00h int 21h code ends data segment dw 0123H,0456H data ends stack segment dw 0,0 stack ends end start
cs=076A,ss=076E,ds=076D
若code段地址为X,则data段地址为:X+3,stack段地址为:X+4
(4)没有程序入口时则ip默认为0,只有第三个程序,因为它是从代码断开始的,所以可以正确执行,别的都不是从代码断开始,所以不能
(5)
assume cs:code a segment dw 1,2,3,4,5,6,7,8,9,0ah,0bh,0ch,0dh,0eh,0fh,0ffh a ends b segment dw 0,0,0,0,0,0,0,0 b ends code segment start: mov ax,al mov ds,ax mov cx,8 mov bx,0 mov ax,bl mov ss,ax mov sp,10h s:push [bx] add bx,2 loop s mov ax,4c00h int 21h code ends
(6)
assume cs:code a segment dw 1,2,3,4,5,6,7,8,9,0ah,0bh,0ch,0dh,0eh,0fh,0ffh a ends b segment dw 0,0,0,0,0,0,0,0 b ends code segment start: mov ax,al mov ds,ax mov cx,8 mov bx,0 mov ax,bl mov ss,ax mov sp,10h s:push [bx] add bx,2 loop s mov ax,4c00h int 21h code ends
实验与总结:有一个细节就是如果没有入口的话那ip默认为0,写程序的时候要细心一些,多写几次