Experiment 3 transfer instruction jump principle and its simple application programming

Experiment 3 transfer instruction jump principle and its simple application programming

 

experimental result

task1

  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 
1. Understand the flexible use of operator offset, pseudo instruction equ and predefined symbol $.
 
The offset instruction calculates the offset, equ indicates the alias, and $gets the current address
 
2. Answer questions
① line27, when the assembly instruction loop s1 jumps, it jumps according to the displacement. Check the machine code through debug disassembly,
Analyze the displacement of its jump? (the displacement value is answered in decimal) from the perspective of CPU, explain how it is calculated
To the offset address of the instruction after the jump label s1.
 

 

As shown in the figure, the assembly language code corresponding to the loop instruction is E2F2, E2 represents loop, F2 represents offset, and its binary form is 11110010

Convert the complement to the original code as 10001110 = - 14

Therefore, the current deviation address is ox1B-14=27-14=13=000D
 
② line44. When the assembly instruction loop s2 jumps, it jumps according to the displacement. Check the machine code through debug disassembly,
Analyze the displacement of its jump? (the displacement value is answered in decimal) from the perspective of CPU, explain how it is calculated
To the offset address of the instruction after the jump label s2.

 

As shown in the figure, the assembly language code corresponding to the loop instruction is E2F0, E2 represents loop, F2 represents offset, and its binary form is 11110000

Convert the complement to the original code as 10010000 = - 16 = - 10

The offset address is Ox(39-10)=Ox(29)

 

The length of the add instruction is different from that of the inc instruction, so the offset is different

 


task2

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 register (ax) =? Register before program execution and exit (line31)
(bx) =? Register (cx) =?
 
(ax) = s1 address (bx) = s2 address     (cx) = stack bottom address = ss+0010=cs
 
② Assemble and link the source program to get the executable program task2.exe. Use debug to observe and verify the debugging results and theory
Whether the analysis results are consistent.

 

 

task3
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 byte ptr ds:[len],10;Stored divisor
    mov cx,7
    mov bx,0
s:  mov al,ds:[bx]
    mov ah,0
    inc bx
    call printNumber
    call printSpace
    loop s
    mov ah,4ch
    int 21h
printNumber:
    div byte ptr ds:[len];ah Save the remainder; al Depositary
    mov dx,ax;dh Save the remainder; dl Depositary
    mov ah,2
    or dl,30h;30h Corresponding to character 0 ascii code
    int 21h
    mov ah,2
    mov dl,dh
    or dl,30h
    int 21h
    ret
printSpace:
    mov dl,' '
    mov ah,2
    int 21h
    ret
code ends
end start
Write 8086 assembly source program task3.asm to output this group of continuous data, data and data in the data section in decimal form on the screen
Space between.
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.
 
Or operand 1 operand 2 performs an or operation on operand 12 and stores the result in operand 1

 

 

task4

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 bl,00000010B;colour
    mov bh,0;Line number
    mov cx,3;String length
    mov si,0;Character content offset address
    call printStr

    mov bl,00000100B
    mov bh,24
    mov cx,3
    mov si,0
    call printStr

    mov ah,4ch
    int 21h
printStr:
    mov ax,0b800h;Video memory address
    mov es,ax

    mov ax,0
    mov al,bh
    mov dx,160;Calculate the video memory address where the line number is located
    mul dx
    mov di,ax

s:  mov al,ds:[si]
    mov es:[di],al;Display character
    inc si
    inc di
    mov es:[di],bl;set up yanse
    inc di
    loop s
    ret
code ends
end start
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
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, the offset of the starting address of the string)
Move address - > 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 black at the bottom of the screen
The string is displayed in red at the bottom
 

The result of 8-bit multiplication is placed in ax (the high bit of the result of 16 bit multiplication is placed in dx and the low bit is placed in AX), and mul 160 obtains the offset address of the corresponding line number in the video memory; the lower eight bits of the video memory address store characters and the upper eight bits store colors;

 

 

 task5

assume cs:code, ds:data

data segment
    stu_no db '201983290347'
    len = $ - stu_no
    len1 = (80-len)/2
data ends

code segment
start:
    mov ax,data
    mov ds,ax
    
    mov bl,00010000b
    call printColor

    mov si,0
    mov bl,00010111b
    mov bh,24
    call printStr
    mov ah,4ch
    int 21h

printColor:
    mov ax,0b800h
    mov es,ax
    mov ax,0
    mov al,25
    mov dx,0
    mov dx,80
    mul dx
    mov cx,ax
    mov al,' '
    mov di,0
    s:    mov es:[di],al
        inc di
        mov es:[di],bl
        inc di
        loop s
    ret

printStr:
    mov ax,0b800h
    mov es,ax
    mov ax,0
    mov al,bh
    mov dx,160
    mul dx
    mov di,ax

    mov al,'-'
    mov cx,len1
    s1:    mov es:[di],al
        inc di
        mov es:[di],bl
        inc di
        loop s1
    
    mov cx,len
    s2:    mov al,ds:[si]
        mov es:[di],al
        inc si
        inc di
        mov es:[di],bl
        inc di
        loop s2

    mov al,'-'
    mov cx,len1
    s3:    mov es:[di],al
        inc di
        mov es:[di],bl
        inc di
        loop s3
    ret
code ends
end start
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.

 

 

 
 

Posted by jlambert on Tue, 30 Nov 2021 20:08:35 -0800