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

 

Experimental task 1

Task 1-1:

To program task1_1.asm assembles and connects, loads and tracks debugging with debug, and answers questions based on the results.

 

 

question answering:

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-2__, The segment address of stack is__ X-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.

 

 

  question answering:

① 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__.

 

Tasks 1-3:

To program task1_3.asm assembles and connects, loads and tracks debugging with debug, and answers questions based on the results.

 

 

question answering:

① 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.

 

 

 

question answering:

① In debug, execute until the end of line17 and before line19. 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_ (N/16) rounded up _.

  ② After the pseudo instruction end start is changed to end:

  task1_1 screenshot:

 

  task1_2 screenshot:

 

  task1_3 screenshot:

 

  task1_4 screenshot:

 

According to the screenshot, only Task1_ 4. The ASM program can still be executed correctly. This is because of task 1_ 1 to task 1_ 3 defines data segments first and then code segments, while task 1_ 4 is to define code segments first and then data segments. end start tells the program that the code starts from start. After writing end, the program will compile from the first line. Because task 1_ 4 code snippet is written in front, and compiling from the first line is not affected.

 

Experiment task 2

Write an assembly source program to realize 160 consecutive bytes to memory units b800:0f00 ~ b800:0f9f, and fill hexadecimal data 03 and 04 repeatedly in turn.

Experimental code

assume cs:code
code segment
    mov ax, 0b800h
    mov ds, ax
    mov bx, 0f00h
    mov cx, 160
s: mov ax, 0403h
    mov [bx], ax
    add bx, 2h
    loop s

    mov ax,4c00h
    int 21h
code ends
end

  Screenshot of experimental results:

 

 

Experimental task 3

It is known that the 8086 assembly source program task3.asm code fragment is as follows.

task3.asm

assume cs:code
data1 segment
    db 50, 48, 50, 50, 0, 48, 49, 0, 48, 49 ; ten numbers
data1 ends

data2 segment
    db 0, 0, 0, 0, 47, 0, 0, 47, 0, 0 ; ten numbers
data2 ends

data3 segment
    db 16 dup(0)
data3 ends

code segment
start:
    ; ×××
    mov ah, 4ch
    int 21h
code ends
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, check the memory space corresponding to the three logical segments data1, data2 and data3 respectively. After adding them one by one, ensure that the results exist in the logical segment data3.

 

code:

assume cs:code
data1 segment
    db 50, 48, 50, 50, 0, 48, 49, 0, 48, 49 ; ten numbers
data1 ends

data2 segment
    db 0, 0, 0, 0, 47, 0, 0, 47, 0, 0       ; ten numbers
data2 ends

data3 segment
    db 16 dup(0)
data3 ends

code segment
start:
    mov bx,0
    mov cx,10
    mov dx,0

 s:mov dx,0
    mov ax,data1
    mov ds,ax
    add dl,[bx]

    mov ax,data2
    mov ds,ax
    add dl,[bx]
    
    mov ax,data3
    mov ds,ax
    mov [bx],dl

    inc bx
    loop s
    mov ax,4c00h
    int 21h
        
code ends
end start

end start

 

View results:

According to the operation results, the experimental requirements have been completed.

 

Experimental task 4

It is known that the 8086 assembly source program task4.asm code fragment is as follows.

task4.asm

assume cs:code
data1 segment
dw 2, 0, 4, 9, 2, 0, 1, 9
data1 ends
data2 segment
dw 8 dup(?)
data2 ends
code segment
start:
; ×××
mov ah, 4ch
int 21h
code ends
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 check the memory space corresponding to data segment data2 to confirm whether the subject requirements are met.

 

Completed code:

assume cs:code

data1 segment
    dw 2, 0, 4, 9, 2, 0, 1, 9
data1 ends 

data2 segment
    dw 8 dup(?)
data2 ends

code segment
start:
    
    mov ax,data2
    mov ss,ax
    mov sp,10h
    
    mov ax,data1
    mov ds,ax   
    mov bx,0
    mov cx,8

 s: push [bx]
    add bx,2
    loop s
    mov ah, 4ch
    int 21h
