Experiment 3 transfer instruction jump principle and its simple application programming

Task 1

Input 8086 assembler source code task1.asm

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

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

 

  After the cpu reads the loop s1 instruction, the IP value is 001Bh, and it needs to jump to the address of 000Dh. Therefore, the displacement is: target address - current address = - 14

 

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

After the cpu reads the loop s2 instruction, the IP value is 0039h, and it needs to jump to address 0029h, so the displacement is: - 16

 

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

As shown above

 

Task 2

Enter 8086 assembler source code 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) =?

ax = s1,bx = s2,cx = cs

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

  From the above figure, s1=0021h, s2=0026h, cs=0772h

  The results are consistent with the theoretical analysis

 

 

Task three

For 8086 CPU, the known logical segment is defined as follows:

1 data segment
2     x db 99, 72, 85, 63, 89, 97, 55
3     len equ $- x
4 data ends

Write 8086 assembly source program task3.asm, and output this group of continuous data in the data section in decimal form on the screen. The data is separated by spaces

 1 assume cs:code, ds:data, ss:stack
 2 data segment
 3     x db 99, 72, 85, 63, 89, 97, 55
 4     len equ $- x
 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     mov ax,0b800h
16     mov es,ax
17     
18     
19     mov bx,0
20     mov si,0
21     
22     mov dx,offset printNumber
23     call dx        ;Print character
24     mov bx,0
25     mov si,4
26     mov dx,offset printSpace
27     call dx        ;Print spaces
28     
29     mov ah,4ch
30     int 21h
31     
32 printNumber:
33     mov cx,7h
34 s1: mov al,ds:[bx]
35     mov ah,0
36     mov dx,10    ;Separate ten bits from one bit
37     div dl
38     mov dl,10h
39     mov dh,ah
40     or al,30h
41     ;Print ten digits
42     mov ah,7
43     mov es:[si],ax
44     inc bx
45     add si,2
46     ;Print everyone
47     mov al,dh
48     or al,30h
49     mov es:[si],ax
50     add si,4
51     
52     loop s1
53     ret
54 printSpace:
55     mov cx,7h
56 s2:    mov al,' '
57     mov ah,7
58     mov es:[si],ax
59     add si,6
60     loop s2
61     ret
62 code ends
63 end start

 

 

 

Task 4

For 8086 CPU, the known logical segment is defined as follows:

1 data segment
2     str db 'try'
3     len equ $ - str
4 data ends

Write the 8086 assembly source program task4.asm, specify the color and line on the screen, and output the string on the screen:

 1 assume cs:code, ds:data
 2 
 3 data segment
 4     s db 'try'
 5     len equ $ - s
 6 data ends
 7 
 8 code segment
 9 start:
10     mov ax,data
11     mov ds,ax
12     mov si,offset s
13     mov bp,0
14     mov bl,2
15     mov bh,0
16     
17     mov dx,printStr
18     call dx
19     mov si,offset s
20     mov bp,0
21     mov bl,4
22     mov bh,0f0h
23     mov dx,printStr
24     call dx
25     
26     mov ah,4c
27     int 21h
28 
29 
30 printStr:
31     mov ah,0b8h
32     mov al,bh
33     mov es,ax
34     mov cx,len
35 s1: mov dl,ds:[si]
36     mov es:[bp],dl
37     inc bp
38     mov es:[bp],bl
39     inc bp
40     inc si
41     loop s1
42     ret
43 
44 code ends
45 end start

 

 

Task 5

For 8086 CPU, for 8086 CPU, the known logical segment is defined as follows

1 data segment
2     stu_no db '201983290497'
3     len = $ - stu_no
4 data ends

At 80 × In 25 color character mode, the student number is displayed in the middle of the last line of the screen. It is required that the student number and broken lines on both sides of the output window are displayed in white foreground color on a blue background:

 1 assume cs:code, ds:data
 2 data segment
 3     stu_no db '201983290497'
 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 si,offset stu_no
14     
15     mov cx,780h
16     mov ah,10h
17     mov al,' '
18     mov bx,0
19 s1:    mov es:[bx],ax        ;Dye all except the last line with a blue background
20     add bx,2
21     loop s1
22     
23     mov dx,offset print
24     call dx
25     mov cx,len
26     mov ah,17h            ;The binary of white characters on blue background is 00010111,16 Hexadecimal 27
27 s3:    mov al,ds:[si]
28     mov es:[bx],ax
29     add bx,2
30     inc si
31     loop s3
32     
33     call dx
34     mov ah,4ch
35     int 21h
36     
37 print:
38     mov cx,22h
39     mov ah,17h
40     mov al,'-'
41 s2:    mov es:[bx],ax
42     add bx,2
43     loop s2    
44     ret
45     
46 code ends
47 end start

 

 

summary

① Through the comprehensive utilization of call, ret and addressing methods, the function of a certain section of code can be regarded as a function and can be called in the main code

② B8000H~BFFFFH display buffer has a total space of 32KB. 80x25 color mode indicates that 25 characters can be displayed in total and 80 characters per line. After setting b8, the address is calculated from the first character position of the first line to the last character position ff of the last line

 

Posted on Tue, 30 Nov 2021 12:16:53 -0500 by frao_0