Experiment 3 transfer instruction jump principle and its simple application programming

Experimental task 1 Using any text editor, enter the 8086 assembler source code task1.asm. task1.asm 1 assume cs:code,...
Experimental task 1
Experimental task 2
  Experimental task 3
Experimental task 4
Experimental task 5

Experimental task 1

Using any text editor, enter the 8086 assembler source code task1.asm.

task1.asm

1 assume cs:code, ds:data 2 3 data segment 4 x db 1, 9, 3 5 len1 equ $ - x 6 7 y dw 1, 9, 3 8 len2 equ $ - y 9 data ends 10 11 code segment 12 start: 13 mov ax, data 14 mov ds, ax 15 16 mov si, offset x 17 mov cx, len1 18 mov ah, 2 19 s1:mov dl, [si] 20 or dl, 30h 21 int 21h 22 23 mov dl, ' ' 24 int 21h 25 26 inc si 27 loop s1 28 29 mov ah, 2 30 mov dl, 0ah 31 int 21h 32 33 mov si, offset y 34 mov cx, len2/2 35 mov ah, 2 36 s2:mov dx, [si] 37 or dl, 30h 38 int 21h 39 40 mov dl, ' ' 41 int 21h 42 43 add si, 2 44 loop s2 45 46 mov ah, 4ch 47 int 21h 48 code ends 49 end start

question answering:

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

A: it can be seen from E2F2 that the displacement is F2 and the decimal is - 14, so the jump displacement is - 14. When loop is executed, the offset address of ip pointing to the next instruction is 00190019h + f2h, which is the offset address of label s1

② 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.

       A: according to E2F0, the displacement is F0, and the decimal system is - 16,   Therefore, the jump displacement is - 16. When loop is executed, the offset address of ip pointing to the next instruction is 00390039h + F0H, which is the offset address of label s2

③ Attach the disassembly screenshot of debugging observation in debug during the above analysis

Screenshot:

Experimental task 2

Using any text editor, enter the 8086 assembler source code task2.asm.

task2.asm

1 assume cs:code, ds:data 2 3 data segment 4 dw 200h, 0h, 230h, 0h 5 data ends 6 7 stack segment 8 db 16 dup(0) 9 stack ends 10 11 code segment 12 start: 13 mov ax, data 14 mov ds, ax 15 16 mov word ptr ds:[0], offset s1 17 mov word ptr ds:[2], offset s2 18 mov ds:[4], cs 19 20 mov ax, stack 21 mov ss, ax 22 mov sp, 16 23 24 call word ptr ds:[0] 25 s1: pop ax 26 27 call dword ptr ds:[2] 28 s2: pop bx 29 pop cx 30 31 mov ah, 4ch 32 int 21h 33 code ends 34 end start

① According to the jump principle of call instruction, it is analyzed theoretically that before the program executes to exit (line31), register (ax) =? Register (bx) =? Register (cx) =?

Answer: (ax) = offset address of label s1, (bx) = offset address of label s2, (cx) is the value of cs register.

② Assemble and link the source program to get the executable program task2.exe. Use debug to observe and verify whether the debugging results are consistent with the theoretical analysis results.

The analysis is consistent with the results

  Experimental task 3

Source code:

1 assume cs:code, ds:data 2 data segment 3 x db 99, 72, 85, 63, 89, 97, 55 4 len equ $- x 5 data ends 6 7 code segment 8 start: 9 mov ax,data 10 mov ds,ax 11 mov si,offset x 12 mov cx,len 13 14 s: 15 call printNumber 16 call printSpace 17 inc si 18 loop s 19 mov ah, 4ch 20 int 21h 21 22 printNumber: 23 mov ah,0 24 mov al,[si] 25 mov bl,10 26 div bl 27 28 mov bx,ax 29 mov ah,2 30 mov dl,bl 31 or dl, 30h 32 int 21h 33 34 mov ah, 2 35 mov dl, bh 36 or dl, 30h 37 int 21h 38 ret 39 40 printSpace: 41 mov ah, 2 42 mov dl, ' ' 43 int 21h 44 ret 45 46 code ends 47 end start

result:

Same as expected

Experimental task 4

Source code:

1 assume cs:code,ds:data 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 bl, 2 14 mov bh, 0 15 call printStr 16 17 mov bl, 4 18 mov bh, 24 19 call printStr 20 21 mov ax, 4c00h 22 int 21h 23 24 printStr: 25 mov ax, 0b800h 26 mov es, ax 27 28 mov si, offset str 29 mov cx, len 30 31 mov al,0A0h 32 mul bh 33 mov di, ax 34 35 s: mov al,[si] 36 mov es:[di], al 37 mov es:[di+1], bl 38 inc si 39 add di, 2 40 loop s 41 ret 42 43 code ends 44 end start

  The results are the same as expected

Experimental task 5

Source code:

1 assume cs:code, ds:data 2 3 data segment 4 stu_no db '201983290272' 5 len = $ - stu_no 6 data ends 7 8 code segment 9 start: 10 mov ax, data 11 mov ds, ax 12 13 mov ax, 0b800h 14 mov es, ax 15 mov al, 24 16 mov dl, 80 17 mul dl 18 mov cx, ax 19 mov di, 0 20 21 s1:mov al, 17h ;Except for the last line, the page is set in blue 22 mov es:[di], byte ptr 20h 23 mov es:[di+1], al 24 add di, 2 25 loop s1 26 27 mov ax, 00a0h 28 mov bh, 24 29 mul bh 30 mov di, ax 31 call printStr 32 33 mov si, offset stu_no 34 mov cx, len 35 call printNum 36 37 call printStr 38 39 mov ah, 4ch 40 int 21h 41 42 printStr: 43 mov ax, 80 44 sub ax, len 45 mov bl, 2 46 div bl 47 mov ch, 0 48 mov cl, al 49 50 s2:mov ah, 17h 51 mov al, '-' 52 mov es:[di], ax 53 add di, 2 54 loop s2 55 ret 56 57 printNum: 58 s3:mov ah, 17h 59 mov al, [si] 60 mov es:[di], ax 61 inc si 62 add di, 2 63 loop s3 64 ret 65 66 code ends 67 end start


The screenshot of the result is as follows

The results are the same as expected

2 December 2021, 17:58 | Views: 5352

Add new comment

For adding a comment, please log in
or create account

0 comments