实验3 多个段的汇编源程序编写与调试

实验任务1

源代码:

assume cs:code, ds:data
data segment
        db 'Nuist'
        db 5 dup(2)
data ends

code segment
start:
        mov ax, data
        mov ds, ax

        mov ax, 0b800H
        mov es, ax

        mov cx, 5
        mov si, 0
        mov di, 0f00h
s:      mov al, [si]
        and al, 0dfh
        mov es:[di], al
        mov al, [5+si]
        mov es:[di+1], al
        inc si
        add di, 2
        loop s

        mov ah, 4ch
        int 21h
code ends
end start

运行结果截图:

 

 在debug里调试到程序返回前的截图:

 

 修改数据后截图:

 猜测这里的数值的作用是更改字符的颜色。

实验任务2

源代码:

assume cs:code, ds:data
data segment
    db 23,50,66,71,35
data ends

code segment
start:
    mov ax,data
    mov ds,ax

    mov cx,5
    mov si,0

s:    mov bl,10
    mov al,ds:[si]
    mov ah,0
    div bl

    add al,30h
    add ah,30h
    mov ds:[si+5],al
    mov ds:[si+6],ah

    mov ah, 2
    mov dl,ds:[si+5]
    int 21h

    mov ah, 2
    mov dl,ds:[si+6]
    int 21h

    mov ah, 2
    mov dl, 32
    int 21h
    inc si
    loop s

    mov ah,4ch
    int 21h
code ends
end start

运行结果:

实验任务3

 源代码:

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

1)

  返回程序前data中数据:

  0123h 0456h 0789h 0ABCh 0DEFh 0FEDh 0CBAh 0987h

 

 2)

  cs=076Ch、ss=076Bh、ds=076A

 

反汇编:

 3)

data段地址为X-2、stack段地址为X-1

实验任务4

源代码:

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

 1)

  0123h、0456h

2)

  cs:076Ch  ss=076Bh   ds=076Ah

 

 

 

3)

  data段地址为X-2    stack段地址为X-1

 4)

  会占有最接近且不超过16的倍数个字节。

实验任务5

源代码:

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

1)

  0123h、0456h

2)

  cs:076Ah  ss=076Eh  ds=076Dh

 

 

3)

  data段地址为X+3    stack段地址为X+4

实验任务6

  第三个可以正常执行。因为如果不指明程序的入口,将会从第一条指令顺序向后执行,前两个都会将data段和stack段中的数据当作指令来执行,而第三个的data段和stack段位于指令代码段的后面不影响程序的正常运行。

实验任务7

源代码:

assume cs:code
a segment
  db 1,2,3,4,5,6,7,8
a ends

b segment
  db 1,2,3,4,5,6,7,8
b ends

c1 segment   
  db 8 dup(0)
c1 ends

code segment
start:
           mov ax,a
    mov ds,ax
    mov ax,b
    mov es,ax
    mov ax,c1
    mov ss,ax

    mov cx,8
    mov si,0

s:    mov ax,ds:[si]
    mov ss:[si],ax
    mov ax,es:[si]
    add ss:[si],ax
    inc si
    loop s
    
    mov ax,4c00h
    int 21h
code ends
end start

 

 

 

 实验任务8

源代码:

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 8 dup(0)
b ends

code segment
start: 
           mov ax,a
    mov ds,ax
    mov ax,b
    mov ss,ax
    mov sp,16
    mov si,0
    mov cx,8

s:    push ds:[si]
    add si,2
    loop s

    mov ax,4c00h
    int 21h
code ends
end start

 

 

 

 

 

 实验总结

1.通过本次实验我掌握了大小写字符的转换方法、数字字符和数值之间的转换方法,同时也学到了利用系统功能调用int 21h中的2号子功能输出单个字符。

2.掌握了含有多个数据段和指令段的空间分配和准确寻址问题。

3.学会了对不同段进行数值操作,主要是利用寄存器和利用栈。

4.掌握了每个段的空间实际占用问题。

5.认识到了指明程序入口的重要性。

posted @ 2020-11-26 16:56  有女孩说要娶我  阅读(120)  评论(2)    收藏  举报