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

1. Experimental task 1 Task 1-1 task1_1.asm source code ...

1. Experimental task 1

Task 1-1

task1_1.asm source code

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

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

task1_2.asm source code

assume 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

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

Because the memory space occupied by the program is continuous, and the segment size accounts for an integer multiple of 16 bytes, 4 and 8-byte segments will also occupy 16 bytes, so the result is the same as task1_1 consistent.

Task 1-3

assume 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

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

Because the memory space occupied by the program is continuous, and the segment size accounts for an integer multiple of 16 bytes, the 20 byte segment will also occupy 32 bytes, so the result is this.

Tasks 1-4

task1_4.asm source code

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 line9 and before line11. 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___.

Because the memory space occupied by the program is continuous, and the segment size accounts for an integer multiple of 16 bytes, the 20 byte segment will also occupy 32 bytes, and because the sequence of code segment data segment stack segment changes, the result is this.

Tasks 1-5

xxx segment db N dup(0) xxx ends

① For the segment defined below, after the program is loaded, the actual memory space allocated to the segment is_ ceil(N/16)*16___.

② 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 cannot be executed because they are all the beginning of the data segment. Replacing end start with end means that the program does not specify the start position and will start execution from the beginning, and the data in the execution data segment will naturally make an error. Only task1_4.asm can be executed because it starts with a code snippet.

2. Experimental task 2

Assembly source code

assume cs:code code segment start: mov ax,0b800h mov ds,ax mov bx,0f00h mov cx,80 s: mov [bx],0403h inc bx inc bx loop s mov ah,4ch int 21h code ends end start

Screenshot of operation results

  3. Experimental task 3

Complete assembly source 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 cx,10 mov bx,0 mov dx,0 s: mov ax,data1 mov ds,ax mov 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 ah,4ch int 21h code ends end start

Load, disassemble and debug screenshots in debug

  Before adding data items in turn, check the debug command and screenshot of the original value of memory space data corresponding to logical segments data1, data2 and data3

  After adding in sequence, view the debug command and screenshot of the original value of memory space data corresponding to logical segments data1, data2 and data3

  4. Experimental task 4

Complete assembly source 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,data1 mov ds,ax mov ax,data2 mov ss,ax mov sp,16 mov cx,8 mov bx,0 s: push [bx] add bx,2 loop s mov ah, 4ch int 21h code ends end start

Load, disassemble and debug screenshots in debug

  Before the program exits, use the d command to view a screenshot of the memory space corresponding to data segment data2.

  5. Experimental task 5

task5.asm source code

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

Screenshot of operation results

Use the debug tool to debug the program, and use the g command to execute the screenshot before the program returns (i.e. after ine25 and before line27)

  What is the function of line19 in the source code?

A: convert lowercase letters to uppercase letters.

    and al, 0dfh, where the conversion of 0dfh to binary is 1101 1111(B),

    ASCII codes of capital letters are 0100 0001 ~ 0101 1010,

    Lower case ASCII codes are 0110 0001 ~ 0111 1010,

    After the ASCII code and odfh and of lowercase letters, the 1 of the third bit will become 0, which is converted from lowercase letters to uppercase letters.

What is the purpose of the byte data in the data segment line4 in the source code?

A: set the color of the display content.

Change the fourth line:

6. Experimental task 6

task6.asm source code

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 al,[bx] or al,20h mov [bx],al add bx,16 loop s mov ah, 4ch int 21h code ends end start

Load, disassemble and debug screenshots in debug

  Before the program exits, use the d command to view a screenshot of the memory space corresponding to the data segment data.

  7. Experimental task 7

task7.asm source code

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 cx,5 mov bx,0 mov si,0 mov di,0 mov dx,0 s1: mov ax,[bx] mov es:[si],ax mov ax,[bx+2] mov es:[si+2],ax add bx,4 add si,16 loop s1 ; mov bx,20 mov si,5 mov cx,5 s2: mov ax,[bx] mov es:[si],ax mov ax,0 mov es:[si+2],ax add bx,2 add si,16 loop s2 ;mov bx,30 mov si,10 mov cx,5 s3: mov ax,[bx] mov es:[si],ax add bx,2 add si,16 loop s3 mov si,0 mov cx,5 s4: mov ax, es:[si+5] mov dx, es:[si+7] div word ptr es:[si+10] mov es:[si+13],ax add si,16 loop s4 mov ah, 4ch int 21h code ends end start

View screenshot of original data information of table segment

  Run in debug until the program exits, use the d command to view the screenshot of the memory space corresponding to the table segment, and confirm whether the information is structurally written to the specified memory as required

  5, Experimental summary

  1.or 20h and and 0dfh commands are very practical. The former can convert uppercase letters to lowercase, and the latter can convert lowercase letters to uppercase. The combination of the two can be used flexibly to easily realize the mixed format output of uppercase and lowercase letters.

  2. In order to prevent the register from being "polluted" by unknown data error when calling a register value, it is recommended to set the register that needs to be used but does not have a specific value to 0 in the assignment stage.

6 November 2021, 22:20 | Views: 2890

Add new comment

For adding a comment, please log in
or create account

0 comments