0% found this document useful (0 votes)
88 views5 pages

EE323 Assignment 2 Solution

This document contains the code for a microprocessor program that functions as a binary clock. It uses two ports, P1 and P2, to display the seconds and minutes respectively. The code increments the seconds value stored in register R0 each time through the loop and displays it on port P1. It similarly increments the minutes value in R1 each time and displays it on port P2. It resets the values to 00 after reaching 59.

Uploaded by

MuhammadAbdullah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
88 views5 pages

EE323 Assignment 2 Solution

This document contains the code for a microprocessor program that functions as a binary clock. It uses two ports, P1 and P2, to display the seconds and minutes respectively. The code increments the seconds value stored in register R0 each time through the loop and displays it on port P1. It similarly increments the minutes value in R1 each time and displays it on port P2. It resets the values to 00 after reaching 59.

Uploaded by

MuhammadAbdullah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

EE-323 Microprocessor Interfacing

Fall 2014

Q2. org 0H

HB EQU R0 ; higher byte for dividend
LB EQU R1 ; lower byte for dividend
DIVD EQU R2 ; divisor
ANSHB EQU R3 ; higher byte of quotient
ANSLB EQU R4 ; lower byte of quotient
REMAIN EQU R5 ; remainder

MOV HB,#00H ; values stored
MOV LB,#0F7H ;
MOV DIVD,#0FFH ;

MOV A,HB ;checking if dividend is smaller than divisor
JNZ X1 ; if higher byte is non zero then jump to normal program
MOV A,LB ;if higher byte is zero compare lower byte with divisor
MOV B,DIVD ;
CJNE A,B,LESS ; if LB not = DIVD then check which is larger dest or source
MOV ANSHB,#0 ; if LB=DIVD (HB=0) then its a special case in which quotient=1
MOV ANSLB,#01H ;and remainder=0
MOV REMAIN,#0 ;
SJMP $ ;end program
;
LESS: JNC X1 ;if c=0 dest>source (LB>DIVD) jump to normal program
MOV ANSHB,#0 ;if c=1 dest<source (LB<DIVD) then dividend is smaller than divisor
MOV ANSLB,#00H ;this is a special case quotient -=0 and remainder=LB of dividend
MOV REMAIN,LB ;
SJMP $ ;end program
;
;
X1: MOV A,LB ; mov LB into a to carry out subtration
SUBB A,DIVD ;
MOV LB,A ; store the answer after subtraction back into LB
;
JC N1 ; if there is a carry we need to decrement HB
;
MOV A, ANSLB ; if no carry after subtration then inc lower byte of answer
ADD A, #01 ;
MOV ANSLB,A ;
JC HIGHANS ; check for carry if the answer LB produces a carry then increment
; the HB of answer
SJMP X1 ; jump back to subtract again
;
N1: CLR C ; this portion we have to increment higher byte of answer
MOV A, ANSLB ; increment quotient's LB
ADD A, #01 ;
MOV ANSLB,A ;
JNC N2 ; if there is a carry after inc quotient's LB then next inst. is executed
INC ANSHB ; increment quotient's HB
CLR C ; clear carry so after next addition/subb we can detect carry
N2: DJNZ HB, X1 ; decrement higher byte of dividend, if it is not zero then repeat subtraction
; when HB of dividend is zero then we only have to worry about the
; LB (lower byte)
X2: MOV A,LB ; X2 is same as before.
SUBB A,DIVD ; subtract DIVID from LB
MOV LB,A ; saves value back into LB
;
MOV A, ANSLB ; increment quotient's lower byte and if there is a carry
ADD A, #01 ; increment the quotient's higher byte
MOV ANSLB,A ;
JC HIGHANS1 ;
EE-323 Microprocessor Interfacing
Fall 2014

;
MOV A,LB ; compare LB and DIVD to check when LB < DIVD
MOV B,DIVD ;
CJNE A,B,CHECK ;
SJMP X2 ; if LB=DIVD go back and subtract again
;
CHECK: JC OUT ; if LB<DIVD then go to label out
JNC X2 ; if LB>DIVD then go to label X2
OUT: ;
MOV REMAIN, A ; save remainder
SJMP $ ;

HIGHANS: INC ANSHB ; increment the higher byte of the answer when the jump originates from X1
CLR C ;
SJMP X1 ;

HIGHANS1: INC ANSHB ; increment the higher byte of the answer when the jump originates from X2
CLR C ;
SJMP X2 ;
END ;
EE-323 Microprocessor Interfacing
Fall 2014


Q4.
(a) Hex file separated in fields:
CC AAAA TT DDDDDDDDDDDDDDDDDDDDDDD SS
:10 0000 00 75900075A000E82401D4F8F590B459F6 75
:10 0010 00 7800E8F590E92401D4F9F5A0B459E779 1E
:06 0020 00 00E9F5A080E0 FC
:00 0000 01 FF

(b) Checksum byte
10+00+00+00+79+90+00+75+A0+00+E8+24+01+D4+F8+F5+90+B4+59+F6 = 88B H
Ignoring the carries = 8B H
Its 2s complement = 75

(c) The list file is shown below
Line I Addr Code Source

1: N 0000 org 0H
2: 0000 75 90 00 MOV P1,#0H ; initialization
3: 0003 75 A0 00 MOV P2,#0H
4:
5: 0006 E8 BACK: MOV A,R0 ; R0 holds the second value
6: 0007 24 01 ADD A, #01 ; increment of one
7: 0009 D4 DA A ; decimal adjust
8: 000A F8 MOV R0,A ; save the value back in R0
9: 000B F5 90 MOV P1,A ; display the sec value on Port 1
10:
11: 000D B4 59 F6 CJNE A,#59H, BACK ; comparison if second is 59 then
; next line is executed otherwise go to BACK
12:
13: 0010 78 00 MOV R0,#0H ; after 59s we get 00s
14: 0012 E8 MOV A,R0 ; move value to ACC
15: 0013 F5 90 MOV P1,A ; display the value on Port1
16:
17: 0015 E9 MOV A,R1 ; R1 hold the minute value
18: 0016 24 01 ADD A,#01 ; inc of 1
19: 0018 D4 DA A ; decimal adjust
20: 0019 F9 MOV R1,A ; save the value back in R1
21: 001A F5 A0 MOV P2,A ; display the min value on P2
22:
23: 001C B4 59 E7 CJNE A, #59H, BACK ; comparison if minute is 59 then
;next line is executed otherwise go to back
24:
25: 001F 79 00 MOV R1,#0H ;
26: 0021 E9 MOV A,R1 ; move value to ACC
27: 0022 F5 A0 MOV P2,A ; display the value on Port1
28: 0024 80 E0 SJMP BACK ;
29: END

You might also like