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

Posted by Rakim on Mon, 08 Nov 2021 00:59:34 +0100

1. Task experiment 1

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

    • Question answer:

        (1) In debug, record the end of line17 and before line19: register (DS)=076A, register (SS)=076B and register (CS)=076C.

(2) assuming that the segment address of code is X after the program is loaded, the segment address of data segment is X-2 and the segment address of stack is X-1.   

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

    • Question answer:

        (1) In debug, record the end of line17 and before line19: register (DS)=076A, register (SS)=076B and register (CS)=076C.

        (2) Assuming that the segment address of code is X after the program is loaded, the segment address of data segment is X-2 and the segment address of stack is X-1.   

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

    • Question answer:

        (1) In the debug process, before the end of line17 and line19, register (DS)=076A, register (SS)=076C and register (CS)=076E.

(2) assuming that the segment address of code is X after the program is loaded, the segment address of data segment is X-4 and the segment address of stack is X-2.   

  • 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 
 7     mov ax, stack
 8     mov ss, ax
 9     mov sp, 20
10 
11     mov ah, 4ch
12     int 21h
13 code ends
14 
15 data segment
16     db 20 dup(0)
17 data ends
18 
19 stack segment
20     db 20 dup(0)
21 stack ends
22 end
    • Screenshot:

    • Question answer:

        (1) In the debug process, before the end of line17 and line19, register (DS)=076C, register (SS)=076E and register (CS)=076A.

        (2) Assuming that after the program is loaded, the segment address of code is X, the segment address of data segment is X+2, and the segment address of stack is X+4.   

  • Tasks 1-5
    • Based on the practice, observation, summary and answer of the above four experimental tasks:

(1) for the segment defined below, after the program is loaded, the actual content space allocated to the segment is [N/16]*16 (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, if the pseudo instruction end start is changed to end, which program can still be executed correctly. Combined with the conclusions obtained from practical observation, analyze and explain the reasons.

A: only task1_4.asm can be executed. Replacing end start with end means that the program does not specify the start position, and the whole code segment (including the data segment) is executed as execution code, so the data in the execution data segment will naturally make an error.

2. Task experiment 2

  • task2.asm assembly 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 p:  mov ds:[bx],0403h
 9     inc bx
10     inc bx
11     loop p
12 
13     mov ah,4ch
14     int 21h
15 code ends
16 end start
  • Screenshot:

3. Task experiment 3

  • task3.asm assembly 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 cx,16
19     mov bx,0
20 s:  mov al,ds:[bx]
21     add al,ds:[bx+16]
22     mov ds:[bx+32],al
23     inc bx
24     loop s
25 
26     mov ah,4ch
27     int 21h
28 code ends
29 end start
  • Screenshot:
    • Front screenshot of data enhancement in turn:

    •   Screenshot after adding data in sequence:

4. Task experiment 4

  • task4.asm assembly 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 stack segment
11     db 16 dup(0)
12 stack ends
13 code segment
14 start:
15     mov ax,data1
16     mov ds,ax
17     mov ax,stack
18     mov ss,ax
19     mov sp,16
20     mov bx,0
21     mov cx,8
22 s1:
23     push ds:[bx]
24     inc bx
25     inc bx
26     loop s1
27 
28     mov bx,16
29     mov cx,8
30 s2:
31     pop ds:[bx]
32     inc bx
33     inc bx
34     loop s2
35 
36     mov ah, 4ch
37     int 21h
38 code ends
39 end start
  • Screenshot:

5. Task experiment 5

  • task5.asm assembly 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:

  • Screenshot after line25 and before line27:

  • Function of line19 in source code:

A: convert all lowercase letters to uppercase letters.

  • Purpose of byte data in data segment line4 in source code:

A: set the font color.

6. Task experiment 6

  • task6.asm assembly 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 cx,4
15     mov bx,0
16 s:  
17     mov dx,cx
18     mov cx,4
19     mov si,0
20 p:
21     mov al,ds:[bx+si]
22     or al,00100000B
23     mov ds:[bx+si],al
24     inc si
25     loop p
26     
27     add bx,16
28     mov cx,dx
29     loop s
30 
31     mov ah, 4ch
32     int 21h
33 code ends
34 end start
  • Screenshot:

7. Task experiment 7

  • task7.asm assembly 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 si,0
20     mov di,0
21     mov bx,0
22     mov cx,5
23     mov sp,0
24 
25  s: mov ax,[si]
26     mov es:[di],ax
27     mov ax,[si+2]
28     mov es:[di+2],ax
29     mov ax,[bx+20]
30     mov es:[di+5],ax
31     mov dx,0
32     mov es:[di+7],dx
33     push cx
34     mov cx,[20+10+bx]
35     mov es:[di+10],cx
36     div cx
37     pop cx
38     mov es:[di+0dh],ax
39     add si,4
40     add di,16
41     add bx,2
42     loop s
43 
44     mov ah, 4ch
45     int 21h
46 code ends
47 end start
  • Screenshot:
    • Screenshot of original data information of table segment:

    • Screenshot of the memory space corresponding to the table segment before the program exits: