Last active
December 23, 2020 06:17
-
-
Save Joursoir/f1641d32a1769a4585f413f08c3371c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.include "m168def.inc" | |
; start defines | |
.def counter = R16 ; number of array values | |
.def first_v = R17 ; first value | |
.def second_v = R18 ; second value | |
.def temp = R19 ; temporary value | |
.def suit_num = R20 ; suitable numbers | |
; end defines | |
.dseg ; start segment of data | |
.org SRAM_START | |
table: .byte 10 | |
; end segment of data | |
.cseg ; start segment of code | |
;array: .db 2, 4, 8, 12, 8, 10, 12, 14, 16, 18 | |
array: .db 2, 0, 4, 8, 12, 2, 0, 2, 18, 16 | |
ldi ZH, high(array) ; pointer to array | |
ldi ZL, low(array) | |
ldi XH, high(table+1) ; pointer to second value | |
ldi XL, low(table+1) ; in table | |
ldi counter, 10 ; number of value to check | |
ldi suit_num, 0 ; number of suitable numbers | |
start: | |
lpm first_v, Z+ | |
lpm second_v, Z | |
dec counter ; decrease value to check | |
breq final ; end loop if counter == 0 | |
/* if | |
??????1? (...0?) - number 1 | |
??????0? (...1?) - number 2 | |
conclusion: numbers differ by 2 */ | |
andi first_v, 0b10 ; logical AND with 2 | |
mov temp, second_v | |
andi temp, 0b10 ; logical AND with 2 | |
cp first_v, temp | |
brne modulo_by_4 ; if numbers have different second bits | |
; then check his modulo (see above why) | |
rjmp start ; repeat loop | |
modulo_by_4: | |
; 00000000 - 8 bit | |
; ??????00 - number multiplicity by 4 | |
sbrc second_v, 0 ; skip next cmd IF first bit == 0 | |
rjmp start ; otherwise goto main loop | |
sbrc second_v, 1 ; skip next cmd IF second bit == 0 | |
rjmp start ; otherwise goto main loop | |
; add it number to table: | |
inc suit_num ; increase number of suitable numbers | |
st X+, second_v ; current number to X | |
rjmp start ; goto main loop | |
final: | |
sts table, suit_num ; write number of suitable number to | |
; first byte of table | |
end: ; endless loop | |
rjmp end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment