Java教程

实验2 多个逻辑段的汇编源程序编写与调试

本文主要是介绍实验2 多个逻辑段的汇编源程序编写与调试,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1.实验任务1

 任务1-1

assume ds:data,cs:code,ss:stack
data segment
    db 16 dup(0)
data ends
stack segment
    db 16 dup(0)
stack ends
code segment
start:
    mov ax,data
    mov ds,ax
    mov ax,stack
    mov ss,ax
    mov sp,16
    mov ah,4ch
    int 21h
code ends
end start

寄存器(DS) = 076a,寄存器(SS) = 076b,寄存器(CS) = 076c

data段的段地址是 X-2,stack的段地址是 X-1

 

 任务1-2

assume ds:data,cs:code,ss:stack
data segment
    db 4 dup(0)
data ends
stack segment
    db 8 dup(0)
stack ends
code segment
start:
    mov ax,data
    mov ds,ax
    mov ax,stack
    mov ss,ax
    mov sp,8
    mov ah,4ch
    int 21h
code ends
end start

寄存器(DS) = 076a,寄存器(SS) = 076b,寄存器(CS) = 076c

data段的段地址是 X-2,stack的段地址是 X-1

 

 任务1-3

assume ds:data, cs:code, ss:stack

data segment
    db 20 dup(0)
data ends

stack segment
    db 20 dup(0)
stack ends
code segment
start:
    mov ax, data
    mov ds, ax

    mov ax, stack
    mov ss, ax
    mov sp, 20

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

寄存器(DS) = 076a,寄存器(SS) = 076c,寄存器(CS) = 076e

data段的段地址是 X-4,stack的段地址是 X-2

 

 任务1-4

assume ds:data, cs:code, ss:stack
code segment
start:
    mov ax, data
    mov ds, ax

    mov ax, stack
    mov ss, ax
    mov sp, 20

    mov ah, 4ch
    int 21h
code ends

data segment
    db 20 dup(0)
data ends

stack segment
    db 20 dup(0)
stack ends
end start

寄存器(DS) = 076c,寄存器(SS) = 076e,寄存器(CS) = 076a

data段的段地址是 X+2,stack的段地址是 X+4

 

 任务1-5

①((N+15)/16)*16

②task1_4.asm可以正确执行。因为如果不指明程序的入口,程序将从我们代码的第一行开始读取。其余task的第一行是我们定义的数据段,不是代码段,因此没有相对应的指令,程序执行时将会发生错误。

 

2.实验任务2

assume cs:code
code segment
start:
    mov ax,0b800h
    mov ds,ax
    mov bx,0f00h
    mov cx,80
s:  mov [bx],0403h
    add bx,2
    loop s
    mov ax,4c00h
    int 21h
code ends
end start

 

3.实验任务3
assume cs:code
data1 segment
    db 50, 48, 50, 50, 0, 48, 49, 0, 48, 49 ; ten numbers
data1 ends

data2 segment
    db 0, 0, 0, 0, 47, 0, 0, 47, 0, 0       ; ten numbers
data2 ends

data3 segment
    db 16 dup(0)
data3 ends

code segment
start:
    mov ax,data1
    mov ds,ax
    mov bx,0
    mov cx,10
s: mov ax,[bx]
    add ax,[bx].16
    mov [bx].32,ax
    inc bx
    loop s
    mov ah,4ch
    int 21h
code ends
end start

 

 

4.实验任务4

assume cs:code

data1 segment
    dw 2, 0, 4, 9, 2, 0, 1, 9
data1 ends 

data2 segment
    dw 8 dup(?)
data2 ends

code segment
start:
    mov ax,data1
    mov ds,ax
    mov bx,0
    mov si,30
    mov cx,8
s: mov ax,[bx]
    mov [si],ax
    sub si,2
    add bx,2
    loop s
    mov ah, 4ch
    int 21h
code ends
end start

 

 

5.实验任务5

assume cs:code, ds:data
data segment
        db 'Nuist'
        db 2, 3, 4, 5, 6
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

 

line19的作用是:

0dfh转换为2进制就是11011111,将其与al进行and操作后,第5位(从0开始)变成0,相当于ascii码减去32,也就是把字母转换为大写字母。

line4的作用是:

用途是设置字符的颜色。

 

6.实验任务6

assume cs:code, ds:data

data segment
    db 'Pink Floyd      '
    db 'JOAN Baez       '
    db 'NEIL Young      '
    db 'Joan Lennon     '
data ends

code segment
start:
   mov ax,data
   mov ds,ax
   mov bx,0
   mov cx,4
s: or byte ptr [bx],32
   add bx,16
   loop s
   mov ah, 4ch
   int 21h
code ends
end start

 

 

7.实验任务7

assume cs:code, ds:data, es:table

data segment
    db '1975', '1976', '1977', '1978', '1979' 
    dw  16, 22, 382, 1356, 2390
    dw  3, 7, 9, 13, 28 
data ends

table segment
    db 5 dup( 16 dup(' ') )  ;
table ends

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

    mov bx,0
    mov bp,0
    mov si,20
    mov cx,5

s:  mov ax,ds:[bx]
    mov es:[bp],ax
    mov ax,ds:[bx+2]
    mov es:[bp+2],ax

    mov ax,ds:[si]
    mov es:[bp+5],ax
    mov word ptr es:[bp+7],0

    mov ax,ds:[si+10]
    mov es:[bp+10],ax

    mov ax,ds:[si]
    mov dl,ds:[si+10]
    div dl
    mov es:[bp+13],al
    mov byte ptr es:[bp+14],0

    add bx,4
    add bp,16
    add si,2

    loop s

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

 

 

这篇关于实验2 多个逻辑段的汇编源程序编写与调试的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!