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

Experiment 1,

Tasks 1-10
To program task1_1.asm assembles and connects, loads and tracks debugging with debug, and answers questions based on the results.
 1 assume ds:data, cs:code, ss:stack 
 2 
 3 data segment 
 4    db 16 dup(0) ; 16 byte units are reserved, and the initial values are 0 
 5 data ends 
 6 
 7 stack segment 
 8    db 16 dup(0) ;16 byte units are reserved, and the initial values are 0 
 9 stack ends 
10 code segment 
11 start:
12    mov ax, data 
13    mov ds, ax 
14 
15    mov ax, stack 
16    mov ss, ax 
17    mov sp, 16  ; Set stack top 
18 
19    mov ah, 4ch 
20    int 21h 
21 code ends 
22 end start
① 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___.
        Note: ds=cs-2,ss=cs-1.

Task 1-2
To program task1_2.asm assembles and connects, loads and tracks debugging with debug, and answers questions based on the results.
 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 code segment
11 start:
12     mov ax, data
13     mov ds, ax
14 
15     mov ax, stack
16     mov ss, ax
17     mov sp, 8
18 
19     mov ah, 4ch
20     int 21h
21 code ends
22 end start
① 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
To program task1_3.asm assembles and connects, loads and tracks debugging with debug, and answers questions based on the results
 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 code segment
11 start:
12     mov ax, data
13     mov ds, ax
14 
15     mov ax, stack
16     mov ss, ax
17     mov sp, 20
18 
19     mov ah, 4ch
20     int 21h
21 code ends
22 end start
① 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
To program task1_4.asm assembles and connects, loads and tracks debugging with debug, and answers questions based on the results.
 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 start
① In debug, execute until the end of line9 and before line11. Record this time: register (DS) =_ 076C___, Register (SS)=__ 076E__, Register (CS) = 076A___
② Suppose that after the program is loaded, the segment address of the code segment is x__, Then, the segment address of the data segment is__ 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__ (N/16)*16__.
1 xxx segment 
2    db N dup(0) 
3 xxx ends 123
② If the program Task1_ 1.asm, task1_ 2.asm, task1_ 3.asm, task1_ 4. In ASM, the pseudo instruction end start is changed to
end, which program can still execute correctly? The reasons are analyzed and explained in combination with the conclusions obtained from practical observation.
      task1_4 can be executed, because after changing the end stat to end, the start does not match the end start, so the program cannot run from start, so the program runs sequentially from the beginning. Only program 4 can run as a program segment.
Experiment task 2
Write an assembly source program to realize 160 consecutive bytes to memory units b800:0f00 ~ b800:0f9f, and fill hexadecimal numbers repeatedly in turn
According to 03 04.
Tips:
1. In experiment task 3 of Experiment 1, experiments with the same effect were done. But at that time, the filling was realized through the f command of debug. This
Second, programming is required.
    In debug, use the f command to batch fill in data to memory cells.
        -f b800:0f00 0f9f 03 04
    Fill the memory unit interval b800:0f00 ~ b800:0f9f for 160 consecutive bytes, and fill hexadecimal data 03 and 04 repeatedly in turn.
2. When programming, pay attention to the problems of hexadecimal and byte order. After writing, run the program. If the result is different from that of experiment task 3 of Experiment 1
To, indicating that there is an error in programming.
 1 assume cs:code
 2 
 3 code segment
 4 start:
 5     mov ax,0b800h
 6     mov ds,ax
 7     mov bx,0f00h
 8     mov cx,80
 9 
10 s:  mov [bx],0403h
11     add bx,2
12     loop s
13 
14     mov ah, 4ch
15     int 21h
16 code ends
17 end start

  Operation results:

 

 

 

Experimental task 3
Code after completion:
 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 bx,0  ; take bx Define as offset
17       mov dx,0  ; take dx Defined as register
18       mov cx,10 ; cx Defined as the number of summations
19    
20 S:   mov  dx,0 ;  Every time the register is cleared
21       mov  ax, data1
22       mov  ds ,ax
23       add   dl, [bx]
24     
25       mov  ax, data2
26       mov  ds ,ax
27       add   dl, [bx]
28 
29       mov  ax, data3
30       mov  ds ,ax
31       add   [bx],dl
32 
33       inc bx
34       loop S
35      
36       mov ax,4c00h
37        int 21h
38 
39 code ends
40 end start

 

