微機系統與介面實驗考試題目(2014級題目-04)

荷葉田田_發表於2018-01-26

微機系統與介面實驗考試題目(2014級題目-04)

題目要求:採用X86組合語言實現如下功能:

迴圈輸出方波、三角波、鋸齒波,任意撥動開關則只迴圈當前波;

注:受限於實驗環境,本次實驗的程式碼未經測試;

分析:開闢一個公共變數liu,用以判斷撥動開關後進入中斷還是連續輸出三種波形;

程式碼:
;三種混合
PUBLIC FLAG

PUBLIC liu
DATA SEGMENT
liu DB 00H
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE
START:
   MOV AX,DATA
   MOV DS,AX
   LEA SI,FLAG
   MOV BX,[SI]

  MOV AX, OFFSET MIR6  ;取中斷服務程式的偏移地址
    MOV SI, 0038H  ;中斷號6的向量起始地址,見實驗講義P48
    MOV [SI], AX   ;將服務程式地址填入中斷向量(佔兩個位元組)
    MOV AX, CS     ;取段地址
    MOV SI, 003AH  ;中斷向量後移兩個位元組等待存入段地址
    MOV [SI], AX   ;將段地址存入中斷向量(佔兩個位元組)
    ;中斷向量共四個位元組大小,分別存服務程式入口地址和段地址
 

CLI            ;遮蔽所有可遮蔽中斷,準備寫入命令字
    MOV AL, 11H    ;主片8255埠地址詳見實驗講義P44
    OUT 20H, AL    ;命令字ICW1,11H=00010001B
    MOV AL, 08H
    OUT 21H, AL    ;命令字ICW2,08H=00001000B
    MOV AL, 04H
    OUT 21H, AL    ;命令字ICW3,04H=00000100B
    MOV AL, 01H
    OUT 21H, AL    ;命令字ICW4,01H=00000001B
    MOV AL, 3FH
    OUT 21H, AL    ;命令字OCW1,3FH=00111111B
    STI            ;控制字寫入完成,允許中斷,結束CLI
    ;OCW1命令字表示除IR6,IR7中斷外其餘中斷均被遮蔽
    ;其餘命令字含義請對照實驗講義P45-P48



   
    MOV DX,06C0H
    MOV AL,00H
    OUT DX,AL

  

SANJIAO:
Z1:

MOV AL,00H
   MOV DX,0600H
   MOV CX,2
   
   MOV BX,01H
Z2:OUT DX,AL
   CALL DELAY
   INC AL

   INC AL
   INC AL
   CMP AL,0C0H
   JB Z2
   
   ;JNZ Z2

Z3:OUT DX,AL
   CALL DELAY
   DEC AL

   DEC AL
   DEC AL
   CMP AL,00H
   JA Z3
   ;JNZ Z3
   LOOP Z2
 CMP LIU,00H
JNZ SANJIAO

FANGBO:
   MOV CX,2
   X1: 
    MOV AL,00H
    MOV DX,0600H 
    OUT DX,AL
    CALL DELAY1
    
    MOV AL,0C0H
    OUT DX,AL
    CALL DELAY1
    LOOP X1
 CMP LIU,00H
JNZ FANGBO
 
JUCHI: 
   MOV AL,00H
   MOV DX,0600H
   MOV CX,2
ZZ2:
   MOV BX,02H
   OUT DX,AL
   CALL DELAY
   CALL DELAY
   INC AL
   INC AL
	INC AL
   INC AL
   INC AL
   CMP AL,0C0H
   JB ZZ2   
   ;JNZ Z2	
	MOV AL,00H		
   ;JNZ Z3
   LOOP ZZ2

 CMP LIU,00H
JNZ JUZHI

   JMP Z1

       
MIR6:  
 
  NOT LIU
    ;按下KK1+進入MIR6中斷,
    MOV AL, 20H    ;命令字OCW2,20H=00100000B,表示結束中斷
    OUT 20H, AL    ;寫入OCW2,結束中斷
    IRET   
X0: 
    MOV AL,00H
    MOV DX,0600H
    MOV CX,0FFH
    ;JMP SANJIAO
    JMP Z1
X2: 
    MOV CX,0FFH
    ;JMP FANGBO
    JMP X1
X3: 
    MOV AL,00H
    MOV DX,0600H
    MOV CX,0FFH
    ;JMP JUCHI
    JMP ZZ2
DELAY:
    PUSH CX
    MOV  CX,02FFH
AA0:
    PUSH AX
    POP  AX
    LOOP AA0
    POP  CX
    RET
    
DELAY1:
    PUSH CX
    MOV  CX,0FFFFH
BB0:
    PUSH AX
    POP  AX
    LOOP BB0
    POP  CX
    RET
CODE ENDS
END START

相關文章