Computer Basics
How does computer perform 3+5 ?
CPU can not understand 3+5, but it understands Load, Add, and Store commands.
A high level instruction needs to be "compiled / translated" into a low level commands (assembly).
CPU execution relies on commands and data. Both commands and data are stored in memory.
CPU reads/writes memory via a bus.
Bus has address lines, data lines, and control lines.
CPU uses program counter (pc) to keep track of which command he is executing in program memory.
What is 3? How does computer represent it? (binary system)
How do we convert number from decimal to hex or vice versa?
There are standard mathematical approach to solve it. But, my favorite is to use programs.
int i=34, j=0x34;
cout << hex << i ; // will print i in hex
cout << dec << j ; // will print j in decimal
If you're not familiar with the subject, I highly recommend studying the following two web pages before moving to control LED lights.
Binary and Hexadecimal number systems and
Controlling LED lights
Each data stored in memory has an address. &a is the address of a.
When computer has LED lights, it usually has a memory address too. It is called Memory Mapped IO.
Why do we use memory mapped IO to control LED?
Two LED (Red and Green) may occupy two different address.
It may occupy the same address, but different data bit (b0 for R, b2 for G below)
What's the tradeoff?
How to control in each case?
Things to learn
how computer executes a program
what's inside a CPU
how CPU interacts with memory
how CPU interacts with IO
binary system
bitwise logic.... Want more detail? LED ON/OFF