The Internet belongs to everyone. Let’s keep it that way.

Protect Net Neutrality
Loading presentation...

Present Remotely

Send the link below via email or IM

Copy

Present to your audience

Start remote presentation

  • Invited audience members will follow you as you navigate and present
  • People invited to a presentation do not need a Prezi account
  • This link expires 10 minutes after you close the presentation
  • A maximum of 30 users can follow your presentation
  • Learn more about this feature in our knowledge base article

Do you really want to delete this prezi?

Neither you, nor the coeditors you shared it with will be able to recover it again.

DeleteCancel

Assembler Rules And Directives

No description
by

Sami Khan

on 12 May 2015

Comments (0)

Please log in to add your comment.

Report abuse

Transcript of Assembler Rules And Directives

Assembler Rules And Directives
Group Members
Introduction
Assembler rules and directives are instructions to the assembler for creating:
Structure of Assembly Language Module

AREA ARMex, CODE, READONLY
; Name this block of code ARMex
ENTRY ; Mark first instruction to execute
start
MOV r0, #10 ; Set up parameters
MOV r1, #3
ADD r0, r0, r1 ; r0 = r0 + r1
stop
MOV r0, #0x18 ; angel_SWIreason_ReportException
LDR r1, =0x20026 ; ADP_Stopped_ApplicationExit
SVC #0x123456 ; ARM semihosting (formerly SWI)
END ; Mark end of file.

Semi Hosting
Semi hosting is a mechanism that enables:
Frequently used directives
The directives which are commonly used in ARM assembler directives are as follows:
DCB, DCW, and DCD Directives:
The DCB directive allocates one or more bytes of memory and defines the initial runtime content of the memory.
Assembly Control Directives
This section describes the following directives to control conditional assembly, looping, inclusions and macros:
Shaheer Usman
Kameran Akhtar
Javed Asghar
Sami ur Rehman Khan
• Areas of code.
• Aligning data.
• Marking the end of code and so forth…
Note:
They are not like processor instructions which tell the processor to:
• Add two numbers.
• Jump somewhere in code.
Since they never turn into machine instructions.
Importance:
• We can’t learn Assembly without knowing how to use Directives.
• In contrast, we can’t even learn Directives without knowing Assembly.
To start with the basic example:
code running on an ARM target to communicate and
use the Input,Output facilities on a host computer that is running a debugger.
Machanism used to enable functions in C Library [eg: printf(), scanf()]
Semi Hosting Implementation:
Semi hosting is implemented by set of defined software instructions.
SWI (Software Interrupt).
SVC (Supervisor Call).
Overview:
• AREA directive.
• RN directive.
• EQU directive.
• ENTRY directive.
• DCB directive.
• DCW directive.
• DCB directive.
• ALIGN directive.
• SPACE directive.
• LTROG directive.
• END directive.
AREA Directive:
The AREA directive instructs the assembler to assemble a new code or data area.
Syntax:
AREA name{,attr}{,attr}...

The following example defines a read-only code area named
Example:
AREA Example , CODE , READONLY

The RN directive defines a register name for a specified register.
RN directive:
Coeff1 RN 8
Coeff2 RN 9
dest RN 0
Syntax:
name RN numeric-expression
Example:
EQU or * directives:
The EQU directive gives a symbolic name to a numeric constant. * is a synonym for EQU.
Example:
Syntax:
name EQU expression
ABC EQU 2
LDR r1, ABC
ENTRY directive:
The ENTRY directive declares its offset in its containing AOF area to be the unique entry point to any program containing the area.
Syntax:
Example:
ENTRY
AREA EXAMPLE , CODE , READONLY
ENTRY

DCB:
Syntax:
DCB expression{ ,expression}
Example:
DCB "C_string",0
The DCW directive allocates one or more halfwords of memory, aligned on 2-byte boundaries, and defines the initial runtime contents of the memory.
DCW:
Syntax:
DCW expression{ ,expression}
DCB:
Syntax:
The DCD directive allocates one or more words of memory, aligned on 4-byte boundaries, and defines the initial runtime contents of the memory. & is a synonym for DCD.
DCD expression{ ,expression}
ALIGN directives:
By default, the ‘ALIGN’ directive aligns the current location within the code to a word of 4-byte boundary.
Syntax:
ALIGN {expression{, offset-expression}}
Space directives:
This directive reserves a zeroed block of memory.
Syntax:
SPACE expression
LTROG directives:
It assigns the Literal Pool Origins. In other words ‘LTROG’ directive instructs the assembler to assemble the current literal pool immediately.
Syntax:
LTROG
END directives:
The ‘END’ directive informs the assembler that it has reached at the end of a source file.
Syntax:
END
• MACRO and MEND.
• MEXIT.
• IF, ELSE, ENDIF and ELIF.
• WHILE and WEND.
MACRO:
You can also define a new operation in your code by writing it as a MACRO and then calling it whenever it is needed.
Syntax:
Two directives are used to define a macro:
MACRO and MEND.
Example:
MEXIT:
Suppose you have a sequence of instructions that appears multiple times in your code – in this case, two add instructions followed by multiplication. You could define a small macro as follows:
MACRO
; macro definition:
;
; vara = 8 * (varb + varc + 6)
$Label_1 AddMul $vara, $varb, $varc
$Label_1
ADD $vara, $varb, $varc ; add two terms
ADD $vara, $vara, #6 ; add 6 to the sum
MOV $vara, $vara, LSL #3 ; multiply by 8
MEND
In your source code file, you can then instantiate the macro as many times as you like. You might call the sequence as
; nvoke the macro
CSet1 AddMul r0, r1, r2
; the rest of your code
And the assembler makes the necessary subsitutions, so that the assembly listing actually reads as
; invoke the macro
CSet1
ADD r0, r1, r2
ADD r0, r0, #6
MOV r0, r0, LSL #3

; the rest of your code

The MEXIT directive is used to exit a macro definition before the end.

Syntax:
MEXIT
IF logical-expression

…;code
{ELSE

…;code}
ENDIF

(where logical – expression is an expression that evaluates to either {
TRUE
} or {
False
})
IF, ELSE, ENDIF and ELIF:
The
IF
directive introduces a condition that is used to decide whether to assemble a sequence of instructions and directives.
The
ELSE
directive marks the beginning of a sequence of instructions or directives that you want to be assembled if the preceding condition fails.
The
ENDIF
directive marks the end of a sequence of instructions or directives that you want to be conditionally assembled.
The
ELIF
directive creates a structure equivalent to
ELSE IF
, without the requirement for nesting or repeating the condition.
Syntax:
WHILE - WEND directives:
The WHILE directive starts a sequence of instructions or directives that are to be assembled repeatedly. The sequence is terminated with a WEND directive.
Syntax:
WHILE logical-expression

;code
WEND
Literals:
Literals are considered to be fixed values, and there are two important types: string literals and numeric literals
Syntax:
{Label} {Instructions | directive | Pseudo - instructons} {;Comments}
Format:
A string literal is a series of characters between double quote characters.
abc sets “this is a string”
A numeric literal consists of a digit normally but if you use a character then value of numeric literal is the ascii code value of character.
Mov r9 #0xCF
Mov r3 #’Q’
Full transcript