3, Experimental content
1. Experimental task 1
Program source code task3_1.asm
1 assume cs:code, ds:data 2 data segment 3 x db 1, 9, 3 4 len1 equ $ - x ; symbolic constants , $Refers to the offset address of the next data item. In this example, it is 3 5 y dw 1, 9, 3 6 len2 equ $ - y ; symbolic constants , $Refers to the offset address of the next data item. In this example, it is 9 7 data ends 8 code segment 9 start: 10 mov ax, data 11 mov ds, ax 12 mov si, offset x ; Take symbol x Corresponding offset address 0 -> si 13 mov cx, len1 ; From symbol x Number of consecutive byte data items at the beginning -> cx 14 mov ah, 2 15 s1:mov dl, [si] 16 or dl, 30h 17 int 21h 18 19 mov dl, ' ' 20 int 21h ; Output space 21 inc si 22 loop s1 23 mov ah, 2 24 mov dl, 0ah 25 int 21h ; Line feed 26 mov si, offset y ; Take symbol y Corresponding offset address 3 -> si 27 mov cx, len2/2 ; From symbol y Number of consecutive word data items started -> cx 28 mov ah, 2 29 s2:mov dx, [si] 30 or dl, 30h 31 int 21h 32 mov dl, ' ' 33 int 21h ; Output space 34 add si, 2 35 loop s2 36 mov ah, 4ch 37 int 21h 38 code ends 39 end start
Screenshot of running test

Problem ① line27: when the assembly instruction loop s1 jumps, it jumps according to the displacement. Check the machine code through debug disassembly and analyze the jump displacement? (the displacement value is answered in decimal) from the perspective of the CPU, explain how to calculate the offset address of the instruction after the jump label s1.
Disassembly screenshot:

A: as shown in the figure, E2 represents loop, F2 represents the offset in the form of complement, which is converted into binary to 11110010, and then converted into original code to 10001110, corresponding to decimal number - 14, so the jump displacement is - 14.
When executing the instruction loop s1, the IP is 0019, and IP+2 is 001B. On this basis, the IP after adding the displacement - 14 is 000D, so as to realize jump.
Problem ② line44: when the assembly instruction loop s2 jumps, it jumps according to the displacement. Check the machine code through debug disassembly and analyze the jump displacement? (the displacement value is answered in decimal) from the perspective of the CPU, explain how to calculate the offset address of the instruction after the jump label s2.
Disassembly screenshot:

Answer: the same as the steps in question ①. The original code of F0 is 10010000 and the corresponding decimal number is - 16, so the skip shift is - 16; The corresponding s2 offset address is 55 + 2-16 = 41.
2. Experimental task 2
Program source code task3_2.asm
assume cs:code, ds:data data segment dw 200h, 0h, 230h, 0h data ends stack segment db 16 dup(0) stack ends code segment start: mov ax, data mov ds, ax mov word ptr ds:[0], offset s1 mov word ptr ds:[2], offset s2 mov ds:[4], cs mov ax, stack mov ss, ax mov sp, 16 call word ptr ds:[0] s1: pop ax call dword ptr ds:[2] s2: pop bx pop cx mov ah, 4ch int 21h code ends end start
According to the jump principle of call instruction, it is theoretically analyzed that before the program executes to exit (line31), register (ax) should be the offset address of s1, register (bx) should be the offset address of s2, and register (cx) should be the segment address of cs.
Screenshot of debugging result interface:


The debugging results are consistent with the theoretical analysis results.
3. Experimental task 3
Program source code task3_3.asm
1 assume cs:code, ds:data 2 3 data segment 4 x db 99,72,85,63,89,97,55 5 len equ $ - x 6 data ends 7 8 code segment 9 start: 10 mov ax,data 11 mov ds,ax 12 13 mov si,offset x 14 mov cx,len 15 mov byte ptr ds:[10], 10 16 17 s1: 18 mov ah, 0 19 mov al, ds:[si] 20 div byte ptr ds:[10] 21 22 call printNumber 23 call printSpace 24 25 inc si 26 loop s1 27 28 mov ah,4ch 29 int 21h 30 31 printNumber: 32 mov bx,ax 33 mov ah, 2 34 35 mov dl,al 36 or dl, 30h 37 int 21h 38 39 mov dl,bh 40 or dl,30h 41 int 21h 42 ret 43 printSpace: 44 mov ah, 2 45 mov dl,' ' 46 int 21h 47 ret 48 49 code ends 50 end start
Screenshot of running test:

4. Experimental task 4
Program source code task3_4.asm
1 assume ds:data, cs:code 2 3 data segment 4 str db 'try' 5 len equ $ - str 6 data ends 7 8 code segment 9 start: 10 mov ax,data 11 mov ds,ax 12 13 mov si,0 14 mov cx,len 15 mov bh,0 16 mov bl,00000010B 17 call printStr 18 19 mov si,0 20 mov cx,len 21 mov bh,24 22 mov bl,00000100B 23 call printStr 24 25 mov ax,4c00h 26 int 21h 27 28 29 printStr: 30 mov ax,0b800h 31 mov es,ax 32 33 mov al,bh 34 mov bh,0a0h 35 mul bh 36 mov bp,ax 37 s: 38 mov ah,ds:[si] 39 mov es:[bp],ah 40 inc bp 41 mov es:[bp],bl 42 inc bp 43 inc si 44 loop s 45 ret 46 47 code ends 48 end start
Screenshot of running test:

5. Experimental task 5
Program source code task3_5.asm
1 assume cs:code, ds:data 2 3 data segment 4 stu_no db '20192375030' 5 len = $ - stu_no 6 data ends 7 8 code segment 9 start: 10 mov ax, data 11 mov ds, ax 12 mov ax, 0b800h 13 mov es, ax 14 15 mov si, 1 16 mov dl, 17h 17 mov cx, 2000 18 bc:mov es:[si], dl 19 add si, 2 20 loop bc 21 22 mov dh, 24 23 mov al, 160 24 mul dh 25 mov bx, ax 26 call minus 27 28 mov si, 0 29 mov cx, len 30 s1:mov dl, [si] 31 mov es:[bx], dl 32 add bx, 2 33 inc si 34 loop s1 35 36 call minus 37 mov ax, 4c00h 38 int 21h 39 40 minus: 41 mov dl, '-' 42 mov cx, 34 43 s:mov es:[bx], dl 44 add bx, 2 45 loop s 46 ret 47 code ends 48 end start
Screenshot of running test:
