Experiment 3 transfer instruction jump principle and its simple application programming

4, Experimental conclusion

1. Experimental task 1

Experimental 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

Running screenshot

 

 

  Question 1: the disassembly screenshot is as follows:

 

 

As you can see,   loop s1   After disassembly   loop 000D   That is, the jump address is 000d, the jump is based on the displacement, and the jump rule is   Current IP + offset = jump address  , The current IP is 001B, converted to decimal is 27, the jump address is 000d, converted to decimal is 13, and the offset that can be calculated is  - fourteen  .

From the perspective of CPU, you can view the stored content and find that the stored content is   F2  ,

Convert to binary   1111 0010  , and  - fourteen   The complement of is   1110 0010  , It happens to be F2, so the CPU stores the offset and calculates the instruction address after the offset according to the IP value.

Question 2: the disassembly screenshot is as follows:

 

 

As you can see,   loop s2   After disassembly   loop 0029   That is, the jump address is 0029. The jump is based on the displacement, and the jump rule is   Current IP + offset = jump address  , The current IP is 0039, converted to decimal is 57, the jump address is 0029, converted to decimal is 41, and the offset that can be calculated is   - sixteen  .

From the perspective of CPU, you can view the stored content and find that the stored content is   F0  ,

Conversion to binary is   1111 0000  , and  - sixteen   The complement of is   1111 0000  , It happens to be F0, so the CPU stores the offset and calculates the instruction address after the offset according to the IP value.

  Question 3: the disassembly screenshot has been given

2. Experimental task 2

Program source code

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

Screenshot of debugging and disassembly:

 

(1) Theoretical analysis, before the program exits, ax=21, bx=26, cx=076c.

(2) debug debugging and verification, and the result is

 

  The results are consistent with the theoretical analysis

3. Experimental task 3

Program source code

assume cs:code, ds:data

data segment
    x db 99, 72, 85, 63, 89, 97, 55
    len equ $ - x
data ends

code segment
start:  
    mov ax, data
    mov ds, ax
    
    mov si, offset x
    mov cx, len
    
s:    mov ah, 0
    mov al, [si]
    call printNumber
    call printSpace
    
    inc si
    loop s
    
    mov ah, 4ch
    int 21h
    
printNumber:    
    mov bx, 10
    div bl
    mov bx, ax
    add bx, 3030h
    mov ah, 2
    mov dl, bl
    int 21h
    mov ah, 2
    mov dl, bh
    int 21h
    ret

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

    
code ends
end start

Screenshot of running test

 

  Consistent with expected requirements

4. Experimental task 4

Program source code

assume cs:code, ds:data

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

code segment
start:
    mov ax, data
    mov ds, ax
    mov si, offset str
    mov cx, len
    
    mov bl, 0ah
    mov bh, 0
    call printStr
    
    mov cx, len
    mov si, offset str
    mov bl, 0ch
    mov bh, 24
    call printStr
    
    mov ah, 4ch
    int 21h
    


printStr:
    mov al, 00a0h
    mul bh
    mov di, ax
    mov ax, 0b800h
    mov es, ax
    
    mov al, bl
    
s:    mov ah, ds:[si]
    mov es:[di], ah;
    mov es:[di+1], bl;
    add di, 2
    inc si
    loop s
    ret
    
    
code ends
end start

Screenshot of running test

 

  The experimental results are in line with expectations

5. Experimental task 5

Program source code

assume cs:code, ds:data

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

code segment
start:
    mov ax, data
    mov ds, ax
    mov si, offset stu_no
    mov cx, len

    mov ax, 0b800h
    mov es, ax
    mov di, 0
    
    mov al,24
    mov dl, 80
    mul dl
    mov cx, ax
s:    
    mov al, 17h
    mov es:[di], byte ptr 20h
    mov es:[di+1], al
    add di, 2
    loop s

    mov ax, 80
    sub ax, len
    mov dl, 2
    div dl
    mov cx, 0
    mov cl, al
    mov bx, cx
    call gang
    mov cx, len
s2:
    mov al, ds:[si]
    mov ah, 17h
    mov es:[di], ax
    add di, 2
    inc si
    loop s2
    mov cx, bx
    call gang
    mov ah, 4ch
    int 21h
    
    
gang:
    
s1:    mov al, '-'
    mov ah, 17h
    mov es:[di], ax
    add di, 2
    loop s1
    ret
code ends
end start

Screenshot of running test

 

  The experimental results are consistent with expectations.

5, Experimental summary

Through this experiment, I have mastered the use of jump instruction, the writing of subroutine and the method of displaying characters. I use call instruction and ret instruction to realize the writing of subroutine. The window displays 25 lines and 80 columns.

Added by mandukar on Sun, 28 Nov 2021 11:14:59 +0200