5.2. Structure of a program in assembler
The following program shows the basic structure of a program in assembler.
;************************************************* *********
; Example structure of a program in assembler
, The microcontroller 8051.
;
; Program to blink all the bits of Port 0
, With a certain time.
;
; Author: Rafael Aranda
; Date: 20-10-2009
: Version: 1.0
;************************************************* *********
$ NOMOD51
$ INCLUDE (REG51.INC)
STRUCTURE NAME
STACK EQU 030H; address stack pointer
;*************************************
; Start interrupt vectors
;*************************************
USING 0
ORG 0H; Source Code (Location of the ROM)
VECTOR: JMP START; Reset
VECTOR ORG +3 H; INT0
VECTOR ORG +0 BH; Timer 0
VECTOR ORG +13 H; INT1
VECTOR ORG +1 BH; Timer 1
VECTOR ORG +23 H; Puerto series RI + TI
VECTOR ORG +2 BH, Timer 2
;********************************
; Tasks initial preparation
;********************************
ORG VECTOR H +30
START: MOV SP, # STACK-1; Set stack pointer
MOV PSW, # 00000000B; Selects register bank 0
MOV P1, # 0H; Prepare port
;*******************
Major Programme
;*******************
PROGRAM: MOV P1, # 0H; Put the bits of Port 0 to 0
CALL DELAY; Perform a delay
MOV P1, # 0FFH; Put the bits of Port 0 to 1
CALL DELAY; Perform a delay
JMP PROGRAM; Restating infinitely
;***************************
; Subroutine timing
;***************************
DELAY: MOV R2, # 7FH
RET_3: MOV R1, # 0FFH
RET_2: MOV R0, # 0FFH
RET_1: DJNZ R0, RET_1
DJNZ R1, RET_2
DJNZ R2, RET_3
RET
END