Experiment 3 transfer instruction jump principle and its simple application programming
task1
Using any text editor, enter the 8086 assembler source code task1.asm.
task1.asm
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 Operation results:assume cs:code, ds:data data segment x db 1, 9, 3 len1 equ $ - x y dw 1, 9, 3 len2 equ $ - y data ends code segment start: mov ax, data mov ds, ax mov si, offset x mov cx, len1 mov ah, 2 s1:mov dl, [si] or dl, 30h int 21h mov dl, ' ' int 21h inc si loop s1 mov ah, 2 mov dl, 0ah int 21h mov si, offset y mov cx, len2/2 mov ah, 2 s2:mov dx, [si] or dl, 30h int 21h mov dl, ' ' int 21h add si, 2 loop s2 mov ah, 4ch int 21h code ends end start
- question answering
① 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
A: the jump displacement is 14byte,
As shown in the figure: 1B + [(F2) supplement] original = 27-14=0DH
② 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.
A: jump to 16byte
As shown in the figure: 39 + [(F0) supplement] original = 57-16=29H
③ Attach the disassembly screenshot of debugging observation in debug during the above analysis
Screenshot above
task3
Using any text editor, enter the 8086 assembler source code task2.asm.
task3.asm
DATAS SEGMENT ;Enter segment code here DATAS ENDS data segment x db 99, 72, 85, 63, 89, 97, 55 len equ $ - x data ends STACKS SEGMENT ;Enter the stack segment code here STACKS ENDS CODES SEGMENT ASSUME CS:CODES,DS:DATAS,SS:STACKS START: mov ax,data mov ds,ax mov cx,len mov si,0 s: mov ah,0 mov al,ds:[si] call printNumber call printSpace inc si loop s mov ah,4ch int 21h printNumber: mov bl,10 ;Binary divided by ten, the remainder is single digits, and the quotient is ten digits div bl ;ah Is the remainder, al For quotient( ah,al Respectively ax High 8 bit Low 8 bit mov bx,ax ;Transmit data to bx For modification ax use int 21h mov ah,2 mov dl,bl or dl,30h int 21h mov dl,bh or dl,30h ;Digital conversion ASCALL code int 21h ret printSpace: mov ah,2 mov dl,' ' int 21h ret CODES ENDS END START
Operation screenshot:
task4
Experiment code:
Click to view the codeDATAS SEGMENT ;Enter segment code here DATAS ENDS data segment x db 'try' len equ $ - str data ends STACKS SEGMENT ;Enter the stack segment code here STACKS ENDS CODES SEGMENT ASSUME CS:CODES,DS:DATAS,SS:STACKS START: mov ax, data mov ds, ax mov ax,0b800h mov es,ax mov si,offset x mov bl, 2 ;Specifies that the string color is green on a black background mov bh, 0 ;Specify the first line of the behavior call printStr mov si,offset x mov bl, 4 ; Specifies that the string color is red on a black background mov bh, 24 ;Specify the last line of the behavior call printStr mov ah, 4ch int 21h printStr: mov al, 160 mul bh mov cx,len mov di, ax s: mov ah, ds:[si] mov es:[di], ah inc di mov es:[di], bl inc si inc di loop s ret CODES ENDS END START
Operation results:
task5
Experiment code:
Click to view the codeDATAS SEGMENT ;Enter segment code here DATAS ENDS data segment stu_no db '2019832900' len = $ - stu_no data ends STACKS SEGMENT ;Enter the stack segment code here STACKS ENDS CODES SEGMENT ASSUME CS:CODES,DS:DATAS,SS:STACKS START: mov ax,data mov ds,ax mov ax,0b800h mov es,ax call p1 ;Set background mov bh,24 ;Set the number of rows to the last row mov al,160 mul bh mov bx,ax call p2 ;Output polyline call p3 ;Output student number call p2 ;Output discount mov ax,4c00h int 21h p2: mov al,'-' mov dl,17h;'-'Color of mov cx,33;Draw 33 on one side'-' s: mov es:[bx],al inc bx mov es:[bx],dl inc bx loop s ret p1: mov si,1 mov bl,17h;Set color mov cx,7d0h ;2000 in total w,4000 individual byte(160*25) s2: mov es:[si],bl add si,2 loop s2 ret p3: mov si,0 ;str'Student number'Offset address of mov dl,17h;colour mov cx,len;length s1: mov al,ds:[si] mov es:[bx],al inc bx mov es:[bx],dl inc bx inc si loop s1 ret CODES ENDS END START
Experimental results: