Experiment 3 transfer instruction jump principle and its simple application programming

Experimental task 1

Give the program task1.asm source code, and run screenshots
 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

Answer question ①
① line27, when the assembly instruction loop s1 jumps, it jumps according to the displacement. Check the machine through debug disassembly
What is the jump displacement of the code? (the displacement value is answered in decimal) from the perspective of CPU, it is explained
How to calculate the offset address of the instruction after the jump label s1.

  The machine code is E2F2. The eight bit binary form of F2 is 11110010, its complement is 10001110, and the decimal form is - 14, that is, the bit shift is 14

CPU: first modify the value of ip by reading the length of the instruction, ip=ip + instruction length, then execute loop s1 and jump to s1. The displacement is equal to the offset address at s1 minus the offset address of the current ip pointing address

Answer question ②
② line44. When the assembly instruction loop s2 jumps, it jumps according to the displacement. Check the machine through debug disassembly
What is the jump displacement of the code? (the displacement value is answered in decimal) from the perspective of CPU, it is explained
How to calculate the offset address of the instruction after the jump label s2.
The machine code of line44 loop command is E2F0. The eight bit binary form of F0 is 11110000, the complement is 10010000, and the decimal form is - 16, that is, the bit shift is 16
CPU: first, modify the value of ip by reading the length of the instruction, ip=ip + instruction length, then execute loop s2 and jump to s2. The displacement is equal to the offset address at s2 minus the offset address of the current ip pointing address
Question ③
③ Attach the disassembly screenshot of debugging observation in debug during the above analysis

 

Experimental task 2
Contents of this part:
The program task2.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
After analysis, debugging and verification, register (ax) =? (bx) = (cx) =? Attach the screenshot of the debugging result interface. ① according to the jump principle of call instruction, first analyze theoretically, register (ax) before program execution and exit (line31)=
? register (bx) =? Register (cx) =?
  call word ptr ds:[0] short transfer, push the offset address (ip) of the next instruction into the stack and transfer it to ds:[0] address, i.e. s1, and then pop ax will stack the content to ax;
  call dword ptr ds:[2] is an inter segment transfer. The base address and offset address (cs and ip) of the next instruction are pushed onto the stack and transferred to the address of ds:[2], that is, s2. Thereafter, pop bx will stack ip to BX and pop cx will stack cs to cx
AX=0021 BX=0026 CX=076C
② Assemble and link the source program to get the executable program task2.exe. Use debug to debug, observe and verify debugging
Whether the results are consistent with the theoretical analysis results.

 

Experimental task 3
Contents of this part:
The program source code task3.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         
13         mov cx, len
14         mov si, 0
15     print:
16         mov al, [si]
17         mov ah, 0
18         call printNumber
19         call printSpace
20         inc si
21         loop print
22  
23         mov ah, 4ch
24         int 21h
25 
26     printNumber:
27         mov bl, 10
28         div bl
29         mov bx, ax
30         
31         mov ah, 2
32  
33         mov dl, bl    ; Printer
34         or dl, 30h
35         int 21h
36  
37         mov dl, bh    ; Print remainder
38         or dl, 30h
39         int 21h
40         ret
41              
42     printSpace:
43         mov ah, 2
44         mov dl, ' '
45         int 21h
46         ret
47  
48 code ends
49 end start
Screenshot of running test

 

Experimental task 4
Contents of this part:
The program source code task4.asm is given
 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 bh, 0   ;Specify the first row
14     mov bl, 2    ;Green characters on black background
15     call printStr
16 
17     mov bh, 24   ;Specify last line
18     mov bl, 4    ;Scarlet letter on black background
19     call printStr
20 
21     mov ah, 4ch
22     int 21h
23 
24 printStr:
25    mov al,0ah  ;160 bytes per line
26    mul bh       ;Multiply by the line number to get the starting address of the line
27    add ax, 0b800h
28    mov es,ax
29 
30     mov cx, len     ;String length
31     mov si, offset str
32     mov di, si
33 s:
34     mov al, [si]
35     mov ah, bl    ;Pass in color attributes
36     mov es:[di], ax       ;Put the characters to be displayed into video memory
37     inc si
38     add di, 2
39     loop s
40     ret
41 code ends
42 end start

 

Screenshot of running test

 

 

Experimental task 5
Contents of this part:
The program source code task5.asm is given
 1 assume cs:code, ds:data
 2 
 3 data segment
 4     stu_no db '201983290032' 
 5     len = $ - stu_no 
 6 data ends
 7 
 8 code segment
 9 start:
10     mov ax, data
11     mov ds, ax
12     mov di, 0
13 
14     call printStuNum
15     
16     mov ah, 4ch
17     int 21h
18 
19 printStuNum:
20     mov ax, 0b800h
21     mov es, ax
22     mov si, 1
23 
24     mov al, 24
25     mov dl, 80
26     mul dl
27     
28     mov cx, ax
29     printBlue:
30         mov al, 17h    ;00010111
31         mov es:[si], al    ;fill color
32         add si, 2
33     loop printBlue
34 
35     sub si, 1
36     mov ax, 80
37     sub ax, len
38     mov dl, 2
39     div dl
40     mov dx, ax    ;preservation-Length of
41 
42     mov cx, dx
43     call printheng
44 
45     mov cx, len
46     printStu:    ;Output student number
47         mov al, ds:[di]
48         mov ah, 17h
49         mov word ptr es:[si], ax
50         inc di
51         add si, 2
52     loop printStu
53 
54     mov cx, dx
55     call printheng
56 
57     ret
58     
59 printheng:
60     mov al, '-'
61     mov ah, 17h
62     mov word ptr es:[si], ax
63     add si, 2
64     loop printheng
65     ret
66      
67 code ends
68 end start

 

Screenshot of running test

 

 

 

 

 

 

 

 

 

Posted on Sun, 28 Nov 2021 03:36:11 -0500 by gavinandresen