Friday, December 31, 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

result++;

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:

Assembly


Operation


Machine language (in hex)


nop

No operation90

inc result

IncrementFF060A00

mov class_size, 45

CopyC7060C002D00

and mask, 128

Logical and80260E0080

add marks, 10

Integer addition83060F000A


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

No comments:

Post a Comment