Electronic – Programming Differences between a Microcontroller and a Microprocessor

assemblymicrocontrollermicroprocessor

So I often see books/tutorials and references when programming in assembly to a microprocessor…..then I see some refer to it as a microcontroller.

For instance the Atmel ATtiny2313….i saw some tutorials on, some call it a microprocessor, some call it a microcontroller?

Which is it? and is programming them (basically) the same? (in assembly)

Best Answer

This is really two questions in one...

Firstly, what is the difference between a microcontroller and a microprocessor?

Microprocessor is a purely a CPU that follows a set of instructions read from an external memory bus. It controls external peripherals (such as screen, keyboard, mouse, hard drive, etc) via an external communications bus. When you program a microprocessor, your program is external to the device. In a computer, this memory is initially the boot up BIOS ROM which initially reads the operating system from the hard drive into RAM memory, then continues to execute it from there.

Microcontroller is kinda like an all-in-one CPU + Memory, with some external ports to communicate with the outside world. It's self contained and doesn't use external memory to hold it's program (although if needed it can read and write working data to external memory).

Secondly, is programming a microcontroller and microprocessor the same?

In some ways yes, and in some ways no.

Assembly language is a broad term that describes a set of instructions that the CPU can directly understand. When you 'compile' assembly language, it doesn't really compile anything, all it does it convert it to a sequence of bytes that represent the commands and plugs in some relative memory locations. This is common to both microprocessors and microcontrollers.

However, different types of CPU understand a different set of CPU instructions. For example, if you write an assembly language program that works with a pic 16F877 microcontroller, it will be complete nonsense to a microprocessor or any other microcontroller outside of the 16Fxxx family of pic microcontrollers.

So, although assembly works in a similar way across all microprocessors and microcontrollers, the actual list of instructions that you write are very different. To write in assembly language, you need to have an in depth knowledge of the device's architecture, which you can normally get from the datasheet in the case of a microcontroller.