汇编语言第六章习题

6.3

assume cs:codesg
codesg segment
	dw 0123h,0456h,0789h,0abch,0defh,0fedh,0cbah,0987h   ;分配内存空间
	dw 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	
start: mov ax,cs		指明程序入口
	mov ss,ax
	mov sp,30h		;设置栈顶ss:sp,栈顶指向10~2F的后一位即30h
	
	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
	
codesg ends
end start

检测点6.1

(1)

assume cs:codesg 
codesg segment 
dw 0123h,0456h,0789h,0abch,0defh,Ofedh,0cbah,0987h 
start:
	mov ax,0
	mov ds,ax 
	mov bx,0
	mov cx,8
s:
	mov ax,[bx]
	mov cs:[bx],ax
	add bx,2
	loop s
	
	
	mov ax,4c00h
	int 21h 
	
codesg ends 
end start

(2)

mov ax,cs	;程序入口
mov sp,26	
pop cs:[bx]

实验5

(1)

这个得自己看,答案可能不一样
①先-t运行到mov ax,data查看段地址
在这里插入图片描述
然后-d查看即可
在这里插入图片描述

在这里插入图片描述
cs=0042、ss=076B、ds=076A

③ 设程序加载后,code段的段地址为X,则data段的段地址为X-2,stack段的段地址X-1。

(2)

前3问略

如果段中的数据占N个字节,则程序加载后该段实际占有的空间为 N除以16向下取整(即如果N为17则取1)*16 + 16, 即 ([N/16] + 1)*16。

因为每一个段占据1*16字节,所以就是这个结果。

(3)

前2问略
<3>设程序加载后,code段的段地址为X,则data段的段地址为__X+3__,stack段的段地址为__X+4__。

(4)

第三个程序能够正确的运行,因为当不指明程序的入口时,cs:code segment的默认ip为0,第三个程序在ip为0时正好对应程序的开始的地方,前面的两个ip对应的是存数据的地方故会错。

(5)

start:  mov ax, a
        mov ds, ax
        mov bx, 0
        mov cx, 8
s:      mov [bx+32], [bx]
        add [bx+32],[bx+16]
        add bx, 1
        loop s

(6)

start:  mov ax, a
        mov ds, ax
 
        mov ax, b
        mov ss, ax
        mov sp, 10h
         
        mov bx, 0
        mov cx, 8
s:      push ds:[bx]
        add bx, 2
        loop s
 
        mov ax, 4c00h
        int 21h
发布了165 篇原创文章 · 获赞 24 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/treblez/article/details/105503613