ds 数据段放入数据正确;
两次push 操作后,ss栈段正确;
由于pop 操作顺序,ds数据段并没有发生改变;
Source Code:
assume cs:code, ds:data, ss:stackdata segmentdw 0123H,0456H,0789H,0abcH,0defH,0fedH,0cbaH,0987H data endsstack segmentdw 0,0,0,0,0,0,0,0 stack endscode segment start:mov ax,stackmov ss,axmov sp,16mov ax,datamov ds,axpush ds:[0]push ds:[2]pop ds:[2]pop ds:[0]mov ax,4c00Hint 21Hcode ends end start
(2)程序加载后,数据段和栈段加载后,实际占据的空间是以16个字节为单位。程序中只给出了前两个字,其他空间都是补充0;
Source Code:
assume cs:code , ds:data , ss:stackdata segmentdw 0123H,0456H data endsstack segmentdw 0,0 stack endscode segmentstart:mov ax,stackmov ss,axmov sp,16mov ax,datamov ds,axpush ds:[0]push ds:[2]pop ds:[2]pop ds:[0]mov ax,4c00Hint 21H code ends end start
(3)
Source Code:
assume cs:code ,ds:data, ss:stackcode segment start:mov ax,stackmov ss,axmov sp,16mov ax,datamov ds,axpush ds:[0]push ds:[2]pop ds:[2]pop ds:[0]mov ax,4c00Hint 21H code endsdata segmentdw 0123H,0456H data endsstack segmentdw 0,0 stack endsend start
相比之前,三个段的顺序发生改变,数据没有改变,但是三个段的入口地址肯定变了;
具体差别:
代码段标号减小;
(5) a 段 + b 段 的和,放到 c 段;
(栈段也可以用 段地址+偏移地址访问)
Source Code:
assume cs:codea segmentdb 1,2,3,4,5,6,7,8a endsb segmentdb 1,2,3,4,5,6,7,8b endsc segmentdb 0,0,0,0,0,0,0,0c endscode segmentstart:mov ax,amov ds,axmov ax,bmov ss,ax ;栈段mov ax,cmov es,axmov bx,0mov cx,8s:mov al,ds:[bx]add al,ss:[bx] ;栈段也段地址+偏移地址访问mov es:[bx],alinc bxloop smov ax,4c00Hint 21H code ends end start
(6)将a段的前8个字,逆序放到 b 段中;
入栈的方式,即为逆序;
Source Code:
assume cs:codea segmentdw 1,2,3,4,5,6,7,8,9,0aH,0bH,0cH,0dH,0eH,0fH,0ffH a endsb segmentdw 0,0,0,0,0,0,0,0 b endscode segment start:mov ax,amov ds,axmov ax,bmov ss,axmov sp,10Hmov bx,0mov cx,8s:push ds:[bx]add bx,2loop smov ax,4c00Hint 21Hcode ends end start