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

empirical conclusion

1. Experimental task 1

Task 1-1

task1_1.asm source code:

 1 assume ds:data, cs:code, ss:stack
 2 data segment
 3     db 16 dup(0) ; 16 byte units are reserved, and the initial values are 0
 4 data ends
 5 stack segment
 6     db 16 dup(0) ; 16 byte units are reserved, and the initial values are 0
 7 stack ends
 8 code segment
 9 start:
10     mov ax, data
11     mov ds, ax
12     mov ax, stack
13     mov ss, ax
14     mov sp, 16 ; Set stack top
15 mov ah, 4ch
16     int 21h
17 code ends
18 end start

task1_1 screenshot before the end of line17 and line19

Question answer

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

2) 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-2h__,   The segment address of stack is  _ X-1h__

 

Task 1-2

task1_2.asm source code:

 1 assume ds:data, cs:code, ss:stack
 2 data segment
 3     db 4 dup(0) ; Four byte units are reserved, and the initial value is 0
 4 data ends
 5 stack segment
 6     db 8 dup(0) ; 8 byte units are reserved, and the initial values are 0
 7 stack ends
 8 code segment
 9 start:
10     mov ax, data
11     mov ds, ax
12     mov ax, stack
13     mov ss, ax
14     mov sp, 8   ; Set stack top
15 mov ah, 4ch
16     int 21h
17 code ends
18 end start

task1_2 screenshot before the end of line17 and line19

Question answer

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

2) 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-2h__,   The segment address of stack is  _ X-1h__

 

Task 1-3

task1_3.asm source code:

assume ds:data, cs:code, ss:stack
 2 data segment
 3     db 20 dup(0) ; 20 byte units are reserved, and the initial values are 0
 4 data ends
 5 stack segment
 6     db 20 dup(0) ; 20 byte units are reserved, and the initial values are 0
 7 stack ends
 8 code segment
 9 start:
10     mov ax, data
11     mov ds, ax
12     mov ax, stack
13     mov ss, ax
14     mov sp, 20 ; Set stack top
15 mov ah, 4ch
16     int 21h
17 code ends
18 end start

task1_3 screenshot before the end of line17 and line19

Question answer

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

2) 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-4h__,   The segment address of stack is  _ X-2h__

 

Tasks 1-4

task1_4.asm source code:

 1 assume ds:data, cs:code, ss:stack
 2 code segment
 3 start:
 4     mov ax, data
 5     mov ds, ax
 6     mov ax, stack
 7     mov ss, ax
 8     mov sp, 20
 9 mov ah, 4ch
10     int 21h
11 code ends
12 data segment
13     db 20 dup(0)
14 data ends
15 stack segment
16     db 20 dup(0)
17 stack ends
18 end start

task1_4. Screenshot of the values of registers DS, CS and SS before debugging to line9 and line11

Question answer

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

2) 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+2h__,   The segment address of stack is  _ X+4h__

 

Tasks 1-5

1) For the segment defined below, after the program is loaded, the actual memory space allocated to the segment is  _ [ N / 16 ] * 16   ([] is rounded up) _.

1 xxx segment
2     db N dup(0)
3 xxx ends

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

task1_4.asm can still run.

 

2. Experimental task 2

Assembly source code:

code segment
start:
    mov ax, 0b800h
    mov ds, ax
    mov bx, 0f00h
    mov cx, 50h  ; 160 Bytes need to be written 80 times, corresponding to hexadecimal number 50 h
    mov ax, 0403h ; Low 03 high 04
s:  mov ds:[bx], ax
    add bx, 2
    loop s

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

Operation results:  

 

 

3. Experimental task 3

Complete compilation source code:

 1 assume ds:data1, 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       ; Cycle 10 times, corresponding to hexadecimal number 0 ah
20 s:  mov ax, ds:[bx]
21     add ax, ds:[bx+10h]    ; take data2 Add corresponding data in ax The address difference is 16 bytes, i.e. 10 h
22     mov ds:[bx+20h], ax    ; hold ax Data storage data3 The difference between the corresponding location addresses is 32 bytes, i.e. 20 h
23     inc bx
24     loop s
25 
26    mov ah, 4ch
27    int 21h
28 code ends
29 end start

Disassembly

Before data items are added in turn, check the original values of memory space data corresponding to logical segments data1, data2 and data3   debug command

Use the g 8 command to debug until the loop is executed, and then use the d ds:0 command to view the original value of memory space data

Use the g 16 command to debug to the end of loop execution, and then use the d ds:0 command to view the added memory space data

It can be seen that the requirements of adding the data of logical segment data1 and logical segment data2 in turn and saving the results in logical segment data3 are realized.

 

