SlideShare a Scribd company logo
ASSEMBLY BASICS
SUBMITTED BY :
SHILPA B G
ASSEMBLY LANGUAGE : BASIC SYNTAX
 In assembler code, the following instruction formatting is
commonly used:
label
opcode operand1, operand2, ...; Comments
 The label is optional. Some of the instructions might have a label in
front of them so that the address of the instructions can be
determined using the label.
 Then, we will find the opcode (the instruction) followed by a
number of operands. Normally, the first operand is the destination
of the operation.
 The number of operands in an instruction depends on the type
of instruction.
 The syntax format of the operand can also be different. For
example, immediate data are usually in the form #number, as
shown here:
MOV R0, #0x12 ; Set R0 = 0x12 (hexadecimal)
MOV R1, #'A' ; Set R1 = ASCII character A
 The text after each semicolon (;) is a comment. These
comments do not affect the program operation, but they can
make programs easier for humans to understand.
 We can define constants using EQU, and then use them inside your
program code. For example,
NVIC_IRQ_SETEN0 EQU 0xE000E100
NVIC_IRQ0_ENABLE EQU 0x1
...
LDR R0,=NVIC_IRQ_SETEN0; ; LDR here is a pseudo-instruction that
; convert to a PC relative load by
; assembler.
MOV R1,#NVIC_IRQ0_ENABLE ; Move immediate data to register
STR R1,[R0] ; Enable IRQ 0 by writing R1 to address
; in R0
 A number of data definition directives are available for insertion of
constants inside assembly code.
 For example, DCI (Define Constant Instruction) can be used to code
an instruction if your assembler cannot generate the exact instruction
that we want and if we know the binary code for the instruction.
DCI 0xBE00 ; Breakpoint (BKPT 0), a 16-bit instruction
 We can use DCB (Define Constant Byte) for byte size constant values,
such as characters, and Define Constant Data (DCD) for word size
constant values to define binary data in your code.
LDR R3,=MY_NUMBER ; Get the memory address value of MY_NUMBER
LDR R4,[R3] ; Get the value code 0x12345678 in R4
...
LDR R0,=HELLO_TXT ; Get the starting memory address of
; HELLO_TXT
BL PrintText ; Call a function called PrintText to
; display string
...
MY_NUMBER
DCD 0x12345678
HELLO_TXT
DCB "Hellon",0 ; null terminated string
ASSEMBLER LANGUAGE : USE OF SUFFIXES
 For the Cortex-M3, the conditional execution suffixes are usually
used for branch instructions.
 However, other instructions can also be used with the conditional
execution suffixes if they are inside an IF-THEN instruction
block.
 In this cases, the S suffix and the conditional execution
suffixes can be used at the same time.
Assembly basics
ASSEMBLER LANGUAGE : UNIFIED
ASSEMBLER LANGUAGE
 To support and get the best out of the Thumb®-2 instruction set, the
Unified Assembler Language (UAL) was developed to allow selection
of 16-bit and 32-bit instructions and to make it easier to port
applications between ARM code and Thumb code by using the same
syntax for both. (With UAL, the syntax of Thumb instructions is now
the same as for ARM instructions.)
ADD R0, R1 ; R0 = R0 + R1, using Traditional Thumb syntax
ADD R0, R0, R1 ; Equivalent instruction using UAL syntax
 The traditional Thumb syntax can still be used. The choice between
whether the instructions are interpreted as traditional Thumb code or
the new UAL syntax is normally defined by the directive in the
assembly file.
 For example, with ARM assembler tool, a program code header with
“CODE16” directive implies the code is in the traditional Thumb
syntax, and “THUMB” directive implies the code is in the new UAL
syntax.
 One thing you need to be careful with reusing traditional Thumb is
that some instructions change the flags in APSR, even if the S suffix
is not used. However, when the UAL syntax is used, whether
the instruction changes the flag depends on the S suffix. For
example,
AND R0, R1 ; Traditional Thumb syntax
AND R0, R0, R1 ; Equivalent UAL syntax (S suffix is added)
 With the new instructions in Thumb-2 technology, some of the
operations can be handled by either a Thumb instruction or a
Thumb-2 instruction.
 For example, R0 = R0 + 1 can be implemented as a 16-bit Thumb
instruction or a 32-bit Thumb-2 instruction.
 With UAL, you can specify which instruction you want by adding
