14 June 2010

Understanding Processor Architecture: Machine and Assembly Language

The processor understands only the machine language, whose instructions consist of strings of 1s and 0s. Machine language is closely related to the assembly language. We prefer to use the assembly language rather than the machine language. Programming in the assembly language also requires knowledge about the processor architecture.

Assembly language programming is referred to low-level programming because each assembly language instruction performs a much lower-level task compared to an instruction in a high-level language. Assembly language instructions are processor specification dependents. For example, a program written in the Intel assembly language cannot be executed on the PowerPC processor.

Here are some IA-32 assembly language examples:
inc result
mov class_size, 45
and mask1, 128
add marks, 10

The first instruction increments the variable result. This assembly language instruction is equivalent to


in C. The second instruction initializes class_size to 45. The equivalent statement in C is

class_size = 45;

The third instruction performs the bitwise and operation on mask1 and can be expressed in C as

mask1 = mask1 & 128;

The last instruction updates marks by adding 10. In C, this is equivalent to

marks = marks + 10;

We can translate the assembly language instructions to the equivalent machine language instructions. Machine language instructions are written in the hexadecimal number system. Here are some IA-32 machine language examples:



Machine language (in hex)


No operation90

inc result


mov class_size, 45


and mask, 128

Logical and80260E0080

add marks, 10

Integer addition83060F000A


  • Guide to RISC Processors for Programmers and Engineers by Sivarama P. Dandamudi, Springer (2005), ISBN 0-387-21017-2.

03 November 2008

P89V51 code SVN

I have decided to open my small project on SDCC c code for P89V51. This project is open source. It is distributed under GNU General Public License.

How to download?

Use this command to anonymously check out the latest project source code

svn checkout http://p89v51-sdcc.googlecode.com/svn/trunk/ p89v51-sdcc-read-only

Or, please find the compressed files (.zip, .gz) from the project page


If found bugs or got troubles, please feel free to report here.


22 April 2007

Build Your Own ARM Cross Compiler Toolchain

GNUARM is a set of open source GNU compiler for ARM microcontroller. The toolchain consists of the GNU binutils, GCC compiler set, Newlib and Insight, the graphical user interface to GNU debugger for Windows and Linux. This article will guide the building process of GNUARM toolchain only for Linux users. For Windows users, there have the installer executable EXE files already. www.scienceprog.com has a tutorial on setting up this tool on Windows environment.

Get the sources
I will demonstrate the building process for GCC-4.1 only. For the others version, you can find the GNUARM distributions files from here. Here is the list of files that are required for the installation.

  • binutils-2.17.tar.bz2 [13.1MB]

  • gcc-4.1.1.tar.bz2 [37.3MB]

  • newlib-1.14.0.tar.gz [7.61MB]

  • insight-6.5.tar.bz2 [20.4MB]

I compiled the sources code with gcc-4.1.1 on Fedora Core 6 (kernel-2.6.18). Note that I built the toolchain as root. I also wanted the arm-target stuff separate from my Linux-native stuff, so I put the toolchain in /usr/local/gnuarm.

Building Instruction
[home]# tar xvf binutils-2.17.tar.bz2
[home]# tar xvf gcc-4.1.1.tar.bz2
[home]# tar xvf newlib-1.14.0.tar.gz
[home]# tar xvf insight-6.5.tar.bz2
[home]# cd binutils-2.17
[binutils-2.17]# ./configure --target=arm-elf \
--prefix=/usr/local/gnuarm --enable-interwork --enable-multilib
[binutils-2.17]# make all install
[binutils-2.17]# export PATH="$PATH:/usr/local/gnuarm/bin"
[binutils-2.17]# cd ../gcc-4.1.1
[gcc-4.1.1]# ./configure --target=arm-elf \
--prefix=/usr/local/gnuarm --enable-interwork \
--enable-multilib --enable-languages="c,c++" \
--with-newlib --with-headers=../newlib-1.14.0/newlib/libc/include
[gcc-4.1.1]# make all-gcc install-gcc
[gcc-4.1.1]# cd ../newlib-1.14.0
[newlib-1.14.0]# ./configure --target=arm-elf \
--prefix=/usr/local/gnuarm --enable-interwork --enable-multilib
[newlib-1.14.0]# make all install
[newlib-1.14.0]# cd ../gcc-4.1.1
[gcc-4.1.1]# make all install
[gcc-4.1.1]# cd ../insight-6.5
[insight-6.5]# ./configure --target=arm-elf \
--prefix=/usr/local/gnuarm --enable-interwork --enable-multilib
[insight-6.5]# make all install

Now, I hope everthing is done. You can test by running arm-elf-gcc command in the shell.

19 April 2007

8051 mcu, von Neumann vs Harvard Architectures

