Addition operation generates SUBI instruction

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

My program is as below, when i try to add a = a +3, the list file has a subtract instruction. Can some one clairy why this is happening? I am using AVRstudio integrated with WinAVR and controller is At90USB1287.

main()
{
unsigned char a, b;
a = 2;
a = a + 3;
}

-------------the corresponding list file is------:

main()
{
d6: cd ef ldi r28, 0xFD ; 253
d8: d0 e2 ldi r29, 0x20 ; 32
da: de bf out 0x3e, r29 ; 62
dc: cd bf out 0x3d, r28 ; 61

unsigned char a, b;

a = 2;
de: 82 e0 ldi r24, 0x02 ; 2
e0: 89 83 std Y+1, r24 ; 0x01
a = a + 3;
e2: 89 81 ldd r24, Y+1 ; 0x01

e4: 8d 5f subi r24, 0xFD ; 253

e6: 89 83 std Y+1, r24 ; 0x01
e8: 0c 94 76 00 jmp 0xec <_exit>

000000ec <_exit>:
ec: ff cf rjmp .-2 ; 0xec <_exit>

Thanks
Bhaskar

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

There is no opcode for add immediate, so the compiler put in a subtract immediate -3.

Regards,
Steve A.

The Board helps those that help themselves.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

a + 3 = a - ( -3)
a + 0x03 = a - (0xFD)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for the response