Back to DFS's Workshop Page
Back to Agenda Page
Computers use binary for data and instructions. Here we will take a slightly simplified look at how math can be done in a CPU's registers.
The 6502 CPU was developed by MOS Technology Inc. in 1975 by a team of former Motorola workers. It was a direct competitor of the Motorola 6800 and Intel 8008. (Wikipedia) When used by Apple, Atari and Commodore for their game consoles and home computers, the microcomputer revolution really took off. (It is actually still in use.)
The 6502 has only three registers: the accumulator and the X and Y registers. The accumulator is where almost all comparisons and arithmetic are performed.
For the purposes of these problems we will work with just the following CPU commands which alter what is in the registers. (See the actual 6502 commands/opcodes.)
If the value in an 8-bit register is interpreted as a signed binary value, the total range is from 10000000 to 01111111, -128 to 127, respectively.
Here we will simulate three basic math operations.
All will actually be performed using addition. With regard to multiplication, this should not come as a surprise since it is really repeated addition. The fact that subtraction is actually accomplished with addition is as a result of using fixed size registers.
To see how this could work, view this possible solution.