Você está na página 1de 4

;Platias Odysseas 8525

;Tzikas Rigas 8589

.include "m16def.inc"

.CSEG

.ORG 0x00

JMP reset
AEM1_LABEL:
.DW 0x38,0x35,0x32,0x35 ;store AEM1 8525 as ASCII

AEM2_LABEL:
.DW 0x38,0x35,0x38,0x39 ;store AEM2 8589 as ASCII

.CSEG

reset:
LDI R25, LOW(RAMEND) ;Initialize stack pointer
OUT SPL, R25
LDI R25, HIGH(RAMEND)
OUT SPH, R25

LDI R20, $FF ;portb output


OUT DDRB, R20

LDI R20, $FF ;leds off


OUT PORTB, R20

LDI ZH, HIGH (2*AEM1_LABEL) ;load aem numbers on registers


LDI ZL, LOW (2*AEM1_LABEL)
LPM
MOV R16,R0
ADIW ZL,2
LPM
MOV R17,R0
ADIW ZL,2
LPM
MOV R18,R0
ADIW ZL,2
LPM
MOV R19,R0

; convert from ASCII to BCD


SUBI R16, 0x30
SUBI R17, 0x30
SUBI R18, 0x30
SUBI R19, 0x30
LSL R16
LSL R16
LSL R16
LSL R16
LSL R18
LSL R18
LSL R18
LSL R18
CLR R2
CLR R3
ADD R2, R16
ADD R2, R17
ADD R3, R18
ADD R3, R19

LDI ZH, HIGH (2*AEM2_LABEL) ;same for AEM2


LDI ZL, LOW (2*AEM2_LABEL)

LPM
MOV R16,R0
ADIW ZL,2
LPM
MOV R17,R0
ADIW ZL,2
LPM
MOV R18,R0
ADIW ZL,2
LPM
MOV R19,R0

SUBI R16, 0x30


SUBI R17, 0x30
SUBI R18, 0x30
SUBI R19, 0x30
LSL R16
LSL R16
LSL R16
LSL R16
LSL R18
LSL R18
LSL R18
LSL R18

CLR R4
CLR R5
CLR R6
CLR R7
CLR R8

ADD R4,R16
ADD R4,R17
ADD R5,R18
ADD R5,R19

RCALL rCompare
BRGE AEM1_Bigger ;if AEM1<AEM2
BRLO AEM2_Bigger ;otherwise

AEM1_Bigger:
COM R5
OUT PORTB, R5 ;LEDS ON
RCALL Delay
OUT PORTB, R20 ;LEDS OFF
COM R5
RJMP compareAEM1

AEM2_Bigger:

COM R3
OUT PORTB, R3 ;LEDS on
RCALL Delay
OUT PORTB, R20 ;LEDS off
COM R3
RJMP compareAEM2

;odd/even
;So you can tell whether an integer is even or odd by looking only at the lowest-
order bit:
;If it's set, the number is odd.
;If not, it's even.
compareAEM1:

LDI R16, 0
LDI R17, 1 ;register R3 has the last 2 digits of the AEM1
BST R3,0 ;copy bit0 of R3 to bit0 of R6
BLD R6,0
CP R6,R16
BREQ evenAEM1
BRNE oddAEM1

evenAEM1:
ADD R7, R17;
RJMP compareAEM2

oddAEM1:
ADD R7, R16
RJMP compareAEM2

compareAEM2: ;same for AEM2


BST R5,0 ;copy bit0 of R2 to bit0 of R6
BLD R8,0
CP R8,R9
BREQ evenAEM2
BRNE oddAEM2

evenAEM2:
ADD R7, R9
RJMP LEDS

oddAEM2:
LDI R17, 2
ADD R7, R17
RJMP LEDS

LEDS:
COM R7
OUT PORTB, R7
rjmp end
end:RJMP end

rCompare:
CP R3,R5 ; compare lower bytes
CPC R2,R4 ; compare upper bytes
RET

Delay: ;Delay loop for 4 sec for the frequency 4 Mhz

ldi R21, 82
ldi R22, 43
ldi R23, 0
L1: dec R23
brne L1
dec R22
brne L1
dec R21
brne L1
RET

Você também pode gostar