1, Experimental purpose
- Understand and master the assembly source program of more than 8086 logic segments
- Understand and skillfully apply flexible addressing methods
- Through the use of assembly instruction loop, understand the essence of loop in programming language and master its correct use in nested loop
- Master the method of debugging 8086 assembler with debug
2, Experimental preparation
Review chapters 5-8 of assembly language by Wang Shuang:
- Assembly source program structure containing multiple logical segments
- Addressing mode
- Assembly instruction loop, div usage
3, Experimental content
Experimental task 1
This experimental task includes 4 sub tasks. Practice one by one, observe and verify in combination with practice, and answer questions.
- 1.1
To program task1_1.asm assembles and connects, loads and tracks debugging with debug, and answers questions based on the results.
assume ds:data, cs:code, ss:stack data segment db 16 dup(0) ; 16 byte units are reserved, and the initial values are 0 data ends stack segment db 16 dup(0) ;16 byte units are reserved, and the initial values are 0 stack ends code segment start: mov ax, data mov ds, ax mov ax, stack mov ss, ax mov sp, 16 ; Set stack top mov ah, 4ch int 21h code ends 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-2 and the segment address of the stack is X-1.
The memory is allocated from top to bottom according to the writing order of data and code segments in the code, so the data segment is allocated first, then the stack segment, and finally the code segment. The address length of one segment is 16 bytes, so the two data segments are allocated one segment address length, X-2 and X-1 respectively. The following sub tasks are similar.
- 1.2
To program task1_2.asm assembles and connects, loads and tracks debugging with debug, and answers questions based on the results.
assume ds:data, cs:code, ss:stack data segment db 4 dup(0) ; Four byte units are reserved, and the initial value is 0 data ends stack segment db 8 dup(0) ; 8 byte units are reserved, and the initial values are 0 stack ends code segment start: mov ax, data mov ds, ax mov ax, stack mov ss, ax mov sp, 8 ; Set stack top mov ah, 4ch int 21h code ends 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-2 and the segment address of the stack is X-1.
The data segment is less than 16 bytes and full 16 bytes are allocated. 8086 memory allocation is generally in 16 bytes.
- 1.3
To program task1_3.asm assembles and connects, loads and tracks debugging with debug, and answers questions based on the results
assume ds:data, cs:code, ss:stack data segment db 20 dup(0) ; 20 byte units are reserved, and the initial values are 0 data ends stack segment db 20 dup(0) ; 20 byte units are reserved, and the initial values are 0 stack ends code segment start: mov ax, data mov ds, ax mov ax, stack mov ss, ax mov sp, 20 ; Set initial stack top mov ah, 4ch int 21h code ends 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-4 and the segment address of the stack is X-2.
- 1.4
To program task1_4.asm assembles and connects, loads and tracks debugging with debug, and answers questions based on the results.
assume ds:data, cs:code, ss:stack code segment start: mov ax, data mov ds, ax mov ax, stack mov ss, ax mov sp, 20 mov ah, 4ch int 21h code ends data segment db 20 dup(0) data ends stack segment db 20 dup(0) stack ends end start
① 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+2 and the segment address of the stack is X+4.
The code segment of the task is at the beginning, so the addresses of data segment and stack segment are at the end.
- 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 (brackets are rounded up)
xxx segment db N dup(0) xxx ends
② 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.
The fourth task can still run successfully. After changing the end start at the end of the other three tasks, the start pseudo instruction becomes invalid, and the program executes backward from the segment prefix. According to the allocation order, the first three tasks start with a data segment, the program cannot recognize the code category, resulting in an error, and the code segment of the fourth task is allocated first to avoid the generation of conflict.
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.
Tips:
- In task 3 of Experiment 1, experiments to achieve the same effect were done. But at that time, the filling was realized through the f command of debug. This time, programming is required.
stay debug In, use f Command to batch fill in data to memory units. -f b800:0f00 0f9f 03 04 Memory unit interval b800:0f00 ~ b800:0f9f For 160 consecutive bytes, fill hexadecimal data 03 and 04 repeatedly in turn.
- When programming, pay attention to the problems of hexadecimal and byte order. After writing, run the program. If the result is inconsistent with that of experiment task 3 of Experiment 1, it indicates that the program is wrong.
Program code:
assume cs:code code segment start: mov ax,0b800h mov ds,ax mov bx,0f00h mov cx,80 p: mov ds:[bx],0403h add bx,2 loop p mov ah,4ch int 21h code ends end start
The results are shown in the figure
Experimental task 3
It is known that the 8086 assembly source program task3.asm code fragment is as follows
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.
Completed 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 ax,data1 mov ds,ax mov cx,16 mov bx,0 s: mov al,ds:[bx] add al,ds:[bx+16] mov ds:[bx+32],al inc bx loop s mov ah, 4ch int 21h code ends end start
Data1 and data2 each have 10 hexadecimal numbers and allocate 16 byte space for them. Therefore, the position of data1 data segment corresponding to data2 data segment is data1+16 and the position of data3 is data1+32. Write the three-step code accordingly
mov al,ds:[bx]
add al,ds:[bx+16]
mov ds:[bx+32],al
Save after adding the number of corresponding positions.
Experimental results:
Experimental task 4
It is known that the 8086 assembly source program task4.asm code fragment is as follows
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.
Code after completion:
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,data1 mov ds,ax mov ax,stack mov ss,ax mov sp,16 mov bx,0 mov cx,8 s1: push ds:[bx] add bx,2 loop s1 mov bx,16 mov cx,8 s2: pop ds:[bx] add bx,2 loop s2 mov ah, 4ch int 21h code ends end start
Press 8 numbers into the stack in turn, and then pop them up to the corresponding position of data2 in turn. Pay attention to the setting of bx value during pop-up.
Experimental results:
Experiment task 5
Use any text editor to enter the assembly source program 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.
1. Operation results
2. Operation results
3. The function of line19 is to convert lowercase letters into uppercase letters. The implementation method is based on the characteristics of ASCII code of English uppercase and lowercase letters. The lowercase letters are 32 higher than the corresponding uppercase letters. The binary number phase and can be used to change the value of the corresponding bit. The binary number phase is filled with 0 where you want to assign 0, and the other bits are filled with 1, which can achieve the effect of "binary mask".
4. Operation results
The five values correspond to the font color of the five letters in turn.
Experimental task 6
It is known that the 8086 assembly source program task6.asm code fragment is as follows
assume cs:code, ds:data data segment db 'Pink Floyd ' ; 16 byte db 'JOAN Baez ' ; 16 byte db 'NEIL Young ' ; 16 byte db 'Joan Lennon ' ; 16 byte data ends code segment start: ; ××× mov ah, 4ch int 21h code ends 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.
Completed procedure:
assume cs:code, ds:data data segment db 'Pink Floyd ' db 'JOAN Baez ' db 'NEIL Young ' db 'Joan Lennon ' data ends code segment start: mov ax,data mov ds,ax mov cx,4 mov bx,0 s: mov dx,cx mov cx,4 mov si,0 p: mov al,ds:[bx+si] or al,00100000B mov ds:[bx+si],al inc si loop p add bx,16 mov cx,dx loop s mov ah, 4ch int 21h code ends end start
Experimental results:
The outer loop traverses 4 lines of words, the memory loop traverses each letter of the first word, and uses dx to temporarily store the cx value. Combine the word data with 00100000B through the or instruction or obtain lower case letters with greater ASCII.
Experimental task 7
Problem scenario description:
The basic information of Power idea from 1975 to 1979 is as follows:
These data have been defined in the logical segment data (line4-6) of program task7.asm.
assume cs:code, ds:data, es:table data segment db '1975', '1976', '1977', '1978', '1979' dw 16, 22, 382, 1356, 2390 dw 3, 7, 9, 13, 28 data ends table segment db 5 dup( 16 dup(' ') ) ; table ends code segment start: mov ah, 4ch int 21h code ends 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. 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.
Completed procedure:
assume cs:code, ds:data, es:table data segment db '1975', '1976', '1977', '1978', '1979' dw 16, 22, 382, 1356, 2390 dw 3, 7, 9, 13, 28 data ends table segment db 5 dup( 16 dup(' ') ) ; table ends code segment start: mov ax,data mov ds,ax mov ax,table mov es,ax mov si,0 mov di,0 mov bx,0 mov cx,5 mov sp,0 s: mov ax,[si] mov es:[di],ax mov ax,[si+2] mov es:[di+2],ax mov ax,[bx+20] mov es:[di+5],ax mov dx,0 mov es:[di+7],dx push cx mov cx,[20+10+bx] mov es:[di+10],cx div cx pop cx mov es:[di+0dh],ax add si,4 add di,16 add bx,2 loop s mov ah, 4ch int 21h code ends end start
Experimental results: