Assembly language 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.
- The following is task1_1.asm source code content:
//task1_1.asm assume 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
- Debug to the end of line17 and before line19,
Input instruction-g 000D
Before jumping to 19 lines of code, view the results:
- Question answer: record at 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).
Task 1-2
To program task1_2.asm assembles and connects, loads and tracks debugging with debug, and answers questions based on the results.
- The following is task1_2.asm source code content:
1 //task1_2.asm 2 assume ds:data, cs:code, ss:stack 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
After debugging to line17, enter the command before line19
-g 000D
Before jumping to 19 lines of code, view the results
- Question answer: record at this time: register (DS) = 076A, register (SS) = 076B, register (CS) = 076C . Assuming that after the program is loaded, the segment address of the code segment is x, the segment address of the data segment is (x-2) and the segment address of the 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.
- The following is task1_3.asm source code content:
1 //task1_3.asm 2 assume ds:data, cs:code, ss:stack 3 data segment 4 db 20 dup(0) 5 data ends 6 stack segment 7 db 20 dup(0) 8 stack ends 9 code segment 10 start: 11 mov ax, data 12 mov ds, ax 13 14 mov ax, stack 15 mov ss, ax 16 mov sp, 20 17 18 mov ah, 4ch 19 int 21h 20 code ends 21 end start
After debugging to line17, enter the command before line19
-
-g 000D
Before jumping to 19 lines of code, view the results:
- Question answer: record at this time: register (DS) = 076A, register (SS) = 076C, register (CS) = 076E . Assuming that after the program is loaded, the segment address of the code segment is x, the segment address of the data segment is (x-4) and the segment address of the 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.
- The following is task1_4.asm source code content:
1 //task1_4.asm 2 assume ds:data, cs:code, ss:stack 3 code segment 4 start: 5 mov ax, data 6 mov ds, ax 7 8 mov ax, stack 9 mov ss, ax 10 mov sp, 20 11 12 mov ah, 4ch 13 int 21h 14 code ends 15 16 data segment 17 db 20 dup(0) 18 data ends 19 20 stack segment 21 db 20 dup(0) 22 stack ends 23 24 end start
- After debugging to line17, enter the command before line19
-g 000D
Before jumping to 19 lines of code, view the results:
- Question answer: record at 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).
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 max{16,N}b.
1 xxx segment 2 db N dup(0) 3 xxx ends
- 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, and Task1 is found_ 4. ASM can be executed correctly. task1_1.asm, task1_2.asm, task1_3.asm cannot be executed correctly. Analysis: task1_4.asm can be executed correctly. task1_1.asm, task1_2.asm, task1_3.asm cannot be executed correctly because end start is changed to end, and the program does not mark the end position of the program segment, so the start position cannot be paired. task1_4.asm starts with a program segment and can run normally. task1_1.asm, task1_2.asm, task1_3.asm starts with a data segment and cannot be recognized as a program segment, so it cannot run.
Experiment task 2
Write an assembly source program to realize 160 consecutive bytes to memory unit b800:0f00-b800:0f9f, and fill hexadecimal data 03 and 04 repeatedly in turn.
- The following is the experimental task 2 design code task2.asm:
1 //task2.asm 2 assume cs:code 3 4 code segment 5 start: 6 mov ax,0b800h 7 mov ds,ax 8 mov bx,0f00h 9 mov cx,80 10 11 s: mov [bx],0403h 12 add bx,2 13 loop s 14 15 mov ah, 4ch 16 int 21h 17 code ends 18 end start
- Generate exe file, and the test run results are as follows:
a row;Row 1 ❤
Experimental task 3
It is known that the code fragment of task3.asm of 8086 assembly source program is as follows:
1 //task3.asm 2 assume cs:code 3 data1 segment 4 db 50, 48, 50, 50, 0, 48, 49, 0, 48, 49 ; ten numbers 5 data1 ends 6 7 data2 segment 8 db 0, 0, 0, 0, 47, 0, 0, 47, 0, 0 ; ten numbers 9 data2 ends 10 11 data3 segment 12 db 16 dup(0) 13 data3 ends 14 15 code segment 16 start: 17 ; ××× 18 code ends 19 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.
1 //Supplementary code 2 code segment 3 start: 4 mov ax,data1 5 mov ds,ax 6 7 mov bx,0 8 mov cx,5 9 s: mov ax,[bx] 10 add ax,[bx+16] 11 mov [bx+32],ax 12 add bx,2 13 loop s
- 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. View the debug command and screenshot of the original value of memory space data corresponding to logical segments data1, data2 and data3:
The following is a screenshot of the memory space corresponding to data1, 2 and 3 logical segments before addition:Run command:
1 -g 0018
Check the memory space data corresponding to the added logical segments data1, data2 and data3 again, and confirm that the added results are stored in the logical segment data3 one by one.
Experimental task 4
It is known that the code fragment of task4.asm of 8086 assembly source program 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(?) 9 data2 ends 10 stack segment 11 db 16 dup(0) 12 stack ends 13 code segment 14 start: 15 16 ; xxx 17 mov ah, 4ch 18 int 21h 19 code ends 20 end start
- Completion procedure:
1 code segment 2 start: 3 mov ax, data1 4 mov ds, ax 5 mov ax, data2 6 mov ss, ax ; 7 mov sp, 10h ; 8 mov bx, 0 9 mov cx, 8 10 s: push [bx] 11 add bx, 2 12 loop s 13 14 mov ah, 4ch 15 int 21h 16 code ends 17 end start
Loading, disassembly and debugging in debug:
- Before exiting the program, use the d command to view the memory space corresponding to data segment data2:
Experiment task 5
Input source code:
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
- Run the source program and get the following results:
The color "NUIST" is displayed in the lower left corner.
- Use the debug tool to debug the program, and use the g command to execute it all at once before the program returns (i.e. after the execution of ine25 and before the execution of line27):
After reading the source program and analyzing the function of the source code in theory, we can conclude that:
- Line 19 in the source code: and al,0dfh command, which sums any number with 0dfh (11011111), and the third position 0 from high to low. It realizes the function of converting the binary representation of lowercase letters into the corresponding binary representation of uppercase letters, that is, the function of converting lowercase letters into uppercase letters.
- The value of the five byte unit in line 4 of the source code controls the color of the letter, and it is slightly modified
db 2,3,4,5,6 --> Change to: db 5 dup(2) or db 5 dup(5)
Reassemble, link, run, observations:
Change to db 5 dup(2): green "NUIST"
Change to db 5 dup(5): magenta "NUIST"
Experimental task 6
It is known that the code fragment of task6.asm of 8086 assembly source program 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 ; xxx 13 mov ah, 4ch 14 int 21h 15 code ends 16 end start
- Complete the program to change the first word of each line in the data section from uppercase to lowercase. The code is as follows:
1 code segment 2 start: 3 mov ax,data 4 mov ds,ax 5 mov cx,4 6 mov bx,0 7 s: 8 mov dx,cx 9 mov cx,4 10 mov si,0 11 s0: 12 mov al,ds:[bx+si] 13 or al,00100000B 14 mov ds:[bx+si],al 15 inc si 16 loop s0 17 add bx,16 18 mov cx,dx 19 loop s 20 21 mov ah, 4ch 22 int 21h 23 code ends
- Complete and test the running program, and use the d command to view the memory space corresponding to the data section: the first word in each line has been converted to lowercase.
Experimental task 7
Problem scenario description: the basic situation 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. Task7.asm 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 ah,4ch 17 int 21h 18 code ends 19 end start
- Complete the program to achieve the title requirements: write the year, income, number of employees and per capita income into the table in a structured way. Each row of data in the table accounts for 16 bytes in the logical segment table. The byte size distribution of each data is as follows. During the period, the data is separated by spaces.
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 bx, 0 mov bp, 0 mov cx, 5 col1: mov ax, [bx] mov es:[bp], ax mov ax, [bx+2] mov es:[bp+2], ax add bx, 4 add bp, 10h loop col1 mov bp, 5 mov cx, 5 col2: mov ax, [bx] mov es:[bp], ax add bx, 2 add bp, 10h loop col2 mov cx, 5 mov bp, 10 col3: mov ax, [bx] mov es:[bp], ax add bx, 2 add bp, 10h loop col3 mov cx, 5 mov bp, 5 col4: mov ax, es:[bp] mov bl, es:[bp+5] div bl mov es:[bp+8], al add bp,10h loop col4 mov ah, 4ch int 21h code ends end start
- To view the original information of the table segment:
- Use the d command to view the memory space corresponding to the table segment and confirm that the information has been written to the specified memory as required: