SECTION II - 8051 ASSEMBLY PROGRAMMING INTRODUCTION

SECTION II - 8051 ASSEMBLY PROGRAMMING INTRODUCTION

The Central Processing Unit [CPU] work only in binary at a very high speed. For hunams it is quite very slow to deal with 0's and 1's in order to program the microcontrollers. The Machine language consists of 0's and 1's and it is know as Program. In the past, the programmers coded programs in machine language. The more efficient way to represent binay numbers is the hexadecimal system. Finally, the machine language were developed which provided mnemonics for the machine code instructions, plus other features which made programming faster and less prone to error. The term mnemonic is frequently used in computer science and engineering literature to refer to codes and abbreviations that are relatively easy to remember. Assembler is used to translate the assembly language program into machine code. Assembly language is a low-level language as it directly deals with the internal structure of the CPU.The programmer must know all the registers of the CPU and the internal structure of the microcontrollers, and the size of each register and other details, in order to program in assembly language.

BASIC, Pascal, C, C++, Java etc, Programmers can use many other languages. These are high-level languages, in these languages the programmer does not have to be concerned with the internal details of the central processing unit [CPU]. Assember which is used to translate an assembly language program into machine code, also called object code or opcode for operation code.Compiler is used to translate the hight-level languages into machine code. To write a program in C, one must use a C compiler to translate the program into machine language. To write a program in assembly language, an 8051 assembler can be used to create a ready-to-run program.

Assembly Language Structure:

Assembly language progeam consists of a series of lines of assembly language instructions. An assembly language instruction consists of mnemonic, optionally followed by one or two operands. The operands are the data items being manipulated, and the mnemonics are the commands to the CPU, telling it what to do with those items.

Sample of an Assembly Language Program:

ORG OH                  ;Start origin at location 0
MOV R4, #20H       ;Load 20H into R4    
MOV R5,#30H        ;Load 30H into R5
ADD A,R4                ;Add contents of R4 to A i.e. A = A + R4
ADD A,R5                ;Add contents of R5 to A i.e. A = A + R5
ADD A,#10H           ;Add to accumulator A value 10H
HERE:SJMP HERE   ;Stay in this loop
END                         ;End of .asm source file
 
  • Assembly language program is a series of statements, or lines, which are either Assembly language instructions such as ADD and MOV, or statements called directives. Instructions tell the CPU what to do, directives also called pseudo-instructions, give directions to the assembler. In the above program, the MOV and ADD instructions are commands to the CPU, ORG and END are directives to the assembler. ORG tells the assembler to place the opcode at memory location 0 while END indicated to the assembler the end of the source code. ORG is for the start of the program and END indicates to the end of the program.

Assembly Language Written format:

  • An assembly language instruction consists of four fields mentioned below. Brackets indicate that a field is optional and not all lines have them. Brackets should not be typed in. 
    [ label: ] mnemonic [ operands ] [;comment]
  • The label field allows the program to refer to a line of code by name. The label field cannot exceed a certain number of characters.
  • The assembly language mnemonic [instruction] and operands fields together perform the real work of the program and accomplish the tasks for which the program was written. The statements such as:

    ADD A,B

    MOV A,#55

  • ADD and MOV are the mnemonics which produce opcodes; "A,B" and "A,#55" are the operands. These two fields could contain assembler pseudo-instructions, or directives. Directives do not generate any machine code [opcode] and are used only by the assembler, as opposed to instructions that are translated into machine code [opcode] for the CPU to execute. ORG [origin] and END are examples of directives [some 8051 assemblers use .ORG and .END]
  • The comment field begins with a semicolon comment indicator " ; ". Comments may be at the end of a line or on a line by themselves. The assembler ignores comments. Although the comments are optional. It is recomended that they be used to describe the program in order to make it easier for someone else to read and understand.
  • " HERE " label in the label field. The label referring to an instruction must be followed by a colon symbol i.e. " ; ". In the above example program the line HERE: SJMP HERE [Short jump instruction], the 8051 is told to stay in this loop indefinitely. If the system has a monitor program, then we do not need this line and it should be deleted from our program.

More From Iamtechnical.com

Advertisement: