AVERAGE SCORE
;Description: Program of Project 1 calculating the average score.
;========================================================
;program notes:
;1. Please write a program to calculate the average score of
; the following 3 score groups;
;2. The scores is saved in an array that can be found in the Data segment.
;3. The first item in the score group array is the counts of score members
; in the array, and the last item in the array should be used to save
; the average score.
;4. A template that includes data segment definition is provided. Build
; your program with that template or create your own.
;=====================================================
.MODEL SMALL
.STACK 64
.DATA
SCORETABLE1 DB 5, 90, 92, 96, 82, 94, 00
SCORETABLE2 DB 8, 70, 66, 83, 90, 92, 96, 82, 88, 00
SCORETABLE3 DB 6, 55, 90, 88, 73, 62, 92, 00
.CODE
MAIN PROC FAR ;this is the program entry point
MOV AX, @DATA ;load the data segment address
MOV DS, AX ;assign value to data segment register
;======================================================
MOV SI,OFFSET SCORETABLE1 ;LOAD THE ADDRESS OF SCORETABLE TO BX
MOV CL,[SI] ;STORE THE FIRST ELEMANT OF THE SCORETABLE TO CX(THE COUNT)
MOV DL,[SI]
MOV AX,0
CALL AGAIN
MOV SI,OFFSET SCORETABLE2 ;LOAD THE ADDRESS OF SCORETABLE TO BX
MOV CL,[SI] ;STORE THE FIRST ELEMANT OF THE SCORETABLE TO CX(THE COUNT)
MOV DL,[SI]
MOV AX,0
CALL AGAIN
MOV SI,OFFSET SCORETABLE3 ;LOAD THE ADDRESS OF SCORETABLE TO BX
MOV CL,[SI] ;STORE THE FIRST ELEMANT OF THE SCORETABLE TO CX(THE COUNT)
MOV DL,[SI]
MOV AX,0
CALL AGAIN
MOV AH, 4CH ;set up to
INT 21H ;return to DOS
MAIN ENDP
AGAIN PROC
INC SI
ADD AL,[SI]
ADC AH,00
DEC CL
JNE AGAIN
MOV DH,0
MOV BX,DX
SUB DX,DX
MOV AX,AX
DIV BX
INC SI
MOV [SI],AL
RET
AGAIN ENDP
;=========================================================
END MAIN ;this is the program exit point
DATA INPUT OUTPUT
;In this program, we try to do input from a piece of 74LS245,
; to acquire the state of a set of button switches.
;Then try to do output to a piece of 74LS373 latcher,
; to control a set of LED lights and display the state acquired.
.MODEL SMALL
.STACK 32
.DATA
.CODE
MAIN PROC FAR
MOV AX, @DATA
MOV DS, AX
MOV AX,0
TODO1:
;TODO1: acquire switches
MOV DX, 50H ;load Y2 address
IN AL,DX
;TODO2: out put to PORT_OUT
MOV DX, 48H ;load Y1 address
OUT DX, AL
CALL DELAY;TODO3: call the DELAY subprocedure before loop back to TODO1
JMP TODO1
;TODO3: quit to DOS
MOV AX, 4C00H
INT 21H
MAIN ENDP
;;==============================================================
;Subprocedure: DELAY
;delay for some millseconds
DELAY PROC
PUSH BX;
PUSH CX;
MOV BX,10h
mov CX,00
loop_OUT:
MOV CX, 10h
loop_inner:
DEC CX
JNZ loop_inner
DEC BX
JNZ loop_OUT
POP CX;
POP BX;
RET
DELAY ENDP
END MAIN
LANTERN CONTROL
Microprocessor programming
;========================================================
;Description: Program of Project 3 lantern control circuit.
;Author:
;Student ID:
;Date:3ed June 2022
;========================================================
.MODEL SMALL
.STACK 64
.DATA
; pattern code and control flags
pattern_code DB 01
;LEDS DB 8
.CODE
MAIN PROC FAR
MOV AX, @DATA
MOV DS, AX
CLI
;TODO1: regist _ISR_Timer
PUSH DS ;save current DS value
MOV AX, 0 ;set DS to the segment address of
MOV DS, AX ;DOS interrupt vector table
MOV BX, OFFSET _ISR_Timer ;load IP address value of ISR
MOV SI, SEG _ISR_Timer ;load CS address value of ISR
MOV [0100H], BX ;write IP into 0100H for INT 40H
MOV [0102H], SI ;write CS into 0102H
POP DS ;restore current DS value
;TODO2: initiALize 8259, use IR6 as interrupt source input
;8259 mode: edge triggering, single piece, ICW4 needed;
; Interrupt Number of IR0 is 40H;
; Normal EOI, none buffered mode.
B8259 EQU 310H
MOV AL, 19 ;ICW1 00010011
MOV DX,B8259+2
OUT DX, AL
MOV AL, 40H ;ICW2
MOV DX,B8259+3
OUT DX, AL
MOV AL, 1 ;ICW4 00000001
OUT DX, AL
;TODO3: initiALize 8255: PortA mode0, output
B8255C EQU 1000H;300H ;base address of 8255 chip
CNTL EQU 82H ;define the control word 10000010
MOV DX, B8255C+3 ;load ctrl reg. address
MOV AL,CNTL
OUT DX, AL ;setup the control word reg of 8255
;MOV SI,OFFSET LEDS
;MOV CX,[SI]
;TODO4: OUTput the pattern code to the lantern
; and wait for the 1st interrupt request
MOV AX, @DATA
MOV DS, AX
MOV SI, OFFSET pattern_code
MOV AL,[SI]
MOV DX, B8255C ;load PA address
OUT DX, AL
;TODO5: initialize 8254: Timer0, mode2, initialize value = 20
B8254 EQU 304H
TIMERCNTL EQU 34H ;00110100
MOV DX,B8254+4
MOV AL, 52 ;counter 0, both bytes, mode 0, BCD
OUT DX, AL ;write control word
MOV AL,20 ;
MOV DX,B8254
OUT DX, AL ;send the low byte
;TODO6: open interrup handling, and output interrupt number of IR6
; to port 60H in the follwing FIX_BUG section,
; in order to fix the bug within 8259 element.
STI
FIX_BUG:
MOV DX,60H
MOV AL,(40H+6) ;dump 40H, which is the int number, to data bus
OUT DX,AL
JMP FIX_BUG
;TODO7: quit to DOS
MOV AX, 4C00H
INT 21H
MAIN ENDP
;;==============================================================
;SubrOUTine: _ISR_Timer
_ISR_Timer PROC FAR
CLI
;===========================================
;put your codes here todo:
; load pattern_code, and change it then output if through 8259.PortA
MOV AX, @DATA
MOV DS, AX
MOV SI,OFFSET pattern_code
MOV CL,[SI]
AGAIN:
SUB AX,AX
ROR CL,01H
MOV AL,CL
MOV DX,B8255C+1
OUT DX,AL
;load PA address
MOV DX, B8255C
IN AL,DX
JMP AGAIN
;JZ RESETCX
;MOV AL, 20 ; RESET TIMER
;MOV DX,B8254
;OUT DX, AL
;===========================================
STI
IRET
;RESETCX:
; MOV SI,OFFSET LEDS
; MOV CX,[SI]
_ISR_Timer ENDP
END MAIN ;this is the program exit point