Experimental task 1
-
task1.asm source code:
data segment x db 1, 9, 3 len1 equ $ - x y dw 1, 9, 3 len2 equ $ - y data ends code segment start: mov ax, data mov ds, ax mov si, offset x mov cx, len1 mov ah, 2 s1:mov dl, [si] or dl, 30h int 21h mov dl, ' ' int 21h inc si loop s1 mov ah, 2 mov dl, 0ah int 21h mov si, offset y mov cx, len2/2 mov ah, 2 s2:mov dx, [si] or dl, 30h int 21h mov dl, ' ' int 21h add si, 2 loop s2 mov ah, 4ch int 21h code ends end start
-
Screenshot of operation results:
-
Question ①
-
Screenshot of debug disassembly:
-
Jump displacement: after executing the LOOP 000D command, the IP will automatically add 2 to 001B, and then jump; Therefore, the end address of Loop instruction is 001B. Since the start address of s1 instruction is 000D, 001B-000D=14, the skip shift is 14.
-
-
Question ②
-
Continue disassembly. The screenshot is as follows:
-
Jump displacement: the end address of Loop instruction is 0039 and the start address of s1 instruction is 0029, so the jump displacement is 001B-000D=16
-
Experimental task 2
-
The task2.asm code is as follows:
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.
-
Assemble and link the source program to obtain the executable program task2.exe. Use debug to debug, observe and verify that the debugging results are consistent with the theoretical analysis results. The screenshot of assembly link is as follows:
The screenshot of commissioning results is as follows:
As can be seen from the figure:- After calling word PTR ds: [0], IP=0021. After POP AX is executed, it is pushed into the stack (AX=0021). At this time, IP=0027 is exactly the offset address of s1.
- After executing call word ptr ds:[2], s2: the CS of pop BX and the IP value of the next instruction are successively pressed into the stack (BX=0026, CX=076C). At this time, IP=0028 is exactly the offset address of s2.
Experimental task 3
- The task3.asm code is as follows:
assume cs:code, ds:data data segment x db 99, 72, 85, 63, 89, 97, 55 len equ $- x data ends code segment start: mov ax, data mov ds, ax mov si, 0 mov bl, 10 mov cx, len s: mov ah, 0 mov al, [si] call printNumber call printSpace inc si loop s mov ah, 4ch int 21h printNumber: div bl mov dl, al ;merchant mov bh, ah ;remainder or dl,30H ;Ten bit output mov ah,2 int 21h mov dl, bh ;Bit output or dl,30H mov ah,2 int 21h ret printSpace: mov ah, 2 mov dl, ' ' int 21h ret code ends end start
- The screenshot of running test is as follows:
Experimental task 4
-
task4.asm code is as follows:
assume cs:code, ds:data data segment str db 'try' len equ $ - str data ends code segment start: mov ax,data mov ds,ax mov si,offset str mov cx,len mov bl,00000010b mov bh,1 call printStr mov si,offset str mov cx,len mov bl,00000100b mov bh,23 call printStr mov ah,4ch int 21h printStr: mov ax,0b800h mov es,ax mov ax,0 mov al,bh mov dx,0a0h mul dx mov di,ax s: mov ah,ds:[si] mov es:[di],ah mov es:[di+1],bl add di,2 inc si loop s ret code ends end start
-
The screenshot of running test is as follows:
Experiment task 5
-
The task5.asm code is as follows:
assume cs:code, ds:data data segment stu_no db '201983290448' len = $ - stu_no data ends code segment start: mov ax, data mov ds, ax mov ax, 0b800h mov es, ax mov si, 1 mov dl, 17h mov cx, 2000 s1:mov es:[si], dl add si, 2 loop s1 mov dh, 24 ; mov al, 160 mul dh mov bx, ax call minus mov si, 0 mov cx, len s2:mov dl, [si] mov es:[bx], dl add bx, 2 inc si loop s2 call minus mov ax, 4c00h int 21h minus: mov dl, '-' mov cx, 34 s3:mov es:[bx], dl add bx, 2 loop s3 ret code ends end start
-
The screenshot of running test is as follows:
Experimental summary
- The OFFSET operator returns the OFFSET of the data label. This OFFSET is calculated in bytes and represents the distance from the data label to the starting address of the data segment.
- Experiments need to be careful, and constantly consolidate basic knowledge and enhance practical ability in practice