Experiment 2 Writing and Debugging Assembly Source Programs for Multiple Logical Segments

1. Experimental Purpose
1. Understand and master the assembly source program for more than 8086 logical segments
2. Understand and apply flexible addressing
3. Understand the nature of loops in programming languages through the use of assembly instruction loops and understand their correct use in nested loops
4. Master debugging 8086 assembler using debug
2. Preparing for Experiment
Review textbook chapters 5-8:
Assembly source structure with multiple logical segments
Addressing method
Assembly directive loop, div usage
3. Experimental Contents
1. Experimental Task 1
- Tasks 1-1

DS=076A;SS=076B;CS=076C;data=x-2;stack=x-1; (16 bytes per segment)

DS=076A;SS=076B;CS=076C;data=x-2;stack=x-1; (16 bytes per segment)

 

- Tasks 1-3

DS=076A;SS=076B;CS=076C;data=x-4;stack=x-2; (32 bytes per segment)

 

- Tasks 1-4

DS=076C;SS=076E;CS=076A;data=x+2;stack=x+4;(ds-076c,ss-076e)

 

- Tasks 1-5

Question 1: The actual allocated space is 16* (N/16 rounded up), which is always a multiple of 16.

Question 2: task1-4 works because start indicates where the code snippet begins and executes automatically from the beginning when start is removed after end. Only 1-4 instructions start at the beginning of the program, while others start with data segments and are incorrectly recognized as instructions and cannot be executed.

 

2. Experimental Task 2

Write an assembly source program to fill hexadecimal data 03 04 in succession to memory unit b800:0f00 ~ b800:0f9f for 160 bytes
assume cs:code
code segment
start:
    mov ax,0b800h
    mov ds,ax
    
    mov bx,0f00h
    mov cx,50h
    mov ax,0403h
s:    mov ds:[bx],ax
    add bx,2
    loop s

    mov ah,4ch
    int 21h

code ends
end start

Run result:

 

 

  3. Experimental Task 3

The programming implementation adds the data of logical segment data1 and logical segment data2 in turn and saves the result to logical segment data3.
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+10h]
    mov [bx+20h],ax
    inc bx
    loop s

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

Run result:

 

 

 

 data1-0000; data2-0010; data3-0020;

4. Experimental Task 4

assume cs:code

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

data2 segment
    dw 8 dup(0)
data2 ends

code segment
start:
    mov ax,data1  ;data1 Is a data segment
    mov ds,ax
    mov ax,data2  ;data2 Is a stack segment, length and data1 identical
    mov ss,ax
    mov sp,10h
    
    mov bx,0
    mov cx,8
s0: push ds:[bx]  ;After all stacking, the top of the stack is data2 At the beginning of the paragraph, data2 Just as data1 Storage in reverse order
    add bx,2
    loop s0


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

Run result:

 

5. Experimental Task 5

Code Analysis:

assume cs:code, ds:data
data segment
        db 'Nuist'
        db 1, 2, 3, 4, 5
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]  ;al Assignment one by one data One letter in the first line
        and al, 0dfh  ;0dfh=0000 1101 1111,The phase operation lowercase letters ASCII Value minus 32 changes to uppercase
        mov es:[di], al
        mov al, [5+si]  ;al assignment data Second line number
        mov es:[di+1], al  ;Insert after letter
        inc si
        add di, 2
        loop s

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

Run result:

 

  Question 3:line19 Role:

0dfh=0000 1101 1111, phase operation changes lowercase ASCII value from 32 to uppercase

  Question 4: Modify the value of 5 byte units in line4, reassemble, link, run, and observe the result.

Run result: db   5 dup(2)

db 5 dup(5)

 

 

 

  Conclusion: Change the color of the preceding letters;

 

6. Experimental Task 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 es,ax

    mov di,0
    mov cx,4
s0:    mov bx,cx  ;Nested Loop, Outer Loop cx Value is saved in bx in

    mov si,di
    mov cx,4  ;Inner loop operates on the first four letters without a line
s1:    mov al,es:[si]
    or al,20h  ;Or operation 20 h=0010 0000 Uppercase letters ASCII Code value plus 32 lowercase
    mov es:[si],al
    inc si
    loop s1

    add di,10h
    mov cx,bx  ;End of inner cycle, cx Count of assignment loops
    loop s0
    
    mov ah, 4ch
    int 21h
code ends
end start

Run result:

 

 

 

7. Experimental Task 7

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

data segment
    db '1975', '1976', '1977', '1978', '1979'
    dd  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 cx,5
    mov bx,0
    mov si,0
s0:    mov ax,[bx]  ;s0 Incoming Year
    mov es:[si+0],ax
    mov ax,[bx+2]
    mov es:[si+2],ax
    add bx,4
    add si,10h
    loop s0

    mov cx,5
    mov bx,14h
    mov si,0
s1:    mov ax,[bx]  ;s1 Incoming revenue
    mov es:[si+5],ax
    mov ax,[bx+2]
    mov es:[si+7],ax
    add bx,4
    add si,10h
    loop s1

    mov cx,5
    mov bx,28h
    mov si,0
s2:    mov ax,[bx]  ;Incoming Employees
    mov es:[si+10],ax
    add bx,2
    add si,10h
    loop s2

    mov cx,5
    mov si,0
s3:    mov ax,es:[si+5]  ;Calculate per capita income, 32 low ax
    mov dx,es:[si+7]  ;32 High Income dx
    mov bx,es:[si+10]  ;Employee
    div bx
    mov es:[si+13],ax  ;Shopping place ax in
    add si,10h
    loop s3

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

Run result:

Code:

 

  Results:

Prior to implementation:

40~80 as spaces

  After implementation:

 

 

  The top four columns of 40-80 are year, 6-9 are income, 11,12 are employees, and 14,15 are average income.

Result table:

  1-4 years 6~9 Income 11,12 Employees 14,15 Average Income
40 1975 0010h 03 05
50 1976 0016h 07 03
60 1977 017eh 09 2a
70 1978 054ch 0d 68
80 1979 0956h 1c 55

 

 

 

 

 

 

 

IV. EXPERIMENTAL SUMMARY

Through this experiment, I learned the role of pseudo-instruction start; Memory allocation for multi-segment programs; Change the color of a character by using the number preceding the character; Use the AND or operation to change the case of characters; The use of the div directive;

Posted on Fri, 05 Nov 2021 12:59:17 -0400 by adam291086