Hi,
I tried four examples here, compiled for a 16F628.
First test:
Code:
IF CODE_ONE = 13 and CODE_TWO = 13 and CODE_THREE = 16 and CODE_FOUR = 21 and CODE_FIVE = 32 THEN
'Correct code
ENDIF
Result: 75 WORDS
Second test:
Code:
If CODE_ONE = 13 THEN
IF CODE_TWO = 13 then
if CODE_THREE = 16 then
if CODE_FOUR = 21 then
if CODE_FIVE = 32 THEN
'correct code
Endif
endif
endif
endif
endif
Result: 26 WORDS
Third test:
Code:
IF CODE_ONE <> 13 THEN EXIT_TO_ERROR
IF CODE_TWO <> 13 THEN EXIT_TO_ERROR
IF CODE_THREE <> 13 THEN EXIT_TO_ERROR
IF CODE_FOUR <> 13 THEN EXIT_TO_ERROR
IF CODE_FIVE <> 13 THEN EXIT_TO_ERROR
'correct code
EXIT_TO_ERROR:
RESULT: 26 WORDS (same as test 2)
Forth test:
This one uses an array to hold the entered code and assumes that the correct password sequence is stored in EEPROM, starting at location 0
Code:
Correct = 1
For i = 0 to 4
Read i, Password
if Code[i] <> Password THEN
Correct = 0
ENDIF
NEXT
If Correct THEN
'correct code
endif
RESULT: 41 WORDS
So between these four method 2 or 3 produces the smallest code - by far. Personally I think Aerostars suggestion is the easiest to read but that might just be me...
/Henrik.
Bookmarks