Experiment 3 transfer instruction jump principle and its simple application programming

Posted by sukanya.paul on Sun, 28 Nov 2021 20:41:01 +0100

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 subroutine, and understand and master its parameter transmission mode
  3.      Understand and master 80 × 25 color character mode display principle
  4.      Integrated application of addressing mode and assembly instructions to complete simple application programming

 

2, Experimental preparation

 

  1. Jump principle of transfer instruction
  2. Usage of assembly instructions jmp, loop, jcxz, call, ret, retf

 

3, Experimental results

Task1

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

  Question 1: 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.

According to 076B:0019 E2F2 LOOP     000D
E2 (Loop instruction) F2 (complement of displacement), that is, the displacement (F2) is supplemented by 14, and the result is the next 1bh-0dh=0dh

Question 2: 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.

According to 076B:0037 E2F0 LOOP     0029
Ibid. (F0) is supplemented by 16, 39h-10h=29h
 

Task2

Using any text editor, enter the 8086 assembler source code task2.asm.
 
Experiment 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=21h;  bx=26h;  cx=076ch;
call word into the next item on the stack, that is, the ip of s1, and out of the stack to ax;
The call dword instruction successively enters cs and ip of stack s2, ip goes out of stack bx, and cs goes out of stack cx;
② 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.
Consistent;

Task3

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.
Requirements:
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.
 
Experiment code:
assume ds:data, cs:code
data segment
    x db 99, 72, 85, 63, 89, 97, 55
    len equ $- x
data ends
data1 segment
    db 10
data1 ends
code segment
start:
    mov ax, data
    mov ds, ax
    mov si, offset x
    mov cx, len

s1:    mov ah, 0
    mov al, ds:[si]
    div byte ptr ds:[10h]
    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
 
Operation results:

Task4

Write 8086 assembly source program task4.asm, specify the color and line on the screen, and output the string on the screen.
Requirements:
Write subroutine printStr
Function: display the string on the screen in the specified line and in the specified color
Entry parameters
The address of the first character of the string -- > ds: Si (where, the segment address of the segment where the string is located -- > DS, and the offset address of the starting address of the string -- > SI)
String length -- > CX
String color -- > bl
Specified line -- > BH (value: 0 ~ 24)
Outlet parameters: None
In the main code, printStr is called twice to display the string in green on a black background at the top of the screen and in red on a black background at the bottom of the screen;
 
Experiment code:
assume ds:data, cs:code
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 bh,0
    mov bl,2
    call printStr

    mov bh,24
    mov bl,4
    call printStr

    mov ax,4c00h
    int 21h

printStr:
    mov si,offset str
    mov al,0a0h
    mul bh
    mov di,ax
    mov cx,len
    mov bh,bl
s:    mov bl,[si]
    mov es:[di],bx
    inc si
    add di,2
    loop s

    ret

code ends
end start

 

Operation results:

 

 

Task5

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 that the student number and broken lines on both sides of the output window are displayed in white foreground.
 
Experiment code:
assume ds:data, cs:code
data segment
    stu_no db '201983290408'
    len = $ - stu_no
data ends

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

    call backgroundCol

    mov di, 3840
    call printLine

    mov di, 3908
    mov si, offset stu_no
    call printStu_no


    mov ax, 4c00h
    int 21h

backgroundCol:
    mov ax,1700h
    mov di, 0
    mov cx, 4000
s:    mov es:[di], al
    mov es:[di+1], ah
    add di, 2
    loop s
    ret

printLine:
    mov cx, 50h
    mov ax, 172dh
s1:    mov es:[di], al
    mov es:[di+1], ah
    add di,2
    loop s1
    ret

printStu_no:
    mov cx, len
    mov ah, 17h
s2:    mov al, [si]
    mov es:[di], al
    mov es:[di+1], ah
    inc si
    add di, 2
    loop s2
    ret

code ends
end start

 

Operation results:

 

 

4, Experimental summary

Through this experiment, I understand and master the jump principle of transfer instruction, the method of using call and ret instruction to realize subroutine, the parameter transmission mode, and 80 × 25 color character mode display principle; comprehensive application of addressing mode and assembly instructions to complete simple application programming.