Experiment 3 transfer instruction jump principle and its simple application programming

4, Experimental conclusion

1. Experimental task 1

(1) Give the program task1.asm source code, and run screenshots

  • Source code:
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
  • Operation screenshot:

(2) Answer question ①
① line27, when the assembly instruction loop s1 jumps, it jumps according to the displacement. Check the machine through debug disassembly
What is the jump displacement of the code? (the displacement value is answered in decimal) from the perspective of CPU, it is explained
How to calculate the offset address of the instruction after the jump label s1.

  • As can be seen from the above figure, after the loop s1 instruction is executed, the IP is 001B and jumps to 000D, so the jump displacement = 000D-001B=-14 (decimal).
  • From the perspective of CPU, check the machine code after reverse compilation: the machine code of loop 000D is E2F2 and F2 is the complement of - 14.
    Answer question ②
    ② line44. When the assembly instruction loop s2 jumps, it jumps according to the displacement. Check the machine through debug disassembly
    What is the jump displacement of the code? (the displacement value is answered in decimal) from the perspective of CPU, it is explained
    How to calculate the offset address of the instruction after the jump label s2.
  • The same as ①. After loop s2 is executed, IP 0039 jumps to 0029, so the jump displacement = 0029-0039 = - 16 (decimal).
  • From the perspective of CPU, check the machine code after reverse compilation: the machine code of loop 0029 is E2F0, and F0 is the complement of - 16.

Question ③
③ Attach the disassembly screenshot of debugging observation in debug during the above analysis.
See the disassembly screenshot in ① answer.

2. Experimental task 2

(1) The program task2.asm source code is given:

assume cs:code, ds:data

data segment
    dw 200h, 0h, 230h, 0h
data ends

stack segment
    db 16 dup(0)
stack ends

code segment
start:  
    mov ax, data
    mov ds, ax

    mov word ptr ds:[0], offset s1
    mov word ptr ds:[2], offset s2
    mov ds:[4], cs

    mov ax, stack
    mov ss, ax
    mov sp, 16

    call word ptr ds:[0]
s1: pop ax

    call dword ptr ds:[2]
s2: pop bx
    pop cx

    mov ah, 4ch
    int 21h
code ends
end start

(2) After analysis, debugging and verification, register (ax) =? (bx) = (cx) =? Attach the screenshot of the debugging result interface.
① According to the jump principle of call instruction, it is analyzed theoretically that the register (ax) before the program execution to exit (line31)=
0021h, register (bx) = 0026h, register (cx) = 076ch
==>Because call word ptr ds:[0] is a short transfer, the current ip, that is, the ip corresponding to s1, is stacked;
call dword ptr ds:[2] is a long transfer. At this time, press cs:ip, that is, cs:s2 on the stack.

② Assemble and link the source program to get the executable program task2.exe. Use debug to debug, observe and verify debugging
Whether the results are consistent with the theoretical analysis results.

It can be seen from the above figure that it is consistent with the theoretical analysis results.

3. Experimental task 3

(1) The program source code task3.asm is given

assume cs:code, ds:data

data segment
x db 99,72,85,63,89,97,55
len equ $- x   ;$Refers to the offset address of the next data item=7
data ends

code segment
start:
mov ax,data
mov ds,ax
mov cx,len
mov si,offset x
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
div bl ;Separate tens and single digits
mov bh,ah ;remainder
mov dl,al ;al Zhong weishang
or dl,30h ;ascii Numeric variable character

mov ah,2
int 21h   ;Output ten digits

mov dl,bh
or dl,30h
int 21h  ;Output single digit
ret

printSpace:
mov ah,2
mov dl,' '
int 21h
ret

code ends
end start

(2) Screenshot of running test:

4. Experimental task 4

(1) The program source code task4.asm is given

assume cs:code, ds:data

data segment
str db 'try', 0
len equ $ - str
data ends

code segment
start:
mov ax, data
mov ds, ax
mov ax,0b800h  ;Display area cache address start location
mov es,ax

mov si,offset printStr
mov ah, 2  ;green
mov bx,0 ;Print on the first line
call si  ; First call

mov si,offset printStr
mov ah,4 ;red
mov bx,3840 ;A line of 80 characters and 160 bytes, the last 24 lines, 24*160=3840
call si

mov ah, 4ch
int 21h

printStr:
mov cx,len
mov si,0
s:
mov al,[si]
mov es:[bx+si],ax
inc si
inc bx
loop s
ret

code ends
end start

(2) Screenshot of running test:

5. Experimental task 5

(1) The program source code task5.asm is given

assume cs:code,ds:data

data segment
stu_no db '201983440043'
len = $ - stu_no
data ends

code segment
start:
mov ax,data
mov ds,ax
mov ax,0b800h
mov es,ax

mov si,offset stu_no
mov di,0
mov al,17h   ;White words on blue background: 0 001 0 111 is 17 h
call printBgcolor
call printHyphen
call printStuno
call printHyphen

mov ah,4ch
int 21h

;The print background color is blue
printBgcolor:
mov cx,1920 ;The background color accounts for 24 lines, with 80 characters in each line: 24*80
s:
inc di
mov es:[di],al;
inc di
loop s
ret

;Print 34 before and after student number'-'
printHyphen:
mov cx,34
s1:
mov word ptr es:[di],'-'
inc di
mov es:[di],al
inc di
loop s1
ret

;Print student number
printStuno:
mov cx,len   ;   stu_no length
s2:
mov bl,ds:[si]
mov es:[di],bl
inc di
mov es:[di],al
inc si
inc di
loop s2
ret

code ends
end start

(2) Screenshot of running test:

Posted on Sun, 28 Nov 2021 13:35:08 -0500 by intergroove