Experiment 2 compilation and debugging of assembly source program of multiple logic segments

Experimental task 1

Task 1-1

task1_1.asm source code task1_1 screenshot before the end of line17 and line19

 

Question answer

① In debug, execute until the end of line17 and before line19. Record this time: register (DS) =_ 076A_, Register (SS) =_ 076B_, Register (CS) =_ 076C_

  ② Assuming that the segment address of the code segment is X after the program is loaded, the segment address of the data segment is X_ X-2_, The segment address of stack is_ X-1_.

                                                                                                    

Task 1-2

task1_2.asm source code task1_2. After debugging to the end of line17 and before line19, observe the screenshot of register DS, CS and SS values

 

Question answer

① In debug, execute until the end of line17 and before line19. Record this time: register (DS) =_ 076A_, Register (SS) =_ 076B_, Register (CS) =_ 076C_

② Assuming that the segment address of the code segment is X after the program is loaded, the segment address of the data segment is X_ X-2_, The segment address of stack is_ X-1_.

 

Task 1-3

Task task1_3.asm source code task1_3. Screenshot of the values of registers DS, CS and SS before the end of debugging to line17 and line19

 

Question answer

① In debug, execute until the end of line17 and before line19. Record this time: register (DS) =_ 076A_, Register (SS) =_ 076C_, Register (CS) =_ 076E_

  ② Assuming that the segment address of the code segment is X after the program is loaded, the segment address of the data segment is X_ X-4_, The segment address of stack is_ X-2_.

 

Tasks 1-4

Task task1_4.asm source code task1_4. After debugging to the end of line17 and before line19, observe the screenshot of register DS, CS and SS values

 

Question answer

① In debug, execute until the end of line9 and before line11. Record this time: register (DS) =_ 076C_, Register (SS) =_ 076E_, Register (CS) =_ 076A_

② Assuming that the segment address of the code segment is X after the program is loaded, the segment address of the data segment is X_ X+2_, The segment address of stack is_ X+4_.

 

Tasks 1-5

Based on the practice and observation of the above four experimental tasks, summarize and answer:

① For the segment defined below, after the program is loaded, the actual memory space allocated to the segment is_ int((N+1)/16)+1_.

② If the program Task1_ 1.asm, task1_ 2.asm, task1_ 3.asm, task1_ 4. In ASM, if the pseudo instruction end start is changed to end, which program can still be executed correctly. The reasons are analyzed and explained in combination with the conclusions obtained from practical observation.

A: only task1_4 can run. The start after end indicates that the starting place of the source program is start. If there is no start, the program runs from the beginning, while the beginning of the other three programs are data segments and cannot run. Only task1_4 starts with a code segment that can run.

 

Experimental task 2

Source code:

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

Experimental results:

 

Experimental task 3

Source code:

 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,10
20 s:
21     mov al,ds:[bx]
22     add al,ds:[bx+16]
23     mov [bx+32],al
24     inc bx
25     loop s
26 
27     mov ah,4ch
28     int 21h
29 code ends
30 end start

Before adding data items in turn, check the debug command and screenshot of the original value of memory space data corresponding to logical segments data1, data2 and data3:

 

After adding in sequence, view the debug command and screenshot of the original value of memory space data corresponding to logical segments data1, data2 and data3:

 

Experimental task 4

Source code:

 1 assume cs:code
 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(?)
 9 data2 ends
10 
11 code segment
12 start:
13     mov ax,data1
14     mov ds,ax
15     mov bx,0
16     mov ax,data2
17     mov ss,ax
18     mov sp,10h
19     mov cx,8
20 s:
21     push [bx]
22     add bx,2
23     loop s
24     
25     mov ah, 4ch
26     int 21h
27 code ends
28 end start

Screenshot of original data segment:

Before the program exits, use the d command to view a screenshot of the memory space corresponding to the data segment data2:

 

Experimental task 5

Source code:

 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

Screenshot of operation results:

 

Use the debug tool to debug the program, and use the g command to execute it once before the program returns (i.e. after ine25 and before line27):

 

 

Q: what is the role of line19 in the source code?

A: use the and method to convert all letters to uppercase letters.

 

Q: what is the purpose of the byte data in the data segment line4 in the source code?

A: make the five letters appear in different colors.

 

Modify the value of 5 byte units in line4, reassemble, link, run and observe the results.

 

 

Experimental task 6

Source code:

 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     mov bx,0
15     mov cx,4
16 s:
17     mov al,[bx]
18     or al,00100000b
19     mov [bx],al
20     add bx,16
21     loop s
22        
23    mov ah, 4ch
24    int 21h
25 code ends
26 end start

Screenshot of original data:

Before the program exits, use the d command to view a screenshot of the memory space corresponding to the data segment data:

 

Experimental task 7

Source code:

 1 assume cs:code, ds:data, es:table
 2 
 3 data segment
 4     db '1975', '1976', '1977', '1978', '1979' 
 5     dw  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     mov bx,0
20     mov si,0
21     mov cx,5
22 s1:
23     mov ax,[bx]
24     mov es:[si],ax    
25     mov ax,[bx+2]
26     mov es:[si+2],ax
27     add bx,4
28     add si,16
29     loop s1
30     
31     mov bx,20
32     mov cx,5
33     mov si,5
34 s2:
35     mov ax,0
36     mov es:[si+2],ax 
37     mov ax,[bx]
38     mov es:[si],ax
39     add bx,2
40     add si,16
41     loop s2
42 
43     mov bx,30
44     mov cx,5
45     mov si,10
46 s3:
47     mov ax,[bx]
48     mov es:[si],ax
49     add bx,2
50     add si,16
51     loop s3
52 
53     mov cx,5
54     mov si,0
55 s4:     
56     mov ax, es:[si+5] 
57     mov dx, es:[si+7] 
58     div word ptr es:[si+10]
59     mov es:[si+13],ax
60     add si,16
61     loop s4
62 
63     mov ah, 4ch
64     int 21h
65 code ends
66 end start

View the screenshot of the original data information of the table segment:

 

Run debug until the program exits, use the d command to view the screenshot of the memory space corresponding to the table segment, and confirm whether the information is structurally written to the specified memory as required:


As shown in the figure, it has been written successfully.

 

Experimental summary

Through this experiment, I have a deeper understanding of the contents of chapters 5-8 in the compilation book, I am familiar with how to achieve the desired results through the code written by myself, and I am familiar with the programming process of compilation. Experiment 1 makes me understand the storage mode of memory through reading the program, and also provides a lot of inspiration for me to write the code later. Experiment 2-6 is basically the same, They all use their knowledge flexibly and complete the corresponding topics through programming. Experiment 7 is a little difficult, but through careful analysis and understanding, they divide the problems into parts and solve them step by step, and finally get the ideal results. This experiment enabled me to apply the knowledge in books in practice, which benefited me a lot.

Posted on Sat, 06 Nov 2021 22:43:56 -0400 by cgchris99