1. 程式人生 > 其它 >EasyCVR分發出來的流播放花屏的問題處理方法

EasyCVR分發出來的流播放花屏的問題處理方法

實驗任務1

驗證性實驗:有些彙編指令會影響到標誌暫存器中的一個或多個狀態標誌位。

在debug環境中,分別實踐、觀察:

① add指令對標誌暫存器中的零標誌位ZF(Zero Flag)、進位標誌位CF(Carry Flag)是否有影響?

add指令對標誌暫存器中的零標誌位ZF(Zero Flag)、進位標誌位CF(Carry Flag)均有影響。

② inc指令對標誌暫存器中的零標誌位ZF(Zero Flag)、進位標誌位CF(Carry Flag)是否有影響?

inc指令對標誌暫存器中的零標誌位ZF(Zero Flag)有影響,對進位標誌位CF(Carry Flag)無影響。

使用任意文字編輯器,錄入8086彙編原始碼task1.asm。

assume cs:code, ds:data

data segment
   x dw 1020h, 2240h, 9522h, 5060h, 3359h, 6652h, 2530h, 7031h
   y dw 3210h, 5510h, 6066h, 5121h, 8801h, 6210h, 7119h, 3912h
data ends
code segment 
start:
    mov ax, data
    mov ds, ax
    mov si, offset x
    mov di, offset y
    call add128

    mov ah, 4ch
    int 21h

add128:
    push ax
    push cx
    push si
    push di

    sub ax, ax

    mov cx, 8
s:  mov ax, [si]
    adc ax, [di]
    mov [si], ax

    inc si
    inc si
    inc di
    inc di
    loop s

    pop di
    pop si
    pop cx
    pop ax
    ret
code ends
end start

在程式碼段種,呼叫add128實現對標號x和y處儲存的兩個128位資料相加,結果儲存在x處的連續128個位元組中。

對程式進行彙編、連結,得到可執行程式task1.exe。在debug中除錯程式,並回答問題。

① line31~line34的4條inc指令,能否替換成如下程式碼?你的結論的依據/理由是什麼?

add si, 2 
add di, 2

答;不能被替換,inc指令對進位標誌位無影響,而add指令對進位標誌位有影響。

② 在debug中除錯,觀察資料段中做128位加之前,和,加之後,資料段的值的變化。

相加前

相加後

實驗任務2

使用任意文字編輯器,錄入8086彙編原始碼task2.asm。

assume cs:code, ds:data
data segment
        str db 80 dup(?)
data ends

code segment
start:  
        mov ax, data
        mov ds, ax
        mov si, 0
s1:        
        mov ah, 1
        int 21h
        mov [si], al
        cmp al, '#'
        je next
        inc si
        jmp s1
next:
        mov ah, 2
        mov dl, 0ah
        int 21h
        
        mov cx, si
        mov si, 0
s2:     mov ah, 2
        mov dl, [si]
        int 21h
        inc si
        loop s2

        mov ah, 4ch
        int 21h
code ends
end start

對源程式task2.asm進行彙編、連結,得到可執行檔案task2.exe。

執行程式,從鍵盤上輸入一串字元,以#結束(比如,輸入George Orwell, 1984#),觀察結果。結合執行結果,理解程式碼並回答問題:

① 彙編指令程式碼line11-18,實現的功能是?

判斷輸入的字元是否為“#”,若為“#”則跳轉到next處執行,若不是,則si+1

② 彙編指令程式碼line20-22,實現的功能是?

輸出一個回車符,也就是換行

③ 彙編指令程式碼line24-30,實現的功能是?

輸出字串,但不包括“#”

實驗任務3

針對8086CPU,已知邏輯段定義如下:

data segment 
    x dw 91, 792, 8536, 65521, 2021 
    len equ $ - x 
data ends

編寫8086彙編源程式task3.asm,在螢幕上以十進位制形式輸出data段中這一組連續的資料,資料和資料之間以空格間隔。

要求:

編寫子程式printNumber

功能:以十進位制形式輸出一個任意位數的整數(整數範圍0 ~ 65535)

入口引數:暫存器ax(待輸出的資料 --> ax)

出口引數:無

編寫子程式printSpace

功能:列印一個空格

入口引數:無

出口引數:無

在主體程式碼中,綜合應用定址方式和迴圈,呼叫printNumber和printSpace, 實現題目要求。

assume ds:data, cs:code, ss:stack
 
data segment
    x dw 91, 792, 8536, 65535, 2021
    len equ $ - x
data ends
 
stack segment
    dw 8 dup(0)
stack ends
 
