Experiment 3 transfer instruction jump principle and its simple application programming

1. 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
Assemble and link the source program to get the executable program task1.exe. After running, combined with the running results, comments and necessary debug
Commissioning:
1. Understand the flexible use of operator offset, pseudo instruction equ and predefined symbol $.
Continuous data items can be easily calculated through line5, line8 and data attributes (bytes, words, doublewords, etc.) of data items
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.
 

  8-bit displacement = 001D-0027=-14   Indicates that the loop s instruction is moved forward by 14 bytes after execution.

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

  8-bit displacement = 0019-0029 = - 16   Indicates that the loop s instruction is moved forward by 16 bytes after execution.

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

2. 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) = 0021 register (bx) = 0026 register (cx) = 076c

 

 

② 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 result is correct
3. Experimental task 3
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 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)
                Outlet parameters: None
        Write the subroutine printSpace
       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.
The description of sub function 2 in attachment *: int 21h is as follows:
1 ; Function: output single character
2 
3 mov ah,2
4 mov dl,  xx        ;xx Is the character to be output, or its ASCII Code value
5 int 21h

  Experiment 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 
12         mov cx,len    ;
13         mov si,0
14        
15 s:    
16         mov ah,0
17         mov al,ds:[si]        ;2 Bits, one byte, in al storage
18         call printNumber
19         call printSpace
20         inc si
21         loop s
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      ;merchant
34         or dl,30h
35         int 21h
36                   
37         mov dl,bh      ;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

 

Result screenshot:

 

 

4. Experimental 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 8086 assembly source program task4.asm, specify the color and line on the screen, and output the string on the screen.
requirement:
Write subroutine printStr
Function: display the string on the screen in the specified line and in the specified color
Entry parameters
The address of the first character of the string -- > ds: Si (where, the segment address of the segment where the string is located -- > DS, and the offset address of the starting address of the string -- > SI)
String length -- > CX
String color -- > bl
Specified line -- > BH (value: 0 ~ 24)
Outlet parameters: None
In the main code, printStr is called twice to display the string in green on a black background at the top of the screen and in red on a black background at the bottom of the screen
Experiment code:
 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 ax,0b800h
12     mov es,ax
13 
14     mov si,offset str
15     mov bl,     2    ;Specifies that the string color is green on a black background
16     mov bh,    0    ;Specify the first line of the behavior
17     
18     call printStr
19 
20     mov si,offset str
21     mov bl,   4       ; Specifies that the string color is red on a black background
22     mov bh, 24      ;Specify the last line of the behavior
23    
24     call printStr
25 
26     mov ah, 4ch
27     int 21h
28 
29 printStr:
30     mov al, 160
31     mul bh
32 
33     mov cx,len
34     mov di, ax     
35 s:
36     mov ah, ds:[si]
37     mov es:[di], ah
38     inc di
39     mov es:[di], bl
40     inc si
41     inc di
42     loop s
43     ret
44 
45 code ends
46 end start

 

Result screenshot:

 

 


5. Experimental task 5
For 8086CPU, for 8086CPU, the known logical 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.
Experiment code:
 1 assume cs:code
 2 
 3 data segment
 4     stu_no db '201983290122'
 5     len = $ - stu_no
 6 data ends
 7 
 8 code segment
 9 start:
10     mov ax,data
11     mov ds,ax
12     mov ax,0b800h
13     mov es,ax
14     call p1
15     
16     mov bh,24
17     mov al,160
18     mul bh
19     mov bx,ax
20     call p2
21     call p3
22     call p2
23 
24     mov ax,4c00h
25     int 21h
26 
27 p2:
28     mov al,'-'
29     mov dl,17h
30     mov cx,34
31     s:
32     mov es:[bx],al
33     inc bx
34     mov es:[bx],dl
35     inc bx
36     loop s
37 ret
38 
39 
40 p1:
41     mov si,1
42     mov bl,17h
43     mov cx,7d0h
44     s2:
45     mov es:[si],bl
46     add si,2
47     loop s2
48 ret
49 
50 p3:
51     mov si,0
52     mov dl,17h
53     mov cx,len
54     s1:
55     mov al,ds:[si]
56     mov es:[bx],al
57     inc bx
58     mov es:[bx],dl
59     inc bx
60     inc si
61     loop s1
62 ret
63 
64 
65 
66 code ends
67 end start

 

Result screenshot:

 

 


Note *:
1. 80 × 25 color character mode display buffer structure, see the description in the textbook "experiment 9 programming according to materials".
2. When writing the program, replace the student number of the data segment with your own student number.
 

Posted on Fri, 03 Dec 2021 05:25:49 -0500 by kansaschuck