To perform arithmetic with the 6502 requires various manipulations to get around what could be seen as a major limitation, when compared to other microprocessors – the 6502 only has addition and subtraction instructions! You may wonder how it is possible to perform division and multiplication! Well, thankfully it is possible.
We can perform addition by using the instruction ADC. ADC means ADd with Carry. Before addition we need to make sure that the carry is clear, so we use CLC, which is CLear Carry.
When two numbers are added together, the 6502 produces an 8-bit number with a carry-bit.
The way that this works is by comparing each digit. 1 + 1 = 10. The 0 becomes the least most significant bit of the result and the 1 is carried over. The next seven calculations are 0 + 0 = 0.
Increment and decrement
There are instructions that allow us to increment and decrement a value. You may wonder why these are included in a section on arithmetic but these instructions are a form of arithmetic! The increment and decrement instructions add and subtract 1 to a number and therefore provide a means of performing addition and subtraction when you want to add or subtract 1.
INX and INY can be used to increment the value of the X and Y registers respectively.
DEX and DEY can be used to decrement the value of the X and Y registers respectively.
There are 2 further instructions, INC and DEC, which increment and decrement a value in a given memory address.