Experiment 3 transfer instruction jump principle and its simple application programming

1. Experimental task 1

task1.asm 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:

  Question 1:

Disassembly screenshot:

  The displacement of jump is - 14. After F2 is converted into the original code, the corresponding decimal value is - 14, so the displacement is - 14. The jump process is as follows: after executing the LOOP 000D command, the IP will automatically add 2 and become 001B, and then jump, 001B+(-E)= 000D, and jump to the place where the IP is 000D.

Question 2:

Disassembly screenshot:

  The displacement of jump is - 16. After F0 is converted to the original code, the corresponding decimal value is - 16, so the displacement is - 16. The jump process is as follows: after executing the LOOP 0029 command, the IP will automatically add 2 to 0039, and then jump to 0039 + (- 0010) = 0029, and jump to IP 0029.

Question 3:

Disassembly screenshot above

 

2. Experimental task 2

task2.asm 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

(1) Theoretically, ax register stores the offset address of s1, bx register stores the offset address of s2, and cx register stores the segment address of cs. Because when call word ptr ds:[0] is executed, the IP value of the next instruction s1:pop ax will be put on the stack, and then when s1:pop ax is executed, the IP value at the top of the stack will be assigned to ax, which is exactly the offset address of s1. When call dword ptr ds:[2] is executed, the segment address cs of the current code segment and the IP value of the next instruction are successively put on the stack, occupying two bytes each, and then jump to the code executing segment s2, assign the IP at the top of the stack to bx, and then assign the segment address cs to cx, and the IP value is exactly the offset address of s2.

(2) Commissioning verification is as follows:

As can be seen from the figure, the IP value 0021 of call word ptr ds:[0] is assigned to the ax register after s1:pop ax is executed.

It can be seen from the figure that after calling DWORD PTR ds: [2], CS=076C and IP=0026 are put into the stack. After executing s2 segment, BX = 0026 and CX = 076c

 

The debugging results are consistent with the analysis results.

 

3. Experimental task 3

task3.asm 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 cx,len
    mov si,0
s:
    mov al,[si]
    mov ah,0
    call printNumber
    call printSpace
    inc si
    loop s

    mov ah,4ch
    int 21h
printNumber:
    mov bl,10
    div bl
    
    mov bx,ax 

    mov dl,bl
    or dl,30h
    mov ah,2
    int 21h
 
    mov dl,bh
    or dl,30h
    mov ah,2
    int 21h
    ret
printSpace:
    mov dl,' '
    mov ah,2
    int 21h

    ret
code ends
end start

Put the contents of the data segment into ax one by one and divide by the value of bl to obtain the quotient and remainder. The quotient is in al and the remainder is in ah, which are converted into ASCII code and output respectively.

Screenshot of running test:

 

 

4. Experimental task 4

task4.asm 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,00000010b
     mov bh,1
     call printStr

    mov si,offset str
    mov cx,len
    mov bl,00000100b
    mov bh,23
    call printStr

    mov ah,4ch
    int 21h
printStr:
    mov ax,0b800h
    mov es,ax

    mov ax,0
    mov al,bh
    mov dx,0a0h
    mul dx
    mov di,ax
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:

 

 

5. Experimental task 5

task5.asm source code:

assume ds:data, cs:code

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

code segment
start:
    mov ax,0b800h
    mov es,ax
    mov bp,1
    mov cx,8000h

 color:
    mov byte ptr es:[bp],00011111B
    add bp,2
    loop color

    mov ax,data
    mov ds,ax
    mov ax,0050h
    sub ax,len
    mov bh,02h
    div bh
    mov bl,al
    mov bh,0

    mov ax,0b800h
    mov es,ax
    mov bp,0F00h

    mov cx,bx
    s:
    mov byte ptr es:[bp],'-'
    add bp,2
    loop s

    mov cx,len
    mov di,0
    s1:
    mov al,ds:[di]
    mov es:[bp],al
    add bp,2
    inc di
    loop s1

    mov cx,bx
    s2:
    mov byte ptr es:[bp],'-'
    add bp,2
    loop  s2

    mov ax,4ch
    int 21h

code ends
end start

Screenshot of running test:

 

Posted by chatmaster on Sun, 28 Nov 2021 06:44:35 -0800