Escolar Documentos
Profissional Documentos
Cultura Documentos
.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
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
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
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
ldi R21, 82
ldi R22, 43
ldi R23, 0
L1: dec R23
brne L1
dec R22
brne L1
dec R21
brne L1
RET