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

### Question 1.1

• Disassemble the program and run it to loop s1.

The machine code of loop s1 is E2F2. The eight bit binary form of F2 is 11110010, and the complement is 10001110, which is - 14. That is, the displacement is 14.

• From the perspective of execution:

1. CS: IP points to 0771:0019, and the next loop instruction machine code E2 F2.
2. E2 F2 enters the instruction buffer.
3. At this time, CX is not zero, so the instruction is executed.
4. \$IP = IP + length of the read instruction \$= = \$IP + 2 = 001B \$, CS: IP points to mov ah,2
5. The CPU executes the instructions in the buffer
6. After execution, IP = 000D, CS: IP points to mov dl,[si].

### Question 1.2

• Run to loop s2.

The machine code of loop s2 is E2F0. The eight bit binary form of F2 is 11110000, and the complement is 10010000, which is - 16. That is, the displacement is 16.

• Similar to the analysis process of the above question, omitted

### Question 2.1

Jump principle of call instruction:

When the CPU executes the call instruction, it performs two steps:

1. Press the current IP or CS and IP into the stack;
2. Transfer.

According to this principle:

• ax should be equal to the IP pushed into the stack by the previous instruction call word ptr ds:[0], which is 21
• bx should be equal to the IP of CS: IP pushed into the stack by the previous instruction call dword ptr ds:[2], which is 26
• cx should be equal to CS pushed into the stack by call dword ptr ds:[2]: CS in IP. The specific value is unknown

### Question 2.2

Test with DEBUG:

Found the conjecture correct.

### 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 bl,byte ptr 10;This divisor 10 should be 8-bit data, so it is used byte Form.
mov si,offset x
mov cx,len
dec cx

s:	call printNumber
call printSpace
inc si
loop s

mov ax,4c00h
int 21

printNumber:
mov al,[si]
mov ah,0h
div bl;take al Divide the number in by 10, al The quotient (actually ten digits) is obtained, ah The remainder (actually single digits) is obtained in.
mov dh,ah;ah It must be 2 in the interrupt display, so put the data in the dh Yes.
mov ah,2
mov dl,al
or dl,30h;take ascii Turn into ascii Corresponding number in
int 21h;Display ten digits
mov dl,dh
or dl,30h
int 21h;Display single digits
ret

printSpace:
mov ah,2
mov dl,' '
int 21h;Output a space
ret

code ends
end start
```

### code

```assume cs:code, ds:data

data segment
x db 'try'
len equ \$ - x
data ends

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

mov ax, data
mov ds, ax
mov si,offset x
mov cx,len
mov bl,00001010b
mov bh,0;Set the first character address pointing x，Count Reg len，The color is green on a black background, specifying the first line
call printStr

mov ax, data;Direct initialization
mov ds, ax
mov si,offset x
mov cx,len
mov bl,00001100b
mov bh,24;Set the first character address pointing x，Count Reg len，The color is red on a black background, specifying line 25
call printStr;Call again

mov ax, 4c00h
int 21h

printStr:
mov al,160
mul bh;At 80*25 In display mode, if there are 160 bytes per line on the screen, the bh Multiply by 160 bh Represents the line on the screen.
mov di,ax
s:	mov al,[si]
mov es:[di],al;ascii code
mov es:[di+1],bl;The display color of this character
inc si
add di,2;Go to the position of the next displayed character after two bytes
loop s
ret

code ends
end start
```

### strengthen

If 160 of line 33 in the code is changed to 1, the red try will be displayed in the 12th (24 / 2) character bit of the first line.

### code

```assume cs:code, ds:data

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

code segment
start:
mov ax,data
mov ds,ax
mov ax,0b800h
mov es,ax
call printBlueScreen;Draw the blue screen first
mov di,0f00h;Start drawing a horizontal line at the first place on the last line
call printLines
call printNum
call printLines

mov ax,4c00h
int 21h

printBlueScreen:
mov di,0h
mov cx,007d0h;The whole screen can display 2000 characters, converted into octal is 07 d.
mov al,00010000b
s:	mov es:[di+1],al
loop s
ret

printLines:
mov al,0002dh;Horizontal ascii code
mov ah,00011111b
mov cx,00022h;34 second
s1:	mov es:[di],al
mov es:[di+1],ah
loop s1
ret

printNum:
mov cx,len
mov si,offset stu_no
mov ah,00011111b
s2:	mov al,[si]
mov es:[di],al
mov es:[di+1],ah
inc si
loop s2
ret

code ends
end start
```

## summary

• This chapter mainly reviews the 80 * 25 display mode and common jump commands. These commands are mainly variants of the jmp command.

• In the 80 * 25 color display mode, each character occupies two bytes. The first byte is ascii code and the second byte is the color of the character displayed on the screen.

Posted by Cheap Commercial on Sun, 28 Nov 2021 05:36:41 -0800