Академический Документы
Профессиональный Документы
Культура Документы
Bi Quc Bo
Assembly Programming
AREA subrout, CODE, READONLY
; Name this block of code
ENTRY
; Mark first instruction to execute
start
MOV r0, #10
; Set up parameters
MOV r1, #3
BL doadd
; Call subroutine
stop
MOV r0, #0x18 ; angel_SWIreason_ReportException
LDR r1, =0x20026
; ADP_Stopped_ApplicationExit
SVC
#0x123456
; ARM semihosting (formerly SWI)
doadd ADD r0, r0, r1
; Subroutine code
BX lr
; Return from subroutine
END
; Mark end of file
BI QUC BO
1
Define constant
NVIC_IRQ_SETEN0
EQU 0xE000E100
NVIC_IRQ0_ENABLE
EQU 0x1
LDR
R0,=NVIC_IRQ_SETEN0
MOV
R1,#NVIC_IRQ0_ENABLE
STR
R1, [R0]
MY_NUMBER
DCD 0x12345678
HELLO_TXT
DCB Hello\n,0
BI QUC BO
2
Addressing mode
MOV
MOV
LDR
LDR
LDR
R0,#1234
R0,R1
R0,[R1]
R0,[R1,#4]
R0,[R1,R2]
BI QUC BO
3
The condition
instruction contain a
condition field which determines
whether the CPU will execute
them
ADD
ADDEQ
R0, R1,R2
R0,R1,R2
;R0 =R1+R2
;R0 = R1+R2 if zero flag is set
BI QUC BO
4
BI QUC BO
5
BI QUC BO
6
Arithmetic operations
Comparisons (no results - just set condition codes)
Logical operations
Data movement between registers
Arithmetic
Operations are:
ADD
ADC
SUB
SBC
RSB
RSC
MUL
UDIV
SDIV
operand1 + operand2
operand1 + operand2 + carry
operand1 - operand2
operand1 - operand2 + carry -1
operand2 - operand1
operand2 - operand1 + carry 1
operand1 * operand2
operand1 / operand2 (unsigned)
operand1 / operand2 (signed)
Syntax:
<Operation>{<cond>}{S} Rd, Rn, Operand2
Examples:
ADD
SUB.N
SUBS.W
r0, r1
r3, #1
r3, r3, #1
BI QUC BO
7
Comparisons
Syntax:
Examples:
CMP r0, r1
TSTEQ r2, #5
BI QUC BO
8
Logical Operations
Operations are:
AND operand1 AND operand2
EOR operand1 EOR operand2
ORR operand1 OR operand2
BIC operand1 AND NOT operand2 [ie bit clear]
Syntax:
<Operation>{<cond>}{S} Rd, Rn,operand2
Examples:
AND r0, r1, r2
BICEQ r2, r3, #7
EORS r1,r3,r0
Data Movement
Operations are:
Examples:
MOV r0, r1
MOVS r2, #10
MVNEQ r1,#0
BI QUC BO
9
Ex:
LDR R0,=0x42
BI QUC BO
10
BI QUC BO
11
Pre-index Addressing
Post-index addressing
BI QUC BO
12
Pre-index addressing
LDR
LDR
LDR
R0,[R1,#4]!
R0,[R1,R2]
R0,[R1,R2,LSL # 2]!
R0 [R1+4]
R1 = R1 + 4
BI QUC BO
13
Post-index addressing
LDR
LDR
LDR
R0, [R1], #4
R0,[R1],R2
R0,[R1],R2,LSL # 2
R0 [R1]
R1 = R1 + 4
Branch instruction
BI QUC BO
14
BI QUC BO
15
<operands>
SUBLT.W R2,R1
LSRLT.W R2,#1
SUBGE.W R1,R2
LSRGE.W R1,#1
;
;
;
;
;
;
;
;
;
;
BI QUC BO
16
Special register
BI QUC BO
17
r0, APSR
r0, IPSR
r0, EPSR
APSR, r0
r0, PSR
PSR, r0
r0, CONTROL
CONTROL, r0
r0, BASEPRI
r0, PRIMASK
r0, FAULTMASK
BASEPRI, r0
PRIMASK, r0
FAULTMASK, r0
BI QUC BO
18