4. Experimental task 4

Complete compilation 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 ;Define stack segments stack
12 stack segment
13     dw 8 dup(0)
14 stack ends
15 
16 code segment
17 start:
18     ; take data1 Data stack
19     mov ax, data1
20     mov ds, ax
21     mov sp, 9  ; Set stack top to 9
22     mov bx, 0
23     mov cx, 8   ; 8 elements in total, 8 cycles
24 s1: push ds:[bx]
25     add bx, 2
26     loop s1
27 
28     ; Out of stack data to data2
29     mov ax, data2
30     mov ds, ax
31     mov bx, 0
32     mov cx, 8
33 s2: pop ds:[bx]
34     add bx, 2
35     loop s2
36 
37     mov ah, 4ch
38     int 21h
39 code ends
40 end start

Data in data1 and data2 before execution

Data in data segment data2 after execution (i.e. from address 076A:0010)

It can be seen that the requirement of storing the 8-word data in logical segment data1 in reverse order into logical segment b is correctly realized.

 

5. Experimental task 5

task5.asm source code:

 1 assume cs:code, ds:data
 2 data segment
 3         db 'Nuist'
 4         db 2, 3, 4, 5, 6
 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 at one time until the screenshot before the program returns:

Function of line19 in source code:

Converts lowercase letters to uppercase letters.

Modify the values of 5 byte units in line4 (change all values to 2), reassemble, link and run again. The operation results are as follows:

It can be seen that the string color changes, so I guess the numerical value here is used to control the display color of the output characters.  

 

6. Experimental task 6

The completed task6.asm 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 
15     mov ax, data
16     mov es, ax
17 
18     mov bx, 0
19     mov cx, 4 ; The outer layer contains 4 expressions and loops 4 times
20 
21 s0: mov si, cx
22     mov cx, 4 ; Inner conversion first word(4 character),Cycle 4 times
23 
24 s1: mov al, es:[bx]
25     or al, 20h  ; Capitalize->a lowercase letter or 00100000B Namely or 20h
26     mov es:[bx], al;
27     inc bx
28     loop s1
29 
30     mov cx, si
31     mov bx, 0
32     mov ax, es
33     inc ax
34     mov es, ax
35     loop s0
36     
37     mov ah, 4ch
38     int 21h
39 code ends
40 end start

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

Using the disassembly command u in debug, it is observed that the exit statement address is 076A:002C

After using the g 002C command, use the d ds:0 command to view the memory space data corresponding to the data segment data

It can be seen that the first word of each line in the data section is changed from uppercase to lowercase.

 

7. Experimental task 7

Complete task7.asm source code:

 1 assume cs:code, ds:data, es:table
 2 
 3 data segment
 4     db '1975', '1976', '1977', '1978', '1979'  ; Start address 0 offset 4 each time
 5     dw  16, 22, 382, 1356, 2390 ; Start address 20 offset 2 each time
 6     dw  3, 7, 9, 13, 28  ; Start address 30 offset 2 each time
 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 cx, 5
21     mov bx, 0
22     mov si, 0
23     mov di, 0
24 s:
25     mov ax, [bx+2]
26     mov es:[di+2], ax
27     mov ax, [bx]
28     mov es:[di], ax
29     mov ax, [si+20]
30     mov word ptr es:[di+5], 0
31     mov word ptr es:[di+7], ax
32     mov ax, [si+30]
33     mov word ptr es:[di+11], ax
34     mov word ptr es:[di+9], 0
35     mov ax, es:[di+7]
36     div byte ptr es:[di+11]
37     mov byte ptr es:[di+13], 0
38     mov es:[di+14], al
39     add bx, 4
40     add si, 2
41     add di, 16
42     loop s
43     
44     mov ah, 4ch
45     int 21h
46 code ends
47 end start

In debug, use the u command to disassemble, and use the g command to debug to the beginning of the cycle, and then use the d command to view the original data in DS and es

Again, use the g command to debug until the program exits, and use the d command to view the data in es

The visible data is stored in the table as required.

 

Experimental summary

1. and 0DFH can be used to convert characters from uppercase to lowercase, and or 20H can be used to convert uppercase to lowercase.

2. When using the double-layer loop structure, you need to save the number of external loops (i.e. the value of register cx) before the start of the internal loop, and restore the value of cx after the end of the internal loop.

3. If the memory space n is defined in the segment, the actual memory space allocated to the segment after the program is loaded is   [ N / 16 ] * 16   ([] is rounded up).

Added by lukeurtnowski on Mon, 08 Nov 2021 07:58:20 +0200