Experimental task 1
This experimental task includes 4 sub tasks. Practice one by one, observe and verify in combination with practice, and answer questions.
Task 1-1
Click to view task1_1.asmassume ds:data, cs:code, ss:stack data segment db 16 dup(0) data ends stack segment db 16 dup(0) stack ends code segment start: mov ax, data mov ds, ax mov ax, stack mov ss, ax mov sp, 16 mov ah, 4ch int 21h code ends end start
- Question one
In debug, it will be executed until the end of line17 and before line19. At this time, record that the register (DS) is__ 770__, Register (SS) yes__ 771__ Register (CS) is__ 772__. - Question two
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
Click to view task1_2.asmassume ds:data, cs:code, ss:stack data segment db 4 dup(0) data ends stack segment db 8 dup(0) stack ends code segment start: mov ax, data mov ds, ax mov ax, stack mov ss, ax mov sp, 8 mov ah, 4ch int 21h code ends end start
- Question one
In debug, it will be executed until the end of line17 and before line19. At this time, record that the register (DS) is__ 770__, Register (SS) yes__ 771__ Register (CS) is__ 772__. - Question two
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
Click to view task1_3.asmassume ds:data, cs:code, ss:stack data segment db 20 dup(0) data ends stack segment db 20 dup(0) stack ends 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 end start
- Question one
In debug, it will be executed until the end of line17 and before line19. At this time, record that the register (DS) is__ 770__, Register (SS) yes__ 772__ Register (CS) is__ 774__. - Question two
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
Click to view task1_4.asmassume 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
- Question one
In debug, it will be executed until the end of line17 and before line19. At this time, record that the register (DS) is__ 772__, Register (SS) yes__ 774__ Register (CS) is__ 770__. - Question two
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:
-
Question one
For the segment defined below, after the program is loaded, the actual memory space allocated to the segment is _.xxx segment db N dup(0) xxx ends
The actual space is 16*Math.ceil(N/16) bytes
-
Question two
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.- task1_1.asm
- task1_2.asm
- task1_3.asm
- task1_4.asm
Conclusion: end start indicates that the program entry is at start. If not, it will be executed from the first line of the program. The first three programs directly execute the space declaration, so the program cannot be recognized, while the last one executes the correct code first and then declares the space, so the program can be recognized correctly, that is, the execution sequence of the fourth program has not changed due to the lack of start.
- task1_1.asm
Experimental 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.
requirement
1 in 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 time, programming is required.
2. 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.
The code is as follows:
Click to view the codeDATAS SEGMENT ;Enter segment code here DATAS ENDS STACKS SEGMENT ;Enter the stack segment code here STACKS ENDS CODES SEGMENT ASSUME CS:CODES,DS:DATAS,SS:STACKS START: mov ax,0b800h mov ds,ax mov bx,0f00h mov cx,80 s:mov byte ptr ds:[bx],0003h inc bx mov word ptr ds:[bx],0004h inc bx loop s mov ah, 4ch int 21h CODES ENDS END START
Experimental results:
It can be found that the modification was successful. However, some contents belonging to read-only memory cannot be changed.
Experimental task 3
It is known that the 8086 assembly source program task3.asm code fragment is as follows.
Click to view task3.asmassume 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: ; ××× code ends end start
requirement
1 programming adds the data of logical segment data1 and logical segment data2 in turn, and the results are saved in logical segment data3.
2 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.
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 ax,data2 mov es,ax mov ax,data3 mov ss,ax mov bx,0 mov cx,10 s:mov ax,0 add ax,ds:[bx] add ax,es:[bx] mov ss:[bx],ax inc bx loop s mov ah, 4ch int 21h code ends end start
Segment 1:
Segment 2:
Segment 3:
You can clearly see that the results are correct and saved in data3.
Experimental task 4
It is known that the 8086 assembly source program task4.asm code fragment is as follows
Click to view task4.asmassume 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
1 complement program to store the 8-word data in logical segment data1 in reverse order in logical segment b.
2. After assembly and connection, load the program in debug, run to line15, and 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.
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,data2 mov es,ax mov bx,0 mov si,14 s:mov ax,ds:[bx] mov es:[si],ax add bx,2 sub si,2 loop s mov ah, 4ch int 21h code ends end start
result:
It is clear that they have successfully discharged in reverse order.
Experimental task 5
Use any text editor to enter the assembly source program task5.asm.
Click to view task5.asmassume 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
Experimental steps:
- 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.
Based on observation, analyze and guess what the numerical function here is.db 2,3,4,5,6 --> Change to: db 5 dup(2) or db 5 dup(5)
answer:
-
Convert lowercase letters into uppercase letters in data
-
The values here are used to adjust the color of each character.
Experimental task 6
It is known that the 8086 assembly source program task6.asm code fragment is as follows.
Click to view task6.asmassume 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: ; xxx mov ah, 4ch int 21h code ends end start
requirement
1 complete the program and change the first word of each line in the data section from uppercase to lowercase.
2 load the program in debug, disassemble it, and check the memory space corresponding to the data section with the d command before line13 exits, and confirm that the first word in each line has changed from uppercase to lowercase.
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 ax,data mov ds,ax mov bx,0 mov cx,4 mov si,0 s:mov al,ds:[0+si] or al,20H mov ds:[0+si],al add si,16 loop s mov ah, 4ch int 21h code ends end start
result:
The first line originally:
After the first line is changed:
The second line originally:
After the second line is changed:
The third line originally:
After the third line is changed:
The fourth line was originally:
After the fourth line is changed:
You can clearly see that the required functions are implemented.
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
Data format requirements for final display:
At the same time, the per capita income can be kept as an integer
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 ax,ds:[1] ;bx,si,di mov cx,5 mov bx,0 mov si,0 s1:mov ax,ds:[bx] mov es:[si],ax add bx,2 mov ax,ds:[bx] add si,2 mov es:[si],ax add bx,2 add si,14 loop s1 mov bx,20 mov cx,5 mov si,5 s2:mov ax,ds:[bx] mov es:[si],ax add si,2 mov word ptr es:[si],0 add bx,2 add si,14 loop s2 mov bx,30 mov cx,5 mov si,10 s3:mov ax,ds:[bx] mov es:[si],ax add bx,2 add si,16 loop s3 mov bx,20 mov di,30 mov cx,5 mov si,13 s4:mov ax,ds:[bx] mov dl,ds:[di] div dl mov es:[si],al add bx,2 add di,2 add si,16 loop s4 mov ah, 4ch int 21h code ends end start
result:
Inspection:
- The data structure meets the requirements.
- The year, income and employee are copied, but the income is two bytes more. It is confirmed that the data is correct.
- Per capita income: (decimal) 16 / 3 = 5,22 / 7 = 3382 / 9 = 421356 / 13 = 1042390 / 28 = 85
Converted to hexadecimal: 05,03,2A,68,55 -- the data is confirmed to be correct.
summary
- Have a deeper understanding of the knowledge of data segment definition, be able to flexibly use multiple data segments, and master the relevant knowledge of the size limit of data segments and the relationship between data segment address and cs.
- Master the registers commonly used in operand addressing, and be able to use them to address flexibly.
- Master the pseudo instructions including db, dw, dd, dup and ptr. At the same time, it can also flexibly use ordinary instructions such as addition, subtraction, multiplication and division and and and or, and can complete simple work.
- More flexible use of debugging commands to debug programs.
- Learned some markdown syntax to make the page more hierarchical and focused.