Experiment 3 transfer instruction jump principle and its simple application programming

1, Experimental purpose
1. Understand and master the jump principle of transfer instruction
2. Master the method of using call and ret instructions to realize subroutines, and understand and master the parameter transfer mode
3. Understand and master 80 × 25 color character mode display principle
4. Integrate addressing mode and assembly instructions to complete simple application programming

 

2, Experimental preparation
Review chapters 9-10 of the textbook:
Jump principle of transfer instruction
Usage of assembly instructions jmp, loop, jcxz, call, ret, retf

 

3, Experimental content

1. Experimental task 1

Using any text editor, enter the 8086 assembler source code task1.asm
code:
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 

    add si, 2 
    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) from the perspective of the CPU, explain how to calculate the offset address of the instruction after the jump label s1.
  The machine code of line27 loop command is E2F2. The eight bit binary form of F2 is 11110010, its complement is 10001110, and the decimal form is - 14, that is, the bit shift is 14
② 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) from the perspective of the CPU, explain how to calculate the offset address of the instruction after the jump label s2.
The machine code of line44 loop command is E2F0. The eight bit binary form of F0 is 11110000, the complement is 10010000, and the decimal form is - 16, that is, the bit shift is 16
③ Attach the disassembly screenshot of debugging observation in debug during the above analysis

2. Experimental task 2
Using any text editor, enter the 8086 assembler source code task2.asm
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
① According to the jump principle of call instruction, it is analyzed theoretically that before the program executes to exit (line31), register (ax) =? Register (bx) =? Register (cx) =?
ax=0021,bx=0026,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.
agreement

 

3. Experimental task 3
For 8086 CPU, the known logical segment is defined as follows:
Write the 8086 assembly source program task3.asm to output this group of continuous data in the data section in decimal form on the screen, and the data is separated by spaces.
requirement:
Write subroutine printNumber
Function: output a two digit number in decimal form
Entry parameter: register ax (data to be output -- > ax)
Outlet parameters: None
Write the subroutine printSpace
Function: print a space
Entry parameters: None
Outlet parameters: None
In the main code, the addressing mode and loop are comprehensively applied, and printNumber and printSpace are called to realize the subject requirements.
code:
assume ds:data, cs:code
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
    mov byte ptr ds:[10], 10

s1:    mov ah, 0
    mov al, ds:[si]

    div byte ptr ds:[10]
    call printNumber
    call printSpace
    inc si
    loop s1

    mov ax, 4c00h
    int 21h

printNumber:mov bx, ax
    or bl, 30h
    or bh, 30h
    mov ah, 2
    mov dl, bl
    int 21h
    mov dl, bh
    int 21h
    ret

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

code ends
end start
When correctly written, the expected test results are as follows:
4. Experimental task 4
For 8086 CPU, the known logical segment is defined as follows:
Write 8086 assembly source program task4.asm, specify the color and line on the screen, and output the string on the screen.
requirement:
Write subroutine printStr
Function: display the string on the screen in the specified line and in the specified color
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 cx,len
   mov si,offset str
   mov bh,0
   mov bl,2
   call printStr
   
   mov cx,len
   mov si,offset str
   mov bh,24
   mov bl,4
   call printStr
   
   mov ah,4ch
   int 21h
printStr:
   ;Address of segment corresponding to calculation line
   mov al,0ah
   mul bh
   add ax,0b800h
   mov es,ax

   mov di,si
   ;Write to video memory
s: mov al,ds:[si]
   mov ah,bl
   mov es:[di],ax
   inc si
   add di,2
   loop s
   ret
code ends
end start
When correctly written, the expected test results are as follows:
Can't achieve green try

 

 

 
5. Experimental task 5
For 8086CPU, for 8086CPU, the known logical segment is defined as follows:
At 80 × In 25 color character mode, the student number is displayed in the middle of the last line of the screen. It is required to output the blue background of the window, student number and broken lines on both sides to
White foreground color display.
Note *:
1. 80 × 25 color character mode display buffer structure, see the description in the textbook "experiment 9 programming according to materials".
2. When writing the program, replace the student number of the data segment with your own student number.
After the program is written correctly, the expected output effect is as follows:
code:
assume cs:code, ds:data

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

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

    call printStuNum
    
    mov ah, 4ch
    int 21h

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

    mov al, 24
    mov dl, 80
    mul dl
    
    mov cx, ax
    printBlue:
        mov al, 17h    ;00010111
        mov es:[si], al    ;fill color
        add si, 2
    loop printBlue

    sub si, 1
    mov ax, 80
    sub ax, len
    mov dl, 2
    div dl
    mov dx, ax    ;preservation-Length of

    mov cx, dx
    call printheng

    mov cx, len
    printStu:    ;Output student number
        mov al, ds:[di]
        mov ah, 17h
        mov word ptr es:[si], ax
        inc di
        add si, 2
    loop printStu

    mov cx, dx
    call printheng

    ret
    
printheng:
    mov al, '-'
    mov ah, 17h
    mov word ptr es:[si], ax
    add si, 2
    loop printheng
    ret
     
code ends
end start

 

Posted by azfar siddiqui on Sat, 27 Nov 2021 20:33:29 -0800