8051 Assembly

 Assembly Language

  • 1- Elements of Assembly Language

Introduction

It was time that hardware-oriented to the core made compromise if they wanted to stay “in the game”. Namely, unlike other circuits which only need to be connected to other components and powered in order to be of any use, microcontrollers require to be programmed as well. Fortunately, they still didn't progress so far in their evolution, so that all microcontroller families “understand” only one language - machine language. That's a good thing. The bad one is that, even primitive, this language of zeros and ones can only be understood by microcontrollers and some of the experts working on its development. In order to bridge this gap between machine and humans, the first high-level programming language called Assembly language was created.

The main problem of remembering codes recognized as instructions by electronics was solved therefore, but another one, equally complicated to both us and “them”(microcontrollers) arose. This problem was also easily solved by means of the program for a PC called assembler and a simple device called programmer.

This program enables the PC to receive commands in the form of abbreviations and convert them unerringly into so called “executable file”. The moment of compiling a program into machine language is crucial as this file, called HEX file, represents a series of binary numbers understandable to microcontrollers only. The program written in assembly language cannot be executed practically unless this file is loaded into the microcontroller memory. This is the moment when the last link in the chain - the programmer - appears on the scene. It is a small device connected to a PC via some of the ports and has a socket for placing chip in.

1. Elements of Assembly Language

Assembly language is basically like any other language, which means that it has its words, rules and syntax. The basic elements of assembly language are:

  • Labels;
  • Orders;
  • Directives; and
  • Comments.

Syntax of Assembly language

When writing a program in assembly language it is necessary to observe specific rules in order to enable the process of compiling into executable “HEX-code” to run without errors. These compulsory rules are called syntax and there are only several of them:

  • Every program line may consist of a maximum of 255 characters;
  • Every program line to be compiled, must start with a symbol, label, mnemonics or directive;
  • Text following the mark “;” in a program line represents a comment ignored (not compiled) by the assembler; and
  • All the elements of one program line (labels, instructions etc.) must be separated by at least one space character. For the sake of better clearness, a push button TAB on a keyboard is commonly used instead of it, so that it is easy to delimit columns with labels, directives etc. in a program.

Numbers

If octal number system, otherwise considered as obsolite, is disregarded, assembly laguage allows numbers to be used in one out of three number systems:
Decimal Numbers

If not stated otherwise, the assembly language considers all the numbers as decimal. All ten digits are used (0,1,2,3,4,5,6,7,8,9). Since at most 2 bytes are used for saving them in the microcontroller, the largest decimal number that can be written in assembly language is 65535. If it is necessary to specify that some of the numbers is in decimal format, then it has to be followed by the letter “D”. For example 1234D.
Hexadecimal Numbers

Hexadecimal numbers are commonly used in programming. There are 16 digits in hexadecimal number system (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F). The largest hexadecimal number that can be written in assembly language is FFFF. It corresponds to decimal number 65535. In order to distinguish hexadecimal numbers from decimal, they are followed by the letter “h”(either in upper- or lowercase). For example 54h.

Binary Numbers

Binary numbers are often used when the value of each individual bit of some of the registers is important, since each binary digit represents one bit. There are only two digits in use (0 and 1). The largest binary number written in assembly language is 1111111111111111. In order to distinguish binary numbers from other numbers, they are followed by the letter “b” (either in upper- or lowercase). For example 01100101B.
Operators

Some of the assembly-used commands use logical and mathematical expessions instead of symbols 


 

Post a Comment

أحدث أقدم