code ends
end start

 

Result screenshot:

It can be seen from the figure that the requirements have been realized

 

Experiment task 5

Use any text editor to enter the assembly source program task5.asm.

task5.asm

assume cs:code, ds:data
data segment
        db 'Nuist'
        db 2, 3, 4, 5, 6
data ends

code segment
start:
        mov ax, data
        mov ds, ax

        mov ax, 0b800H
        mov es, ax

        mov cx, 5
        mov si, 0
        mov di, 0f00h
s:      mov al, [si]
        and al, 0dfh
        mov es:[di], al
        mov al, [5+si]
        mov es:[di+1], al
        inc si
        add di, 2
        loop s

        mov ah, 4ch
        int 21h
code ends
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?

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

db 2,3,4,5,6
--> Change to:
db 5 dup(2) or db 5 dup(5)

Based on observation, analyze and guess what the numerical function here is.

 

Assemble and link the program to get the executable file. The running results are as follows

 

 

Use the debug tool to debug the program. Before the program returns, that is, after line25 and before line27, the observation results are as follows

 

 

 

The function of line19 in the source code is to change lowercase letters into uppercase letters

 

Change the of line4 to db 5 dup(2), and the result screenshot is as follows:

 

  As can be seen from the figure, the command of this statement is to change the font color.

 

Experimental task 6

It is known that the 8086 assembly source program task6.asm code fragment is as follows.

task6.asm

 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    ; ×××
13    mov ah, 4ch
14    int 21h
15 code ends
16 end start

requirement:

① Complete the program and change the first word of each line in the data section from uppercase to lowercase.

② Load the program in debug, disassemble it, and check the memory space corresponding to the data section with the d command before exiting line13. Confirm that the first word in each line has changed from uppercase to lowercase.

 

The code after completion is as follows:

 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 
17 s0:mov dx,cx
18     mov cx,4
19     mov si,0
20 
21 s: or byte ptr [bx+si], 00100000b
22    inc si
23    loop s
24    add bx,10h
25    mov cx,dx
26    loop s0
27 
28    mov ah, 4ch
29    int 21h
30 code ends
31 end start

 

The operation results are as follows

 

 

The screenshot shows that the effect has been improved.

 

  Experimental task 7

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. During the period, the data is separated by spaces.

② After assembly and connection, load and debug the program in debug. Use the u command, g command and d command flexibly and reasonably to display the data information of the logical segment table at the beginning, and the data information of the data segment table after structurally storing the data to confirm the realization of the subject requirements.

 

The experimental code 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 
16      mov ax, data
17     mov ds, ax
18     mov ax, table
19     mov es, ax
20     
21     mov bx, 0    ;particular year
22     mov si, 0
23     mov cx, 5
24 s0:mov ax, [si]    
25     mov es:[bx], ax
26     mov ax, [si+2]
27     mov es:[bx+2], ax
28     add si, 4
29     add bx, 10h
30     loop s0
31 
32     mov bx, 0    ;income
33     mov si, 14h
34     mov cx, 5
35 s1:mov ax, [si]
36     mov es:[bx+5], ax
37     mov ax, 0
38     mov es:[bx+5+2], ax
39     add si, 2
40     add bx, 10h
41     loop s1
42 
43     mov bx, 0    ;Number of employees    
44     mov si, 1eh
45     mov cx, 5
46 s2:mov ax,[si]
47     mov es:[bx+0ah], ax
48     add si, 2
49     add bx, 10h
50     loop s2
51 
52     mov bx, 0    ;Seeking quotient
53     mov cx, 5
54 s3:mov ax, es:[bx+5]
55     mov dx, es:[bx+5+2]
56     div word ptr es:[bx+0ah]
57     mov es:[bx+0dh], ax
58     add bx, 10h
59     loop s3
60     
61     mov ah, 4ch
62     int 21h
63 code ends
64 end start

 

Screenshot of experimental results:

 

Posted by VisionsOfCody on Thu, 11 Nov 2021 19:35:13 -0800