suffixes:
ADDS R0, #1 ; Use 16-bit Thumb instruction by default
; for smaller size
ADDS.N R0, #1 ; Use 16-bit Thumb instruction (N=Narrow)
ADDS.W R0, #1 ; Use 32-bit Thumb-2 instruction (W=wide)
 The .W (wide) suffix specifies a 32-bit instruction. If no suffix is
given, the assembler tool can choose either instruction but usually
defaults to 16-bit Thumb code to get a smaller size.
 Depending on tool support, you may also use the .N (narrow)
suffix to specify a 16-bit Thumb instruction.
 Again, this syntax is for ARM assembler tools. Other assemblers
might have slightly different syntax.
 If no suffix is given, the assembler might choose the instruction for
you, with the minimum code size In most cases, applications will be
coded in C, and the C compilers will use 16-bit instructions if
possible due to smaller code size. However, when the immediate
data exceed a certain range or when the operation can be better
handled with a 32-bit Thumb-2 instruction, the 32-bit instruction
will be used.
 The 32-bit Thumb-2 instructions can be half word aligned. For
example, you can have a 32-bit instruction located in a half word
location.
0x1000 : LDR r0,[r1] ;a 16-bit instructions (occupy 0x10000x1001)
0x1002 : RBIT.W r0 ;a 32-bit Thumb-2 instruction (occupy
; 0x1002-0x1005)
 Most of the 16-bit instructions can only access registers R0–R7;
32-bit Thumb-2 instructions do not have this limitation.
 However, use of PC (R15) might not be allowed in some of the
instructions. Refer to the ARM v7-M Architecture Application
Level Reference Manual [Ref. 2] (section A4.6) if you need to
find out more detail in this area.
Assembly basics

More Related Content