We can classify computer architectures into two categories:

von Neumann architecture: computers has a single, common memory space in which both program instructions and data are stored. There is a single internal data bus that fetches both instructions and data. They can not be performed at the same time.

Harvard architecture: computers have separate memory areas for program instructions and data. There are two or more internal data buses, which allow simultaneous access to both instructions and data. The CPU fetches program instructions on the program memory bus.

The 8051 microcontrollers (MCS-51) have an 8-bit data bus. They can address 64K of external data memory and 64K of external program memory. These may be separate blocks of memory, so that up to 128K of memory can be attached to the microcontroller. Separate blocks of code and data memory are referred to as the Harvard architecture. A single block of memory may be mapped to act as both data and program memory. This is referred to as the Von Neumann architecture.

The 8051 has two separate read signals, RD# (P3.7) and PSEN#. The RD# (P3.7) is activated by clearing to logic level 0 when a byte is to be read from external data memory, PSEN#, from external program memory. All external code is fetched from external program memory. The bytes from external program memory may be read by special read instructions such as the MOVC. And there are separate instructions to read from external data memory, such as the MOVX instruction. In order to read from the same block using either the RD# signal or the PSEN# signal, the two signals are combined with a logic AND operation. This way, the output of the AND gate is low when either input is low.

By adopting the Von Neumann architecture, code may be written to memory as data bytes, and then executed as program instructions.

Further Reading

12 April 2007

Microcontroller Programmer DIY

I search about this issue for a while, "Building programmer of our own designs". I found a few of open source programmer projects so that every body can use and contribute it. Here is an opportunity of learning the microcontroller programmer designs from that open schematics.

Here is a list of Microcontroller Programmer, Do It Yourself (DIY).
  • ATMEL 89C Series Flash Microcontroller Programmer Ver 1.1 - This programmer was designed in view of to be flexible, economical and easy to built, the programmer hardware utilizes the standard TTL series parts and no special components are used. The programmer is interfaced with the PC parallel port and there is no special requirement for the PC parallel port, so the older computers can also be used with this programmer.

  • Atmel 89C2051 In-Circuit Programmer Schematic - The idea is to add this circuitry to a board with already has ram at 2000 and an 82C55 I/O chip to provide ports A, B and C. This is a "beta release" schematic. Use at your own risk

  • ISP Flash Microcontroller Programmer Ver 3.0 - This ISP Programmer can be used either for in-system programming or as a stand-alone spi programmer for Atmel ISP programmable devices. The programming interface is compatible to STK200 ISP programmer hardware so the users of STK200 can also use the software which can program both the 8051 and AVR series devices.

  • Atmel AT89Cx051 programmer

  • PIC
  • PP06 PIC Programmer Software - PP06 is an open-source Production programmer for Microchip's PIC micros. Specifically designed for use in factory in-circuit programming, and development of master/slave systems it supports many pics,and is easily extended to different hardware.

  • Classic PIC Programmer - The classic PIC 16C84/16F84 programmer. The design is originally by David Tait and modified by Bob Blick

  • AVR
  • AVR911: AVR Open-source Programmer - The AVR Open-source Programmer (AVROSP) is an AVR programmer application that replaces the AVRProg tool included in AVR Studio. It is a command-line tool, using the same syntax as the STK500 and JTAGICE command-line tools in AVR Studio.

  • AVR In-System Programmer - They provide details on our version of the Atmel AVR In-System Programmer (ISP). They provide schematics and printed circuit board (PCB) art to allow you to construct your own programmer.

09 April 2007

Learn Embedded Linux with ARMulator

uClinux is an excellent way to study the embedded operating systems for an engineer, student, hobbyist, Linux-enthusiast. I am interested in Embedded Linux for ARM microcontroller. Before buying a new mcu evaluation board, there is a smart way to study the Embedded Linux. That is studying it with the emulator called ARMUlator.

I tested on Fedora Core 6 Linux with GCC 3.4.x (how to install gcc 3.4 for FC6).

What you get

Here are some files you can use to put together uClinux running in the GDB/ARMulator.

Building the Debugger/Emulator
 tar xvf gdb-5.0.tar.bz2
 gunzip gdb-5.0-uclinux-armulator-20060104.patch.gz
        patch -p0 < gdb-5.0-uclinux-armulator-20060104.patch
 cd gdb-5.0
        export CC=gcc34
 ./configure --target=arm-elf
 make install

Running the precompiled binaries

The ARMulator expects the romfs to be in a file called "boot.rom". You must use the matching kernel/romfs combo's.
 gunzip romfs.2.4.x
 gunzip linux.2.4.x
 ln -s romfs.2.4.x boot.rom
 arm-elf-gdb linux-2.4.x
 gdb> target sim
 gdb> load
 gdb> run