code segment
start:
    mov ax, data
    mov ds, ax
 
    mov ax, stack
    mov ss, ax
    mov sp, 16
 
    mov cx, len/2 ;
    print:
        mov ax, word ptr ds:[di]   
        add di, 2                   
        push cx 
        call printNum    ; 列印數字
        call printSpace     ; 列印空格
        pop cx             
        loop print
     
        mov ah, 4ch
        int 21h
 
printNum:
    mov bx, 0       ; 獲取位數
count:
        mov bp, 10      
        mov dx, 0           
        div bp         
        push dx        
        inc bx          
        mov cx, ax     
        inc cx         
        loop count
        mov cx, bx          ; 將位數賦值,用於迴圈
printcount:
        pop dx          
        add dl, 30h       ;數字轉為字串
        mov ah, 2 
        int 21h
        loop printcount
        ret
 
printSpace:
    mov ah, 2
    mov dl, 20h
    int 21h
    ret
 
code ends
end start

實驗結果

實驗任務4

針對8086CPU,已知邏輯段定義如下:

data segment 
      str db "assembly language, it's not difficult but tedious"              
      len equ $ - str 
data ends

編寫8086彙編源程式task4.asm,將data段中字串裡的小寫字元轉換成大寫。

要求:

編寫子程式strupr

功能:將包含任意字元的字串中的小寫字母變成大寫

入口引數

(ds:si ) 字串首地址的段地址和偏移地址分別送至ds和si

(cx) 字串的長度

出口引數:無

在主體程式碼中,設定入口引數,呼叫strupr, 實現題目要求。

assume cs:code, ds:data
  
data segment
    str db "assembly language, it's not difficult but tedious"
    len equ $ - str
data ends
  
code segment
start:
    mov ax, data
    mov ds, ax
    mov cx, len
    mov si, 0
  
s:
    call strupr
  
    mov cx, len
    mov si, 0
    mov ah, 2

printStr:
    mov dl, ds:[si]
    int 21h
    inc si
    loop printStr
  
    mov ah, 4ch
    int 21h

strupr:
    mov al, byte ptr ds:[si]
    cmp al, 'a'
    jb s0
    cmp al, 'z'
    ja s0
    sub al, 20h
    mov ds:[si], al
      
s0:
    inc si
    loop strupr
    ret

code ends
end start

實驗結果

呼叫前

呼叫後

實驗任務5

使用任意文字編輯器,錄入8086彙編原始碼task5.asm。

assume cs:code, ds:data

data segment
    str1 db "yes", '$'
    str2 db "no", '$'
data ends

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

    mov ah, 1
    int 21h

    mov ah, 2
    mov bh, 0
    mov dh, 24
    mov dl, 70
    int 10h

    cmp al, '7'
    je s1
    mov ah, 9
    mov dx, offset str2
    int 21h

    jmp over

s1: mov ah, 9
    mov dx, offset str1
    int 21h
over:  
    mov ah, 4ch
    int 21h
code ends
end start

對源程式task5.asm進行彙編、連結,得到可執行檔案task5.exe。

執行程式,輸入7,觀察結果。輸入其他字元,觀察結果。結合執行結果和註釋,理解程式碼實現的功能

程式功能

判斷從鍵盤上輸入的字元是否為7,若輸入字元為7,則在螢幕的第24行第70列顯示yes,否則在螢幕的第24行第70列顯示no。

實驗任務6

實驗任務1、2、3、5中使用了不少系統提供的中斷例程。本實驗任務中,要求自行實現一個42號軟中斷例程,

使得通過 int 42 或 int 2ah 軟中斷呼叫,實現在螢幕最下方中間以黑底綠字列印"welcome to2049!"。

建議配合教材第12章學習理解並實踐。

assume cs:code

code segment
start:
    ; 42 interrupt routine install code
    mov ax, cs
    mov ds, ax
    mov si, offset int42  ; set ds:si

    mov ax, 0
    mov es, ax
    mov di, 200h        ; set es:di

    mov cx, offset int42_end - offset int42
    cld
    rep movsb

    ; set IVT(Interrupt Vector Table)
    mov ax, 0
    mov es, ax
    mov word ptr es:[42*4], 200h
    mov word ptr es:[42*4+2], 0

    mov ah, 4ch
    int 21h

int42: 
    jmp short int42_start
    str db "welcome to 2049!"
    len equ $ - str

    ; display string "welcome to 2049!"
int42_start:
    mov ax, cs
    mov ds, ax
    mov si, 202h

    mov ax, 0b800h
    mov es, ax
    mov di, 24*160 + 32*2

    mov cx, len
s:  mov al, [si]
    mov es:[di], al
    mov byte ptr es:[di+1], 2
    inc si
    add di, 2
    loop s

    iret
int42_end:
   nop
code ends
end start
assume cs:code

code segment
start:
    int 42

    mov ah, 4ch
    int 21h
code ends
end start

實驗結果