Total members 11344 |It is currently Tue Jul 29, 2014 3:46 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

All times are UTC [ DST ]



  assembler directives types
Mon Apr 01, 2013 10:53 pm 

Assembler directives types:
Directives are used to force the assembler to perform certain operations. In this article we divide directives into five types:

1.Control Directives:

- INCLUDE Include an additional file in a program
An application of this directive has the effect as though the entire file was copied to a place where the "include" directive was found.
Code:
#include <file_name>         ; System file
#include “file_name”         ; User file

- CONSTANT Gives a constant numeric value to the textual designation
Each time that <name> appears in program, it will be replaced with <value>
Constant <name>=<value>
Code:
Constant MAXIMUM=200
Constant Length=40

- VARIABLE Gives a variable numeric value to textual designation
It differs from CONSTANT directive in that after applying the directive, the value of textual designation can be changed.
Variable<name>=<value>
Code:
variable level=30
variable time=23


- EQU Defining assembler constant
To the name of a constant <name_constant> is added value <value>
Code:
<name_constant> equ <value>   

Example:
Code:
five equ 5



- END End of program
Syntax:
Code:
end

At the end of each program it is necessary to place 'end' directive so that assembly translator would know that there are no more instructions in the program.
Example:
Code:
movlw 0xFF
movwf PORTB
end


- IF Conditional program branching
Syntax:
Code:
if<conditional_term>


If condition in <conditional_term> was met, part of the program which follows IF directive would be executed. And if it wasn't, then the part following ELSE or ENDIF directive would be executed.
Example:
Code:
if level=100
goto FILL
else
goto DISCHARGE
endif


- ELSE The alternative to 'IF' program block with conditional terms
Syntax:
Code:
Else


Used with IF directive as an alternative if conditional term is incorrect.
Example:
Code:
If time< 50
goto SPEED UP
else
goto SLOW DOWN
endif


- ENDIF End of conditional program section
Syntax:
Code:
endif


Directive is written at the end of a conditional block to inform the assembly translator that it is the end of the conditional block
Example:
Code:
If level=200
goto LOADS
else
goto UNLOADS
endif


- WHILE Execution of program section as long as condition is met
Syntax:
Code:
while<condition>
.
endw

Program lines between WHILE and ENDW would be executed as long as condition was met. If a condition stopped being valid, program would continue executing instructions following ENDW line. Number of instructions between WHILE and ENDW can be 100 at the most, and number of executions 256.
Example:
Code:
While i<10
i=i+1
endw


- ENDW End of conditional part of the program
Syntax:
Code:
endw


Instruction is written at the end of the conditional WHILE block, so that assembly translator would know that it is the end of the conditional block
Example:
Code:
while i<10
i=i+1
endw


2. Data Directives:

- DB Defining one byte data
Syntax:
Code:
[<label>]db <term> [, <term>,.....,<term>]


Directive reserves a byte in program memory. When there are more terms which need to be assigned a byte each, they will be assigned one after another.
Code:
Example:
db 't', 0x0f, 'e', 's', 0x12


- DE Defining the EEPROM memory byte
Syntax:
Code:
[<term>] de <term> [, <term>,....., <term>]

Directive is used for defining EEPROM memory byte. Even though it was first intended only for EEPROM memory, it could be used for any other location in any memory.
Example:
Code:
org H'2100'
de "Version 1.0" , 0



- DT Defining the data table
Syntax:
Code:
[<label>] dt <term> [, <term>,........., <term>]

Directive generates RETLW series of instructions, one instruction per each term.
Example:
Code:
dt "Message", 0
dt first, second, third


- Dw
Define 1 or multiple word constants
Syntax:
Code:
dw <expr>,…,<expr>

Example:
Code:
array dw 0x1234,0x2300,0x40,0x33



3. Object File Directives:

- PROCESSOR
Defining microcontroller model
Syntax:
Code:
Processor <microcontroller_type>

Instruction sets the type of microcontroller where programming is done.
Example:
Code:
processor 16F84



- ORG
Defines an address from which the program is stored in microcontroller memory
Syntax:
Code:
<label>org<value>

This is the most frequently used directive. With the help of this directive we define where some part of a program will be start in the program memory.
Example:
Code:
Start org
        movlw 0xFF
        movwf PORTB


The first two instructions following the first 'org' directive are stored from address 00, and the other two from address 10.


- BANKSEL
Select access bank
Syntax:
Code:
banksel <label>

Generate the instruction sequence to set active data bank to the one where<label> is located
Examples:
Code:
bigq set 0x300
……
banksel bigq

this directive will cause the assembler to
; insert the instruction movlb 0x03

4. macro directives:

  • macro
  • endm
  • exitm

Sum_of_3 macro arg1, arg2, arg3 ; WREG <- [arg1]+[arg2]+[arg3]
Code:
movf arg1,W,A
addwf arg2,W,A
addwf arg3,W,A
endm


_________________
Please recommend / share my post if you found it helpful.


Author:
Mastermind
User avatar Posts: 2694
Have thanks: 73 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : assembler directives types
 Control Directives usage PIC assembly     -  
 Object File Directives Usage PIC Assembly     -  
 Types of Pointers in C++     -  
 Types of Registers     -  
 What are the types of jdbc drivers.?     -  
 pointers to derived types     -  
 temperature transformer between different types     -  
 java data types     -  
 lesson9: XSD Complex Types Indicators     -  
 Get Registered File Types and Their Associated Icons in C#     -  

All times are UTC [ DST ]









Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team