Experiment 3 transfer instruction jump principle and its simple application programming

1. Experimental task 1 use any text editor to enter the 8086 assembler source code task1.asm.

task1.asm

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

Assemble and link the source program to obtain the executable program task1.exe. After running, combined with the running results and comments, and necessary debug ging:

 

 

 

 

1. Understand the flexible use of operator offset, pseudo instruction equ and predefined symbol $. Through line5, line8 and the data attributes of data items (bytes, words, doublewords, etc.), the number of continuous data items can be calculated easily without manual counting.

Note *: the symbolic constants len1 and len2 do not occupy the memory space of the data segment

2. Answer questions

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

The machine code E2F2 of Loop, the displacement is F2 (1111 0010), and the inverse code is 1111 0001, so the original code is 1000 1110 (- 14)

From the perspective of cpu: the loop instruction modifies the ip to point to 000DH, and the ip of the next instruction of the loop instruction is 001BH, then the displacement is 0DH-1BH=13-27=-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. ③ Attach the disassembly screenshot of debugging observation in debug during the above analysis

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

 

 

 

2. Experimental task 2 use any text editor to 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 theoretically analyzed that before the program is executed to exit (line31), register (ax) =0021h and register (bx) =0026h   Register (cx) = 076ch

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

 

 

3. Experiment task 3 is for 8086 CPU. The known logic 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 the 8086 assembly source program task3.asm to output this group of continuous data in the data section in decimal form on the screen, and the data is separated by spaces.

requirement:

Write subroutine printNumber

Function: output a two digit number in decimal form

Entry parameter: register ax (data to be output -- > ax)

Exit parameter: printSpace without writing subroutine

Function: print a space

Entry parameters: None

Outlet parameters: None

In the main code, the addressing mode and loop are comprehensively applied, and printNumber and printSpace are called to realize the subject requirements.

When correctly written, the expected test results are as follows:

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

 

 

4. Experiment task 4 is for 8086 CPU. The known logic segment is defined as follows:

1 ; Function: output single character
2 mov ah, 2
3 mov dl, ×× ; ××Is the character to be output, or its ASCⅡCode value
4 int 21h
 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 cx,len
14    mov si,offset str
15    mov bh,0
16    mov bl,2
17    call printStr
18    
19    mov cx,len
20    mov si,offset str
21    mov bh,24
22    mov bl,4
23    call printStr
24    
25    mov ah,4ch
26    int 21h
27 printStr:
28    ;Address of segment corresponding to calculation line
29    mov al,0ah
30    mul bh
31    add ax,0b800h
32    mov es,ax
33 
34    mov di,si
35    ;Write to video memory
36 s: mov al,ds:[si]
37    mov ah,bl
38    mov es:[di],ax
39    inc si
40    add di,2
41    loop s
42    ret
43 code ends
44 end start

 

 

  5. Experiment task 5 is for 8086 CPU. For 8086 CPU, the known logic segment is defined as follows:

1 data segment
2 stu_no db '20498329042'
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.

 1 assume cs:code,ds:data
 2 
 3 data segment
 4     stu_no db '201983290376'
 5     len = $-stu_no
 6 data ends
 7 stack segment
 8     dw 2 dup(0)
 9 stack ends
10 code segment
11 start:
12     ;White characters on blue background
13     mov bl,00010111b
14     mov bh,' '
15     mov ax,stack
16     mov ss,ax
17     mov sp,2
18     mov ax,data
19     mov ds,ax
20     mov si,0
21     mov cx,25
22     ;Fill background
23 fillBg:
24     mov al,0ah
25     mov dx,si
26     mul dl
27     add ax,0b800h
28     mov es,ax
29     push cx
30     push si
31     mov cx,050h
32     mov si,1
33     ;Inner loop, fill one line
34 fillBgLine:
35     mov es:[si],bx
36     add si,2
37     loop fillBgLine
38     
39     pop si
40     pop cx
41     inc si
42     loop fillBg
43     
44     ;Process last line
45     mov dx,028h
46     sub dx,len/2    ;2dx Is the number of polylines
47     mov si,0
48     ;Output front polyline
49     call printLine
50     ;Output student number
51     mov cx,len
52     mov di,offset stu_no
53 no: mov al,ds:[di]
54     mov es:[si],al
55     inc di
56     add si,2
57     loop no
58     call printLine
59     
60     mov ah,4ch
61     int 21h    
62 printLine:
63     mov cx,dx
64 s:    mov es:[si],byte ptr '-'
65     add si,2
66     loop s
67     ret
68 
69 code ends
70 end start

 

  summary

1. Have a better understanding and mastery of the jump principle of transfer instruction

2. Use call and ret instructions to realize subroutine programming, and have a basic understanding of its and its parameter transmission mode

3. Master the display principle and programming of color character mode

 

Posted on Sun, 28 Nov 2021 09:21:17 -0500 by rosieraz