Tuesday, March 22, 2016

8051 Assembly Programming

  • CPU can work only in binary
  • It is difficult for humans to deal with 0’s and 1’s in order to program the computer
  • A program that consists of 0s and 1s is called machine language
  • Assembly languages were developed to provide mnemonics for machine code instructions.
  • Comparing to machine language, Programming in assembly language is easier, faster and less prone to error.
  • Assembly language is referred to as low-level language because it deals directly with the internal structure of the CPU and its registers.
  • Assembly language programs must be translated into machine code by a program called an assembler.
  • Assembly language is a series of lines or statements of assembly language instruction or directives (also called pseudo-instructions).
  • Instructions tell CPU what to do and directives give directions to the assembler
Structure of 8051 Program:
ORG
Label :mnemonic operands; comment
END
  • ORG – Indicates the start of the program. It tells the assembler to place the opcode at memory location 0
  • END – Indicates to the assembler the end of program or source code
  • Label – Allows the program to refer a line of code by name. Any label referring to an instruction must be followed by a colon symbol (:). It is an optional field. Each label name must be unique. Label consists of alphabets A to Z or a to z, numbers 0 – 9, special characters question mark (?), period (.), at (@), underline (_) and dollar ($). First character of label must be alphabetic. Mnemonics and reserved words must not be used as label.
  • Mnemonic is the command to CPU
  • Operand(s) is the data to command. It is an optional field. Few commands do not need data.
  • Comment – Comments may be at the end of a line or on a line by themselves. Comment must begin with semicolon (;). It is an optional field.
Sample Program:
ORG; start (origin) at location 0
START :MOV R1, #23H; load 23H into R1
MOV R2, #32H; load 32H in to R2
MOV A, #0; load 0 into A
ADD A, R1; add contents of R1 to A. A = A+R1. A = 23
ADD A, R2; add contents of R2 to A. A = A+R2. A = 55
ADD A, #10H; add constant 10 to A. A = A+10. A = 65
END; end of asm source file



Related topics:
8051 Assembling a Program   |   8051 Assembly Template   |   8051 Simulator   |   8051 Data Types and Directives   |   8051 Instruction Set Overview   |   8051 Instruction Set Summary

List of topics: 8051

No comments:

Post a Comment