Lecture 9

Assembly Language

Machine code is very hard to follow because it uses binary code to represent the instructions. To provide a more human friendly version of machine code, assembly language is used.

An assembly language statement is a line of text that translates into a single machine instruction.

Assembly Language is expressed in a more human readable form than the binary instructions and names are allowed for memory locations, registers, operations etc.

For example:

ADD [result],[coursework],[exam]

Example: translate the following C statement to assembly language and machine code.

x=y*(y+z);

Assume x,y and z are stored in memory locations 0,1 and 2 and there are general purpose registers called A,B,C...etc

The 3e,3f,8c,9f and 4e are binary codes that contain the operation and registers for the instruction. Note that I have just made these up and they have no real meaning. (See chapter 2 and appendix C of Brookshear for an example of a simple instruction set)

Example:

if (x==3) x++;
y++;

Example:

while (x--<4) {
  y+=x;
}

What about arrays and pointers?

A pointer is an address that can be stored in a register - it may point to the start of an array.

Example:

for(i=0;i!=100;i++) {
  score[i]=0;
}

Here is a small program that recompiles itself and generates an Assembly Language listing.

The first column is a line number, next is a byte offset, next is the machine code, then labels and assembler directives and finally the assembly language itself. Try changing the program to see what code it produces.

Click here to see the program that is run by the cpu in the last lecture.

Where is Assembly Language compared with other programming languages.

________________________
Specification Languages
   Z, VDM
________________________
Declarative Languages
  Prolog
________________________
Functional Languages
  Lisp, ML
_______________________
High Level Imperative Languages
  Pascal, Ada, C++
_______________________
Low Level Imperative Languages
  C
_______________________
Assembly Language
_______________________
Machine Code
_______________________
Hardware