-
Notifications
You must be signed in to change notification settings - Fork 0
/
fullAdder.asm
91 lines (73 loc) · 2.11 KB
/
fullAdder.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
.include "./mp.inc"
start: ldi r17,0b11000000
out DDRD,r17
level: call delay
call delay
call delay
in r16,PORTD
ldi r22,0b00000000 ;a,b and c
ldi r23,0b00000000
ldi r24,0b00000000
ldi r25,0b00000001 ;temporary value 1 stored in r25
ldi r26,0b00000000 ;sum
ldi r27,0b00000000 ;carry
li1: ldi r19,0b00000001
and r19,r16
subi r19,0b00000001
breq l1
li2: ldi r20,0b00000010
and r20,r16
subi r20,0b00000010
breq l2
li3: ldi r21,0b00000100
and r21,r16
subi r21,0b00000100
breq l3
jmp solver
l1: add r22,r25
jmp li2
l2: add r23,r25
jmp li3
l3: add r24,r25
jmp solver
solver: add r26,r22
eor r26,r23
eor r26,r24 ;sum calculated a ex-or b ex-or c
add r27,r22
and r27,r23
ldi r28,0x00
add r28,r23
and r28,r24
or r27,r28 ;a.b+b.c stored in r26
ldi r28,0x00
add r28,r22
and r28,r24
or r27,r28 ;a.b+b.c +a.c stored in r27
sum: ldi r28,0x00
mov r28,r26
subi r28,0x01
breq final ;if sum==1 then display 1st bit as high
ldi r17,0b00000000 ;if sum==0 then display 1st bit as low
carry: ldi r28,0x00
mov r28,r27
subi r28,0x01
breq final2 ;if carry==1 then display 2nd bit as high
ldi r28,0b00000000 ;if carry==0 then display 2nd bit as low
or r17,r28
final: ldi r17,0b10000000
jmp carry
final2: ldi r28,0b01000000
or r17,r28 ;moving sum and carry into r17 as 1st and 2nd bit respectively
out PORTD,r17 ;show output through port d
call delay
call delay
call delay
jmp level
delay: ldi r29,0xFF
ldi r30,0x3F
ldi r31,0x30
l4: subi r29,0x01
sbci r30,0x00
sbci r31,0x00
brne l4
ret