Experiment 3 transfer instruction jump principle and its simple application programming

1, Experimental purpose 1. Understand and master the jump...

1, Experimental purpose

1. Understand and master the jump principle of transfer instruction

2. Master the method of using call and ret instructions to realize subroutines, and understand and master the parameter transfer mode

3. Understand and master 80 × 25 color character mode display principle

4. Integrate addressing mode and assembly instructions to complete simple application programming

2, Experimental preparation

Review chapters 9-10 of the textbook:

1. Jump principle of transfer instruction

2. Usage of assembly instructions jmp, loop, jcxz, call, ret, retf

3, Experimental content

1. Experimental task 1

Using any text editor, enter the 8086 assembler source code 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:

  In code   mov si, offset x displays mov si, 0000 when executing. You can know that the offset address of X is 0, which is the initial address; mov cx, len1 displays mov cx, 0003. It can be concluded that the offset address of len1 is the offset address of the next data item.

  At the end of execution, the results obtained and the parameter values.

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

  Execute the loop s1 instruction to jump to the position of 000D, that is, s1.

Displacement calculation method:

E2 represents loop, F2 represents offset 11110010 in complement form, converted to original code form: 10001110, converted to decimal number: - 14,

The current address 0019 is converted to decimal 25, 25 - 14 = 11. Take the instruction first, then offset the address + 2, change to 13, and convert to hexadecimal 000D, which is exactly where s1 is located.

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

  The calculation method is the same as that in question ①. F0 = 11110000, converted to original code = 10010000, converted to decimal number - 16, current position 0037 is 55, 55 - 16 = 39, after taking the instruction + 2, it is 41, converted to hexadecimal number 0029, which is exactly the offset address of s2.

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 data segment 3 dw 200h, 0h, 230h, 0h 4 data ends 5 stack segment 6 db 16 dup(0) 7 stack ends 8 9 code segment 10 start: 11 mov ax, data 12 mov ds, ax 13 14 mov word ptr ds:[0], offset s1 15 mov word ptr ds:[2], offset s2 16 mov ds:[4], cs 17 18 mov ax, stack 19 mov ss, ax 20 mov sp, 16 21 22 call word ptr ds:[0] 23 s1: pop ax 24 25 call dword ptr ds:[2] 26 s2: pop bx 27 pop cx 28 mov ah, 4ch 29 int 21h 30 code ends 31 end start

① According to the jump principle of call instruction, it is theoretically analyzed that before the program executes to exit (line31),

Register (ax) = offset s1

Register (bx) = offset s2

Register (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.

ax result verification:

  bx result verification:

  cx result verification:

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.

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 code segment 7 start: 8 mov ax,data 9 mov ds,ax 10 mov byte ptr ds:[len],10 11 mov cx,7 12 mov bx,0 13 s: mov al,ds:[bx] 14 mov ah,0 15 inc bx 16 call printNumber 17 call printSpace 18 loop s 19 mov ah,4ch 20 int 21h 21 printNumber: 22 div byte ptr ds:[len] 23 mov dx,ax 24 mov ah,2 25 or dl,30h 26 int 21h 27 mov ah,2 28 mov dl,dh 29 or dl,30h 30 int 21h 31 ret 32 printSpace: 33 mov dl,' ' 34 mov ah,2 35 int 21h 36 ret 37 code ends 38 end start

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.

1 assume cs:code,ds:data 2 data segment 3 str db 'try' 4 len equ $ - str 5 data ends 6 stack segment 7 db 16 dup(0) 8 stack ends 9 code segment 10 start: 11 mov ax,data 12 mov ds,ax 13 ; mov byte ptr ds:[len],160 14 mov ax,stack 15 mov ss,ax 16 mov sp,16 17 18 mov bl,00000010B 19 mov bh,0 20 mov cx,3 21 mov si,0 22 call printStr 23 24 mov bl,00000100B 25 mov bh,24 26 mov cx,3 27 mov si,0 28 call printStr 29 30 mov ah,4ch 31 int 21h 32 printStr: 33 mov ax,0b800h;Video memory address 34 mov es,ax 35 36 mov ax,0 37 mov al,bh;Line number 38 mov dx,160 39 mul dx 40 mov di,ax 41 42 s: mov al,ds:[si] 43 mov es:[di],al 44 inc si 45 inc di 46 mov es:[di],bl 47 inc di 48 loop s 49 ret 50 code ends 51 end start

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.

1 assume cs:code, ds:data 2 data segment 3 stu_no db '201983290055' 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 14 mov si, 1 15 mov dl, 17h 16 mov cx, 2000 17 bc:mov es:[si], dl 18 add si, 2 19 loop bc 20 21 mov dh, 24 ;Line number 22 mov al, 160 23 mul dh 24 mov bx, ax 25 call minus 26 27 mov si, 0 28 mov cx, len 29 s1:mov dl, [si] 30 mov es:[bx], dl 31 add bx, 2 32 inc si 33 loop s1 34 35 call minus 36 mov ax, 4c00h 37 int 21h 38 39 minus: 40 mov dl, '-' 41 mov cx, 34 42 s:mov es:[bx], dl 43 add bx, 2 44 loop s 45 ret 46 code ends 47 end start

Experimental summary

1. In this experiment, we have a full understanding of offset and call instructions.

assume cs:code, ds:datadata segment stu_no db '201983290055' len = $ - stu_nodata ends
code segmentstart: mov ax, data mov ds, ax mov ax, 0b800h mov es, ax
mov si, 1 mov dl, 17h mov cx, 2000 bc:mov es:[si], dl add si, 2 loop bc
    mov dh, 24; line number     mov al, 160     mul dh     mov bx, ax     call minus
mov si, 0 mov cx, len s1:mov dl, [si] mov es:[bx], dl add bx, 2 inc si loop s1
call minus mov ax, 4c00h int 21h
minus: mov dl, '-' mov cx, 34 s:mov es:[bx], dl add bx, 2 loop s retcode endsend start

29 November 2021, 07:29 | Views: 6738

Add new comment

For adding a comment, please log in
or create account

0 comments