Experiment 3: transfer instruction jump principle and its simple application programming

Experiment 3: transfer instruction jump principle and its simple application programming ...
Experiment task 1:
Experiment task 2:
Experiment task 3:
Experiment task 4:
Experiment task 5:
Experiment 3: transfer instruction jump principle and its simple application programming

Experiment task 1:

  • The program test1.asm source code and running screenshot are given

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

Operation results:

  • ① 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: the machine code of the loop instruction is E2F2. At this time, 000D stored in the loop is the offset address 000D to jump. When the CPU executes the loop instruction, it will directly change the IP to 000D, and then the CPU obtains the physical address 076B:000D of the next instruction according to CS:IP to complete the jump.

  • ② 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: the machine code of the loop instruction is E2F0. At this time, 0029 stored in the loop is the offset address 0029 to jump. When the CPU executes the loop instruction, it will directly change the IP to 0029, and then the CPU obtains the physical address 076B:0029 of the next instruction according to CS:IP to complete the jump.

Experiment task 2:

  • The program test2.asm source code is given

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: through learning, we can know that the jump principle of call is to press the corresponding IP or CS:IP into the stack. Before the program exits, the call instruction is executed twice. The first call instruction presses the word data of ds:[0], that is, IP into the stack, then ax=0021. The second call instruction presses the double word data of ds:[2], that is, DS:IP into the stack, DS into CX, IP into BX, then bx=0026, cx=076C.

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

Experiment task 3:

  • The program source code test3.asm is given

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 mov cx,len 13 mov si,0 14 15 s: mov ah,0 16 mov al,[si] 17 mov bx,offset printnumber 18 call bx 19 mov bx,offset printSpace 20 call bx 21 inc si 22 loop s 23 mov ah, 4ch 24 int 21h 25 26 printnumber: 27 mov bl,10 28 div bl 29 mov bx,ax 30 mov ah,2 31 mov dl,bl 32 or dl,30h 33 int 21h 34 mov dl,bh 35 or dl,30h 36 int 21h 37 ret 38 39 printSpace: 40 mov ah,2 41 mov dl,' ' 42 int 21h 43 ret 44 code ends 45 end start

  • Screenshot of running test

Experiment task 4:

  • The program source code test4.asm is given

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

Experiment task 5:

  • The program source code test5.asm is given

1 assume cs:code, ds:data 2 data segment 3 stu_no db '201983290152' 4 len = $ - stu_no 5 data ends 6 7 code segment 8 start: 9 mov ax, data 10 mov ds, ax 11 mov ax, 0b800h 12 mov es, ax 13 mov bl, 017h 14 mov si, 0 15 mov di, 0 16 mov al, 050h 17 mov bh, 18h 18 mul bh 19 20 mov cx, ax 21 s: mov es:[di+1], bl 22 add di, 2 23 loop s 24 25 mov cx, 022h 26 s1: mov byte ptr es:[di], '-' 27 mov es:[di+1], bl 28 add di, 2 29 loop s1 30 31 mov cx, len 32 s2: mov al, [si] 33 mov es:[di], al 34 mov es:[di+1], bl 35 inc si 36 add di, 2 37 loop s2 38 39 mov cx, 023h 40 s3: mov byte ptr es:[di], '-' 41 mov es:[di+1], bl 42 add di, 2 43 loop s3 44 45 code ends 46 end start
  • Screenshot of running test

30 November 2021, 07:15 | Views: 8631

Add new comment

For adding a comment, please log in
or create account

0 comments