PPTX
Chapter 2 programming concepts - I
PPTX
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
PDF
N_Asm Assembly arithmetic instructions (sol)
PPTX
8086 Microprocessor
PPTX
Chapter 4 programming concepts III
PPT
Compreport
PDF
Lecture5(1)
PPSX
Assembly language programming
Chapter 2 programming concepts - I
assembly language programming organization of IBM PC chapter 9 part-1(MULTIPL...
N_Asm Assembly arithmetic instructions (sol)
8086 Microprocessor
Chapter 4 programming concepts III
Compreport
Lecture5(1)
Assembly language programming

What's hot (20)

PPTX
Multiplication & division instructions microprocessor 8086
PDF
PPS
Computer instructions
PPTX
Chapter 5 programming concepts iv
PPTX
Chapter 3 programming concepts-ii
PPTX
Computer design
PDF
Assembly language part I
PDF
Assembly language 8086
PPTX
Advanced procedures in assembly language Full chapter ppt
PDF
Msp430 assembly language instructions &addressing modes
PPTX
[ASM]Lab4
PPTX
Assembly language programming intro
PDF
Assembly language 8086 intermediate
PPT
Wk1to4
PPTX
Chapter 1 archietecture of 8086
PDF
Assembler directives and basic steps ALP of 8086
PDF
Unit 3 – assembly language programming
PPSX
Orca share media1492336349924
PPTX
ARM Architecture Subroutine and Flags
Multiplication & division instructions microprocessor 8086
Computer instructions
Chapter 5 programming concepts iv
Chapter 3 programming concepts-ii
Computer design
Assembly language part I
Assembly language 8086
Advanced procedures in assembly language Full chapter ppt
Msp430 assembly language instructions &addressing modes
[ASM]Lab4
Assembly language programming intro
Assembly language 8086 intermediate
Wk1to4
Chapter 1 archietecture of 8086
Assembler directives and basic steps ALP of 8086
Unit 3 – assembly language programming
Orca share media1492336349924
ARM Architecture Subroutine and Flags
Ad

Similar to Assembly basics (20)

PPTX
armcortexinsructionsetupdated (2).pptx
PPT
Arm Cortex material Arm Cortex material3222886.ppt
PPTX
Module 2 PPT of ES.pptx
PPTX
Cortex_M3 Instruction SetCortex_M3 Instruction SetCortex_M3 Instruction Set.pptx
PPTX
Microcontroller directives
PPTX
ARM-7 ADDRESSING MODES INSTRUCTION SET
PDF
PDF
Unit II arm 7 Instruction Set
PPTX
PPT
Embedded Systems ARM Computer Architecture
PDF
Alp 05
PDF
Embedded Systems (18EC62) - ARM Cortex-M3 Instruction Set and Programming (Mo...
PPT
Intel µp instruction encoding and decoding
PDF
L10 assembly-language-programming-of-atmega328 p
DOCX
MES LAB MANUAL for engineering students.
PPT
Assembly Language Basics
PPTX
Microprocessor instructions
DOCX
Computer architecture is made up of two main components the Instruct.docx
PDF
8051 instruction set
PDF
Unit II Arm7 Thumb Instruction
armcortexinsructionsetupdated (2).pptx
Arm Cortex material Arm Cortex material3222886.ppt
Module 2 PPT of ES.pptx
Cortex_M3 Instruction SetCortex_M3 Instruction SetCortex_M3 Instruction Set.pptx
Microcontroller directives
ARM-7 ADDRESSING MODES INSTRUCTION SET
Unit II arm 7 Instruction Set
Embedded Systems ARM Computer Architecture
Alp 05
Embedded Systems (18EC62) - ARM Cortex-M3 Instruction Set and Programming (Mo...
Intel µp instruction encoding and decoding
L10 assembly-language-programming-of-atmega328 p
MES LAB MANUAL for engineering students.
Assembly Language Basics
Microprocessor instructions
Computer architecture is made up of two main components the Instruct.docx
8051 instruction set
Unit II Arm7 Thumb Instruction
Ad

Recently uploaded (20)

PDF
Model Code of Practice - Construction Work - 21102022 .pdf
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
Safety Seminar civil to be ensured for safe working.
PPTX
Current and future trends in Computer Vision.pptx
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPT
Project quality management in manufacturing
PDF
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
PPTX
OOP with Java - Java Introduction (Basics)
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PDF
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
PPTX
additive manufacturing of ss316l using mig welding
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
DOCX
573137875-Attendance-Management-System-original
PPT
Mechanical Engineering MATERIALS Selection
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PDF
composite construction of structures.pdf
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PPTX
Lecture Notes Electrical Wiring System Components
Model Code of Practice - Construction Work - 21102022 .pdf
Internet of Things (IOT) - A guide to understanding
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Safety Seminar civil to be ensured for safe working.
Current and future trends in Computer Vision.pptx
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
Project quality management in manufacturing
Evaluating the Democratization of the Turkish Armed Forces from a Normative P...
OOP with Java - Java Introduction (Basics)
CYBER-CRIMES AND SECURITY A guide to understanding
Unit I ESSENTIAL OF DIGITAL MARKETING.pdf
additive manufacturing of ss316l using mig welding
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
573137875-Attendance-Management-System-original
Mechanical Engineering MATERIALS Selection
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
composite construction of structures.pdf
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Lecture Notes Electrical Wiring System Components

Assembly basics

  • 2. ASSEMBLY LANGUAGE : BASIC SYNTAX  In assembler code, the following instruction formatting is commonly used: label opcode operand1, operand2, ...; Comments  The label is optional. Some of the instructions might have a label in front of them so that the address of the instructions can be determined using the label.  Then, we will find the opcode (the instruction) followed by a number of operands. Normally, the first operand is the destination of the operation.
  • 3.  The number of operands in an instruction depends on the type of instruction.  The syntax format of the operand can also be different. For example, immediate data are usually in the form #number, as shown here: MOV R0, #0x12 ; Set R0 = 0x12 (hexadecimal) MOV R1, #'A' ; Set R1 = ASCII character A  The text after each semicolon (;) is a comment. These comments do not affect the program operation, but they can make programs easier for humans to understand.
  • 4.  We can define constants using EQU, and then use them inside your program code. For example, NVIC_IRQ_SETEN0 EQU 0xE000E100 NVIC_IRQ0_ENABLE EQU 0x1 ... LDR R0,=NVIC_IRQ_SETEN0; ; LDR here is a pseudo-instruction that ; convert to a PC relative load by ; assembler. MOV R1,#NVIC_IRQ0_ENABLE ; Move immediate data to register STR R1,[R0] ; Enable IRQ 0 by writing R1 to address ; in R0  A number of data definition directives are available for insertion of constants inside assembly code.  For example, DCI (Define Constant Instruction) can be used to code an instruction if your assembler cannot generate the exact instruction that we want and if we know the binary code for the instruction. DCI 0xBE00 ; Breakpoint (BKPT 0), a 16-bit instruction
  • 5.  We can use DCB (Define Constant Byte) for byte size constant values, such as characters, and Define Constant Data (DCD) for word size constant values to define binary data in your code. LDR R3,=MY_NUMBER ; Get the memory address value of MY_NUMBER LDR R4,[R3] ; Get the value code 0x12345678 in R4 ... LDR R0,=HELLO_TXT ; Get the starting memory address of ; HELLO_TXT BL PrintText ; Call a function called PrintText to ; display string ... MY_NUMBER DCD 0x12345678 HELLO_TXT DCB "Hellon",0 ; null terminated string
  • 6. ASSEMBLER LANGUAGE : USE OF SUFFIXES  For the Cortex-M3, the conditional execution suffixes are usually used for branch instructions.  However, other instructions can also be used with the conditional execution suffixes if they are inside an IF-THEN instruction block.  In this cases, the S suffix and the conditional execution suffixes can be used at the same time.
  • 8. ASSEMBLER LANGUAGE : UNIFIED ASSEMBLER LANGUAGE  To support and get the best out of the Thumb®-2 instruction set, the Unified Assembler Language (UAL) was developed to allow selection of 16-bit and 32-bit instructions and to make it easier to port applications between ARM code and Thumb code by using the same syntax for both. (With UAL, the syntax of Thumb instructions is now the same as for ARM instructions.) ADD R0, R1 ; R0 = R0 + R1, using Traditional Thumb syntax ADD R0, R0, R1 ; Equivalent instruction using UAL syntax
  • 9.  The traditional Thumb syntax can still be used. The choice between whether the instructions are interpreted as traditional Thumb code or the new UAL syntax is normally defined by the directive in the assembly file.  For example, with ARM assembler tool, a program code header with “CODE16” directive implies the code is in the traditional Thumb syntax, and “THUMB” directive implies the code is in the new UAL syntax.  One thing you need to be careful with reusing traditional Thumb is that some instructions change the flags in APSR, even if the S suffix is not used. However, when the UAL syntax is used, whether the instruction changes the flag depends on the S suffix. For example, AND R0, R1 ; Traditional Thumb syntax AND R0, R0, R1 ; Equivalent UAL syntax (S suffix is added)
  • 10.  With the new instructions in Thumb-2 technology, some of the operations can be handled by either a Thumb instruction or a Thumb-2 instruction.  For example, R0 = R0 + 1 can be implemented as a 16-bit Thumb instruction or a 32-bit Thumb-2 instruction.  With UAL, you can specify which instruction you want by adding suffixes: ADDS R0, #1 ; Use 16-bit Thumb instruction by default ; for smaller size ADDS.N R0, #1 ; Use 16-bit Thumb instruction (N=Narrow) ADDS.W R0, #1 ; Use 32-bit Thumb-2 instruction (W=wide)
  • 11.  The .W (wide) suffix specifies a 32-bit instruction. If no suffix is given, the assembler tool can choose either instruction but usually defaults to 16-bit Thumb code to get a smaller size.  Depending on tool support, you may also use the .N (narrow) suffix to specify a 16-bit Thumb instruction.  Again, this syntax is for ARM assembler tools. Other assemblers might have slightly different syntax.  If no suffix is given, the assembler might choose the instruction for you, with the minimum code size In most cases, applications will be coded in C, and the C compilers will use 16-bit instructions if possible due to smaller code size. However, when the immediate data exceed a certain range or when the operation can be better handled with a 32-bit Thumb-2 instruction, the 32-bit instruction will be used.
  • 12.  The 32-bit Thumb-2 instructions can be half word aligned. For example, you can have a 32-bit instruction located in a half word location. 0x1000 : LDR r0,[r1] ;a 16-bit instructions (occupy 0x10000x1001) 0x1002 : RBIT.W r0 ;a 32-bit Thumb-2 instruction (occupy ; 0x1002-0x1005)  Most of the 16-bit instructions can only access registers R0–R7; 32-bit Thumb-2 instructions do not have this limitation.  However, use of PC (R15) might not be allowed in some of the instructions. Refer to the ARM v7-M Architecture Application Level Reference Manual [Ref. 2] (section A4.6) if you need to find out more detail in this area.