requirement:
① The programming adds the data of logical segment data1 and logical segment data2 in turn, and the results are saved in logical segment data3.
② Load, disassemble and debug in debug. Before and after the data items are added in turn, view the three logical segments data1 respectively,
Confirm that the memory space corresponding to data2 and data3 is added one by one to ensure that the result exists in the logical segment data3.

Screenshot of original data:

Execute the command

Results after operation:

 

 

 

Experimental task 4
It is known that the 8086 assembly source program task4.asm code fragment is as follows.
 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(0)
 9 data2 ends
10 
11 code segment
12 start:
13     mov ax, data1
14     mov ds, ax
15     mov ax, data2
16     mov ss, ax
17     mov sp, 16
18 
19     mov bx, 0
20     mov cx, 8
21  s:
22     push [bx]
23     add bx, 2
24     loop s
25 
26     mov ah, 4ch
27     int 21h
28 code ends
29 end start
requirement:
① Complete the program to store the eight word data in logical segment data1 in reverse order in logical segment b.
② After assembly and connection, load the program in debug and run it to line15. Before the program exits, use the d command to view the data corresponding to data segment data2
Memory space, confirm whether the subject requirements are met.
Experimental results: it is found that the requirements of the topic are successfully completed

 

 

 

Experiment task 5
Use any text editor to enter the assembly source program task5.asm.
 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
Read the source program, theoretically analyze the functions of the source code, especially line15-25, what are the functions realized by the loop, and understand the functions of each instruction line by line.
     Assemble and link the program to get the executable file, run and observe the results.
     Use the debug tool to debug the program and observe the results before the program returns, that is, after line25 and before line27.
 

 

      What is the function of line19 in the source code?

      Use bitwise and operations to capitalize letters

     Modify the value of 5 byte units in line4, reassemble, link, run and observe the results.
1 db 2,3,4,5,6 
2 --> Change to: 
3 db 5 dup(2) or db 5 dup(5)
Based on observation, analyze and guess what the numerical function here is.
 

 

  Here, the function of numerical value should be to change the color of letters.

 


Experimental task 6
It is known that the 8086 assembly source program task6.asm code fragment is as follows.
 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 
20     mov bx,0
21     mov bp,0
22     mov si,20
23     mov cx,5
24 
25 s:  mov ax,ds:[bx]
26     mov es:[bp],ax
27     mov ax,ds:[bx+2]
28     mov es:[bp+2],ax
29 
30     mov ax,ds:[si]
31     mov es:[bp+5],ax
32     mov word ptr es:[bp+7],0
33 
34     mov ax,ds:[si+10]
35     mov es:[bp+10],ax
36 
37     mov ax,ds:[si]
38     mov dl,ds:[si+10]
39     div dl
40     mov es:[bp+13],al
41     mov byte ptr es:[bp+14],0
42 
43     add bx,4
44     add bp,16
45     add si,2
46 
47     loop s
48 
49     mov ah, 4ch
50     int 21h
51 code ends
52 end start

 

requirement:
① Complete the program, realize the title requirements, and write the year, income, number of employees and per capita income into the table section in a structured way.
In the table, each row of data occupies 16 bytes in the logical segment table, and the byte size of each data is allocated as follows. Interim, between data
Space spacing.
② After assembly and connection, load and debug the program in debug. Use u command, g command and d command flexibly and reasonably to display the beginning logic
The data information of the segment table, and the data information of the segment table after the structured data is stored, confirm to realize the subject requirements.

 

  Results after running:

 

 

 

Tips:
1. This exercise task is not difficult, but cumbersome. You need to carefully sort out the layout of each data item in the table before you practice
Move address). Then, the addressing mode and loop are flexibly applied to realize the movement of data between memory and memory.
2. When practicing, do not consider the decimal division, use the div command for integer division, and keep the quotient.

Posted on Wed, 10 Nov 2021 13:09:52 -0500 by Drace