Experiment 3 Transfer Instruction Jump Principle and Simple Application Programming

IV. EXPERIMENTAL CONCLUSIONS

Experiment Task 1

Task3_ Source for 1

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

Run result: Output two lines 19 3

 

  Question 1

  line27, assembly instruction loop s1 jumps based on the amount of displacement. View its machine through debug disassembly
Code, what is the displacement of the jump? (Displacement values are answered in decimal numbers) 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 loop1 is E2F2. The jump displacement is 001B-000D=E   That is 001B+(-E)=000D, displacement is -14

From the CPU point of view, E2F2, where the displacement is F2, F stands for forward transfer, 001B+00F2=010D, take the last two bits

Question 2

(2) line44, the assembly instruction loop s2 jumps according to the amount of displacement. View its machine through debug disassembly
Code, what is the displacement of the jump? (Displacement values are answered in decimal numbers) From the perspective of the CPU, explain
How to calculate the offset address of the instruction after the jump label s2.  

  loops2's machine instruction is E2F0, jump offset is 0039-0029=0010 jump forward 16 bytes

From the CPU point of view, E2F0, where the displacement is F0, F stands for forward transfer, 0039+00F0=0129, take the last two bits

2. Experimental Task 2

Tsak3_ Source for 2

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

Question 1

According to the jump principle of call instruction, theoretical analysis is made first. Register (ax) = register before program execution (line31)
(bx) =? Register (cx) =?
ax = offset s1, the offset address of s1; ax=0021h
bx = offset s2, the offset address of s2; bx=0026h
cx=cs, the CS value of s2   cx=076C
When the call instruction executes, the IP of the next instruction is stacked
call word ptr ds:[0], stack the IP of its next instruction pop ax, and jump. So ax in pop ax holds the IP of s1
call dword ptr ds:[0] stacks the C s and IP of its next instruction at the same time and jumps. So bx in pop bx holds the IP of s2.
cx in pop cx holds the cs value of s2

  3. Experimental Task 3

Write 8086 assembly source program task3_3.asm to output this set of continuous data, data and data in decimal form on the screen in data segment
Space between.
data segment
   x db 99, 72, 85, 63, 89, 97, 55 
   len equ $- x 
data ends
Requirement:
Write subprogram printNumber
Function: Output a two-digit number in decimal form
Entry parameter: register ax (data to be output--> ax)
Export parameters: none
Write subprogram printSpace
Function: Print a space
Entry parameters: none
Export parameters: none
In the main code, a combination of addressing methods and loops is applied, calling printNumber and printSpace to achieve the title requirements.
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
    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 ah,4ch
    int 21h

printNumber:
    mov dl,al
    mov dh,ah

    or dl,30h
    mov ah,2
    int 21h
    
    mov dl,dh
    or dl,30h
    int 21h

    ret

printSpace:
    mov ah,2
    mov dl,' '
    int 21h
ret
    
code ends
end start

4. Experimental Task 4

Write 8086 assembly source program task3_4.asm, on the screen to specify the color, row, on the screen output string.

data segment
    str db 'try'
    len equ $ - str
data ends
Requirement:
Write subprogram printStr
Function: Display string on screen at specified line, with specified color
Entry parameters
The first character address of the string--> ds:si (where the segment address of the segment in which the string is located - > ds, and the offset address of the starting address of the string - > si)
String Length--> CX
String Color--> bl
Specified row --> BH (value: 0 ~24)
Export parameters: none
In the main code, call printStr twice so that the string is displayed in green on the top of the screen and black at the bottom of the screen
Bottom red display string
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 si,0
    mov bh,0;Line Number
    mov bl,4;colour
    mov cx,len
    call printStr

    mov si,0
    mov bh,24
    mov bl,2
    mov cx,len
    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;160 characters per line
    mul dx
    mov di,ax
s:
    mov al,ds:[si]
    mov ah,bl;colour
    mov es:[di],ax
    inc si
    add di,2
    loop s
ret

code ends
end start

 

 

  5. Experimental Task 5

At 80 × In 25 color character mode, the school number is displayed in the middle of the last line of the screen. The output window is required to have blue bottom, school number and polylines on both sides, displayed in white foreground color.
The logical segment is defined as follows
 
Note*:
1.80 × The 25-color character mode shows the buffer structure, as described in the textbook "Experiment 9 Programming From Materials".
2. When writing the program, change the number of the data segment to your own.
 
assume cs:code, ds:data

data segment
    stu_no db '201983290029'
    len = $ - stu_no
    l2 = 40 - len/2
data ends

code segment
start:
    mov ax,data
    mov ds,ax
    mov si,0
    mov bl,00010001B
    call printOr
    mov bl,00010111B
    call printNo
    mov ah,4ch
    int 21h
printOr:
    mov ax,0b800h;Video memory address
    mov es,ax
    mov ax,0
    mov al,24
    mov dx,160;
    mul dx
    mov cx,ax
    
s0:
    mov byte ptr es:[di],' '
    mov es:[di+1],bl
    add di,2
    loop s
    
ret

printNo:
    mov ax,0b800h;Video memory address
    mov es,ax

    mov ax,0
    mov al,24
    mov dx,160;160 bytes per line
    mul dx
    mov di,ax
    mov cx,l2;Print-
s:
    mov byte ptr es:[di],'-'
    mov es:[di+1],bl
    add di,2
    loop s
    mov si,0
    mov cx,len;Print school number
s1:
    mov al,ds:[si]
    mov ah,bl;colour
    mov es:[di],ax
    add di,2
    inc si
    loop s1
    mov cx,l2;Print-
s2:
    mov byte ptr es:[di],'-'
    mov es:[di+1],bl
    add di,2
    loop s2
ret
    

code ends
end start

 

 

 

V. EXPERIMENTAL SUMMARY

A character displayed on the screen with foreground and background colors. Format of attribute bytes

  7     6    5    4   3  2    1   0

  BL   R   G   B   I   R   G   B

  Twinkle     background     Highlight     background

 

Posted by john0117 on Sat, 27 Nov 2021 10:09:21 -0800