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
 

 

 

Register DS=076A; SS=076B; CS=076C;

Code's address segment is X, Data's address segment is X-32; The address segment of the stack is X-16

 

Tasks 1-2

 

Register DS=076A; SS=076B; CS=076C;

Code's address segment is X, Data's address segment is X-12; The address segment of the stack is X-8

 

Tasks 1-3

 

 

Register DS=076A; SS=076C; CS=076E;

Code's address segment is X, Data's address segment is X-40; The address segment of the stack is X-20

 

Tasks 1-4

 

 

Register DS=076C; SS=076E; CS=076A;

Code's address segment is X, Data's address segment is X+20; The address segment of the stack is X+40

 

 

 

Tasks 1-5

1:16*(N/16 rounded up)

2:task1-4 works because start indicates the starting position of the code snippet and executes automatically from the beginning of the program after the end is removed. 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.

 

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

 1 assume cs:code
 2 
 3 code segment
 4 
 5 start:
 6     mov ax, 0b800h
 7     mov ds, ax
 8     mov bx, 0f00h
 9 
10     mov cx, 50h
11     mov ax, 0403h
12 s:    mov ds:[bx], ax
13     add bx, 2
14     loop s
15 
16     mov ah, 4ch
17     int 21h
18 code ends
19 end start

 

 

 

 

 

 

  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.
 1 assume cs:code
 2 data1 segment
 3     db 50, 48, 50, 50, 0, 48, 49, 0, 48, 49 ; ten numbers
 4 data1 ends
 5 
 6 data2 segment
 7     db 0, 0, 0, 0, 47, 0, 0, 47, 0, 0       ; ten numbers
 8 data2 ends
 9 
10 data3 segment
11     db 16 dup(0)
12 data3 ends
13 
14 code segment
15 start:
16        mov ax, data1
17     mov ds, ax
18     mov bx, 0
19     mov cx, 0ah
20 s:    mov ax, ds:[bx]
21     add ax, ds:[bx+10h]
22     mov ds:[bx+20h], ax
23     inc bx
24     loop s
25 
26     mov ah, 4ch
27     int 21h
28 code ends
29 end start

 

 

 

4. Experimental Task 4

 

 

 1 assume cs:code, ss:stack
 2 
 3 data1 segment
 4     dw 2, 0, 4, 9, 2, 0, 1, 9
 5 data1 ends 
 6 
 7 data2 segment
 8     dw 8 dup(0)
 9 data2 ends
10 
11 stack segment
12     dw 8 dup(0)
13 stack ends
14 
15 code segment
16 start:
17     mov ax, data1
18     mov ds, ax
19     mov sp, 9
20     mov bx, 0
21     mov cx, 8
22 s1:    push ds:[bx]
23     add bx, 2
24     loop s1
25 
26     mov ax, data2
27     mov ds, ax
28     mov bx, 0
29     mov cx, 8
30 s2:    pop ds:[bx]
31     add bx, 2
32     loop s2
33     mov ah, 4ch
34     int 21h
35 code ends
36 end start

 

 

 

 

Experiment Task 5

 

 

 1 assume cs:code, ds:data
 2 data segment
 3         db 'Nuist'
 4         db 5 dup(2)
 5 data ends
 6 
 7 code segment
 8 start:
 9         mov ax, data
10         mov ds, ax
11 
12         mov ax, 0b800H
13         mov es, ax
14 
15         mov cx, 5
16         mov si, 0
17         mov di, 0f00h
18 s:      mov al, [si]
19         and al, 0dfh
20         mov es:[di], al
21         mov al, [5+si]
22         mov es:[di+1], al
23         inc si
24         add di, 2
25         loop s
26 
27         mov ah, 4ch
28         int 21h
29 code ends
30 end start

 

 

 

 

  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)

 

 

 

 

 

  Experiment Task 6

 1 assume cs:code, ds:data
 2 
 3 data segment
 4     db 'Pink Floyd      '
 5     db 'JOAN Baez       '
 6     db 'NEIL Young      '
 7     db 'Joan Lennon     '
 8 data ends
 9 
10 code segment
11 start:
12     mov ax, data
13     mov ds, ax
14 
15     mov ax, data
16     mov es, ax
17 
18     mov bx, 0
19     mov cx, 4
20 s1:    mov si, cx
21     mov cx, 4
22 s2:    mov al, es:[bx]
23     or al, 20h
24     mov es:[bx], al
25     inc bx
26     loop s2
27 
28     mov cx, si
29     mov bx, 0
30 
31     mov ax, es
32     inc ax
33     mov es, ax
34 
35     loop s1
36    mov ah, 4ch
37    int 21h
38 code ends
39 end start

 

 

 

 1 assume cs:code, ds:data, es:table
 2 
 3 data segment
 4     db '1975', '1976', '1977', '1978', '1979'   
 5     dd  16, 22, 382, 1356, 2390                 
 6     dw  3, 7, 9, 13, 28                     
 7 data ends
 8 
 9 table segment
10     db 5 dup( 16 dup(' ') )     
11 table ends
12 
13 code segment
14 start:
15     mov ax, data
16     mov ds, ax
17     mov ax, table
18     mov es, ax
19 
20     mov bx, 0   
21     mov si, 0   
22     mov di, 0  
23     mov cx, 5   
24 year:  
25     mov dx, cx  
26     mov cx, 4   
27 yearnum:  
28     mov al, byte ptr ds:[di]   
29     mov byte ptr es:[bx][si], al
30     inc si     
31     inc di     
32     loop yearnum 
33 
34     mov cx, dx     
35     add bx, 10h   
36     mov si, 0      
37     loop year
38 
39     mov bx, 0      
40     mov si, 5     
41     mov cx, 5      
42 income:
43     mov ax, word ptr ds:[di]
44     mov word ptr es:[bx][si], ax
45     add si, 2
46     add di, 2
47     mov ax, word ptr ds:[di]
48     mov word ptr es:[bx][si], ax
49     add si, 2
50     add di, 2               
51 
52     add bx, 10h    
53     mov si, 5      
54     
55     loop income
56 
57     mov bx, 0   
58     mov si, 0Ah   
59     mov cx, 5       
60 employee: 
61     mov ax, word ptr ds:[di]
62     mov word ptr es:[bx][si], ax
63     add si, 2
64     add di, 2
65     
66     add bx, 10h     
67     mov si, 0Ah    
68 
69     loop employee
70 
71     mov bx, 0       
72     mov si, 5       
73     mov cx, 5       
74 average:
75     mov ax, word ptr es:[bx][si]
76     add si, 2
77     mov dx, word ptr es:[bx][si]
78     add si, 3       
79     div word ptr es:[bx][si]
80     add si, 3     
81     mov word ptr es:[bx][si], ax
82     
83     add bx, 10h     
84     mov si, 5      
85     loop average
86 
87 
88     mov ah, 4ch
89     int 21h
90 code ends
91 end start

 

 

Result:

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

 

Posted by akravets on Mon, 08 Nov 2021 15:26:50 -0800