1. Using the mov instruction, write a program that swaps the contents of any two registers. Using Listing 1.1 as start point, replace lines 11 to 13 with your own instructions.
In your own words, answer the following questions:
What is the difference between an embedded computer and a gen- eral purpose computer?
What is the difference between processor, microprocessor, and mi- crocontroller?
What is a cross-compiler and why is it needed?
8. Using the xor instruction, write a program that swaps the contents of two registers. To do a = a xor b you have to say, for example, eor r1, r2, where r1 holds a and r2 holds b. The mechanism to swap them is explained in XOR swap algorithm.
To write software for the SAM4S board a cross-compiler is needed. A cross-compiler runs on one computer platform (the host computer), and creates executables for a different platform. Particularly, we will be using the GNU Toolchain for ARM, which, among other tools, includes a C compiler and an assembler.
In the host computer, source code is first compiled into an executable for the ATSAM4SD32C MCU, and then it is transferred to it using a flashing tool. Once the executable is deployed, an on-board chip debugger (Figure 1.4), interfaces with the host to enable debugging of the MCU.
All of the different host-side softwaretools needed for development are integratedin Atmel Studio. Communication betweenthe target platform and host is via USB. Fig-ure 1.6 depicts, in a simplified manner, thedescribed programming environment.
The Atmel SAM4S Xplained Pro Starter Kit shown in Figure 1.5a is com-posed of the SAM4S board (the main board), and three more daughter boards: IO1, OLED1, and PROTO1. The SAM4S board uses an AtmelATSAM4SD32C MCU for processing. This MCU has 160 KB of SRAM as main memory, 2 KB of cache, an ARM Cortex-M4 as processor, and a max clock frequency of 120 Mhz.
The next step in this shrinking process is to integrate CPU, memory, and I/O into a single die; and this is exactly what micro-controllers do. A micro-controller (MCU) is a computer in a die. From the outside, they look just as any other regular IC, and often are indistinguishable from MPUs.
MCUs and MPUs serve different purposes.The former ones are easier to connect with the world because I/O peripherals are built in. Also, there is no need for a memory controller,nor the memory itself to be placed in a motherboard together with the MPU. This means the effort that goes into designing MCU-based computer boards is less. Different MCUs have different I/O peripherals, from timers and clocks to Ethernet and USB controllers. The fewer external components required by a MCU allows for smaller computer boards and reduced production cost; which is good for, say, a washing machine manufacturer.
MCUs are typically the choice in small electronic systems such as computer keyboards, hard drives, refrigerators, anti-theft alarms, IoT objects,and even small robots. Modern cars, in particular, are a very good example of how ubiquitous MCUs have become given that they are shipped with no fewer than fifty of them.
Nevertheless, MCUs are constrained in memory and CPU sophistication. The capacity of main memory seldom surpasses 512 KB; cache sizes go from none to a few KB; the fastest of them run at no more than a few hundreds of MHz;and certain more advanced CPU features such as memory management unit are not present. This is why MPUs are used in applications that demand more resources or more sophistication. Applications such as laptops, tablets, mobile phones, bank machines, WiFi routers, industrial and military robots, and aircraft systems. Incidentally, all these computer systems typically have micro-controllers for secondary processing. In other words, computers often have smaller computers alongside it doing specialized subtasks.
Now let us introduce the SAM4S board, which will serve as computer for the remaining of this book.
A processor or central processing unit (CPU) is the hardware that executes instructions in a computer, and it is composed of circuitry such as registers, the arithmetic logic unit, and the control unit. All these components can each be obtained as integrated circuits (ICs), also known as microchips,and placed together in a circuit board as shown in Figure 1.1. In fact, that is how computers were built in the past. However, for other than educational purposes, there is absolutely no reason to do this any more, as processors themselves are now built as ICs. To be more precise, they are built into a very specific part of an IC, a single piece of semiconducting material known as die¹.
Microprocessors (MPUs) are processors built in adie; the die integrates all the transistors that form all the components of a CPU. Figure 1.2 shows the Eniac-on-a-chip, a die replica of the first general-purpose computer, which weighted over thirty metric tons
A microprocessor by itself is not a computer.It would require at least some form of memory and I/O to make one. In the case of a desktop computer or laptop, all these components are soldered as part of the motherboard. Is it possible to make computer boards even smaller? The short answer is yes, and in the next section we discuss how micro-controllers achieve this.
We generally associate the term computer with laptops, desktop computers, or even mobile devices. This is only a very small sample of computers, however. Most computers exist as part of other systems (say mechanical or electronic systems), and they range from simple coffee makers to incredibly complex aircraft navigation systems. These computers are referred to as embedded, and are different in that they are dedicated special purpose devices. Unlike general-purpose computers, embedded ones tend to serve a single purpose throughout their lifetime. Consider an everyday printer. While it is possible to replace printer software with software of a different type, only more printer software would make sense. Embedded computers can be built from either microprocessors or micro-controllers. Let us look explore the differences.