# Experiment 3 transfer instruction jump principle and its simple application programming

4, Experimental conclusion

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:

Answer question ①:

The last two digits of the loop instruction machine code are F2, representing the decimal number - 14. It can be seen that the jump displacement is 14. From the perspective of the CPU, the offset address of the first byte after the loop instruction is 001B and the destination address of the jump is 000D. The decimal number 14 is obtained by subtracting the two.

Answer question ②:

The last two digits of the loop instruction machine code are F0, representing the decimal number - 16. It can be seen that the jump displacement is 16. From the perspective of the CPU, the offset address of the first byte after the loop instruction is 0039 and the destination address of the jump is 0029. The decimal number 16 is obtained by subtracting the two.

Question ③:

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

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 before the program is executed to exit (line31), register (ax) = the offset address of instruction pop ax, register (bx) = the offset address of instruction pop bx, and register (cx) = the segment address of the current code.

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

It can be seen that the value of ax is 0021, which is the offset address of the instruction pop ax; the value of bx is 0026, which is the offset address of the instruction pop bx; and the value of cx is 076c, which is the segment address of the current code. It is consistent with the analysis results.

3. Experimental task 3

Give the program source code task3.asm:

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 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 dl,al
mov bh,ah
add dl,30h
mov ah,2
int 21h
mov dl,bh
add dl,30h
mov ah,2
int 21h
ret
printSpace:
mov dl,20h
mov ah,2
int 21h
ret
code ends
end start

Screenshot of running test:

4. Experimental task 4

Give the program source code task4.asm:

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 ax,0b800h
mov es,ax
mov si,offset str
mov bl,2h
mov bh,0
mov di,0
mov cx,len
call printStr
mov si,offset str
mov bl,4h
mov bh,25
mov di,0f00h
mov cx,len
call printStr
mov ah,4ch
int 21h
printStr:
s:mov al,[si]
mov ah,bl
mov es:[di],ax
inc si
add di,2
loop s
ret
code ends
end start

Screenshot of running test:

5. Experimental task 5

Give the program source code task5.asm:

assume cs:code,ds:data
data segment
stu_no db '201983290098'
len = \$ - stu_no
data ends
code segment
start:
mov ax,0b800h
mov es,ax
mov ax,data
mov ds,ax
mov si,offset stu_no
mov di,0
mov al,0
mov ah,17h
mov cx,780h
s:mov es:[di],ax
add di,2
loop s
mov al,2dh
mov cx,22h
s1:mov es:[di],ax
add di,2
loop s1
mov cx,0ch
s2:mov al,[si]
mov es:[di],ax
add di,2
inc si
loop s2
mov al,2dh
mov cx,22h
s3:mov es:[di],ax
add di,2
loop s3
mov ah,4ch
int 21h
code ends
end start

Screenshot of running test:

5, Experimental summary

1. I am familiar with two methods of outputting characters. Using mov ah,2; int 21h can only output characters to the next line of the current command line; moving characters to the video memory space can display characters at any position on the page through corresponding addressing methods.

2. I am familiar with the use method and data storage location of div command: for 8-bit division, the divisor is placed in ax, and the remainder and quotient are placed in ah and al; I am also familiar with the principle of call and ret instructions: the call instruction first presses the current code segment offset address IP into the stack and saves it, then jumps to the specified address and assigns it to IP. The ret command assigns the address saved in the stack to IP.

Posted on Wed, 01 Dec 2021 00:05:40 -0500 by DSGameMaker