I see that one command is arifmetic and another one is logical. But is there a difference when we use them?🤔
What's the difference between commands ADD and OR?
Welcome to AVRFreaks!
Yes, the difference is when ADD causes overflow. You can simulate it.
Thanks! I see. So there's only a difference with flags. Arithemic operations consist flag C and H when logical don't. Am I right?
Consider ORing 9 | 10 :
9 (decimal) = 0x09 (hex) = 0b00001001 binary
| 10 (decimal) = 0x0A (hex) = 0b00001010 binary
11 (decimal) = 0x0B (hex) = 0b00001011 binary
Consider ADDng 9 + 10 :
9 (decimal) = 0x09 (hex) = 0b00001001 binary
+ 10 (decimal) = 0x0A (hex) = 0b00001010 binary
19 (decimal) = 0x13 (hex) = 0b00010011 binary
In this example, the least significant 3 bits are the same for ADD and OR, but there is a carry from the 4th bit into the 5th bit.
ADD is the same as an XOR plus a carry into the next (more) significant bit.
Consider XORng 9 ^ 10 :
9 (decimal) = 0x09 (hex) = 0b00001001 binary
^ 10 (decimal) = 0x0A (hex) = 0b00001010 binary
03 (decimal) = 0x03 (hex) = 0b00000011 binary
Thanks! I see. So there's only a difference with flags. Arithemic operations consist flag C and H when logical don't. Am I right?
No.
0x01 ADD 0x01 is 0x02
0x01 OR 0x01 is 0x01
Thank you, I got it)
Thank you for your such a detailed answer 🙂
Thanks
So, you see some rules: bits does counts.
If you are sure that reg1 does have 4 lowest bits '0', then ADD and OR with 4 bits reg2 will do the same.
I see that one command is arifmetic and another one is logical. But is there a difference when we use them?🤔
What do you mean ???? One is used for adding (ADD) & one is used for the OR function (OR)...why didn't you bother to read about what they do?
Did you look at the difference between the ADC and Timer1? Study the instruction set thoroughly and work out examples---that is the key to your success.
add
Go on! AVR Assembler is a perfect new language to learn. Proceeds with ADC which is for 16 or more bits addition. Do learn instructions as they appear in your code.
You will never need all of them (80, perhaps).
"ATmega32" instruction use summary:
.lds : 0 .sts : 0 adc : 140 add : 149 adiw : 21 and : 30
andi : 78 asr : 2 bclr : 0 bld : 6 brbc : 0 brbs : 0
brcc : 31 brcs : 55 break : 0 breq : 199 brge : 1 brhc : 0
brhs : 0 brid : 0 brie : 0 brlo : 97 brlt : 6 brmi : 10
brne : 318 brpl : 15 brsh : 35 brtc : 7 brts : 0 brvc : 0
brvs : 0 bset : 0 bst : 3 call : 793 cbi : 111 cbr : 16
clc : 6 clh : 0 cli : 2 cln : 0 clr : 194 cls : 0
clt : 2 clv : 0 clz : 5 com : 44 cp : 43 cpc : 42
cpi : 241 cpse : 75 dec : 199 eor : 54 fmul : 0 fmuls : 0
fmulsu: 0 icall : 0 ijmp : 30 in : 31 inc : 140 jmp : 122
ld : 153 ldd : 86 ldi :1528 lds : 612 lpm : 21 lsl : 64
lsr : 69 mov : 427 movw : 148 mul : 18 muls : 0 mulsu : 0
neg : 3 nop : 74 or : 51 ori : 1 out : 72 pop : 273
push : 258 rcall : 739 ret :1020 reti : 4 rjmp : 828 rol : 50
ror : 67 sbc : 34 sbci : 61 sbi : 84 sbic : 10 sbis : 2
sbiw : 4 sbr : 24 sbrc : 148 sbrs : 94 sec : 10 seh : 0
sei : 2 sen : 0 ser : 25 ses : 0 set : 3 sev : 0
sez : 2 sleep : 1 spm : 0 st : 176 std : 32 sts : 615
sub : 40 subi : 124 swap : 23 tst : 143 wdr : 0
Instructions used: 83 out of 113 (73.5%)
Likewise...
...that's in code that fills 59.1% of a '328.