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

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

```assume cs:code, ds:data

data segment
x db 1, 9, 3
len1 equ \$ - x ; symbolic constants , \$Refers to the offset address of the next data item. In this example, it is 3

y dw 1, 9, 3
len2 equ \$ - y ; symbolic constants , \$Refers to the offset address of the next data item. In this example, it is 9
data ends

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

mov si, offset x ; Take symbol x Corresponding offset address 0 -> si
mov cx, len1 ; From symbol x Number of consecutive byte data items at the beginning -> cx
mov ah, 2
s1:mov dl, [si]
or dl, 30h
int 21h

mov dl, ' '
int 21h ; Output space

inc si
loop s1

mov ah, 2
mov dl, 0ah
int 21h ; Line feed

mov si, offset y ; Take symbol y Corresponding offset address 3 -> si
mov cx, len2/2 ; From symbol y Number of consecutive word data items started -> cx
mov ah, 2
s2:mov dx, [si]
or dl, 30h
int 21h

mov dl, ' '
int 21h ; Output space

loop s2

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

①   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) - 14

From the perspective of the CPU, explain how to calculate the offset address of the instruction after the jump label s1.

(1)(cx)=(cx)-1

(2) If (cx)=0, do nothing, and the program continues to execute downward;

If (Cx)= 0, then the jump offset address (IP) = (IP)+8-bit displacement (000D-001B)

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

-16

From the perspective of the CPU, explain how to calculate the offset address of the instruction after the jump label s2.

(1)(cx)=(cx)-1

(2) If (cx)=0, do nothing, and the program continues to execute downward;

If (Cx)= 0, then the jump offset address (IP) = (IP)+8-bit displacement (0029-0039)

Question ③

③ Attach the disassembly screenshot of debugging observation in debug during the above analysis

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```

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 register (ax) =0021 before program execution and exit (line31)   Register (bx) = 0026 register (cx) = 076C

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

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
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]
mov bl,10
div bl;use ax Divide the number in by 10 and the quotient is al In, the remainder is ah in mov dx,ax

call printNumber
call printSpace

inc si
loop s

mov ah,4ch
int 21h

printNumber:
mov dx,ax
add dx,3030h;Between number and string ascll The relationship between code value and number->character
mov ah,2;Output character
int 21h
mov ah,2
mov dl,dh
int 21h
ret
printSpace:  mov dl,' '
int 21h
ret

code ends
end start```

Screenshot of running test

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 dh,1 ;Set number of rows
mov dl,0 ;Set number of columns
mov cl,2 ;Set color
mov ax,data
mov ds,ax
mov si,0
call show_str

mov dh,25 ;Resets the number and color of rows and columns
mov dl,0
mov cl,4
call show_str

mov ax,4c00h
int 21h
show_str:
push cx
push si
mov ax,0b800h
mov es,ax
mov al,0a0h
dec dh
mul dh
mov bx,ax
mov al,2
mul dl
sub dl,2
add bx,ax ;Get the actual offset position
mov di,0
mov ch,0
mov al,cl
s:
mov cl,ds:[si]
jcxz next :Judge whether the last character is zero. If it is zero, it ends
mov es:[bx+di],cl ;String before
mov es:[bx+di+1],al ;Color behind
inc si
jmp s
next:
pop si
pop cx
ret
code ends
end start```

Screenshot of running test

The program source code task5.asm is given

```assume cs:code, ds:data

data segment
stu_no db'201983290355'
len = \$ - stu_no
data ends

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

call s

mov ah,4ch
int 21h

s:
mov ax,0b800h
mov es,ax
mov si,1

;Dye 24 lines of the screen blue
mov al,24
mov dl,80
mul dl

mov cx,ax
s1:
mov al,17h
mov es:[si],al
loop s1

sub si,1

;Print the last line, calculate'-'Number of
mov ax,80
sub ax,len
mov dl,2
div dl
mov dx,ax

;Print the to the left of the student number'-'
mov cx,dx
call s2

;Print student number
mov cx,len
s3:
mov al,ds:[di]
mov ah,17h
mov word ptr es:[si],ax
inc di
loop s3

mov cx,dx
call s2

ret

;Print the to the right of the student number'-'
s2:
mov al,'-'
mov ah,17h
mov es:[si],ax