ARM Architecture Learning 3

Publisher:buzzedyLatest update time:2016-04-08 Source: eefocusKeywords:ARM Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
ARM program status register:

The ARM architecture contains a Current Program Status Register (CPSR) and five Separate Program Status Registers (SPSRs). These registers are set and read using the MSR and MRS instructions.

  The Current Program Status Register (CPSR) holds information about the current processor state. The other five Separate Program Status Registers (SPSRs), one for each privileged mode, hold information about the state the processor must return to upon completion of exception handling in that mode.

  SPSR is used for exception handling, and its functions include:

  (1) Save the current operation information in the ALU.

  (2) Control the enable and disable of interrupts.

  (3) Set the processor's operating mode.

  The arrangement of each bit of the program status register is shown in the figure.

Figure 1.1 Program Status Register Format

  1. Condition Code Flags

  N, Z, C, and V are all conditional code flags. Their contents can be changed by the results of arithmetic or logical operations and can determine whether a certain instruction is executed.

  In ARM state, most instructions are executed conditionally; in Thumb state, only branch instructions are executed conditionally. The specific meanings of each bit of the condition code flag are shown in Table 1.


Table 1 Specific meaning of condition code flag bits

  2. Control bit

  The lower 8 bits of PSR (including I, F, T and M [4:0]) are called control bits. These bits can be changed when an exception occurs. If the processor runs in privileged mode, these bits can also be modified by the program.

  (1) Interrupt disable bits I and F.

  I=1, disable IRQ interrupt;

  F=1, disable FIQ interrupt.

  (2) T flag: This bit reflects the operating status of the processor.

  For T series processors of ARM architecture v5 and above, when this bit is 1, the program runs in Thumb state, otherwise it runs in ARM state.

  For non-T series processors of ARM architecture v5 and above, when this bit is 1, the next instruction is executed to cause the instruction exception defined by the bit; when this bit is 0, it indicates running in ARM state.

  (3) Operation mode bit M [4:0]: M0, M1, M2, M3, and M4 are mode bits that determine the operation mode of the processor. The specific meanings are shown in Table 2. Image loading...

Table 2 Specific meaning of operation mode bit M[4∶0]

  As can be seen from Table 2, not all combinations of operating mode bits are valid, and other combinations will cause the processor to enter an unrecoverable state.

  3. Reserved bits

  The remaining bits in the PSR are reserved bits. When changing the conditional code flags or control bits in the PSR, the reserved bits should not be changed, and the reserved bits should not be used to store data in the program. The reserved bits will be used for ARM version extensions.

 

 

Complete list of assembly instructions:
1. Data transfer instructions────────────────────────────────────────They
transfer
data between memory and registers, and between registers and input/output ports.
1. General data transfer instructions.
MOV transfers words or bytes.
MOVSX sign-extends first, then transfers.
MOVZX zero-extends first, then transfers.
PUSH pushes words into the stack.
POP pops words out of the stack.
PUSHA pushes AX, CX, DX, BX, SP, BP, SI, DI into the stack in sequence.
POPA pops DI, SI, BP, SP, BX, DX, CX, AX out of the stack in sequence.
PUSHAD pushes EAX, ECX, EDX, EBX, ESP, EBP, ESI, EDI into the stack in sequence.
POPAD pops EDI, ESI, EBP, ESP, EBX, EDX, ECX, EAX out of the stack in sequence.
BSWAP swaps the order of bytes in a 32-bit register
XCHG swaps words or bytes.( At least one operand is a register, and segment registers cannot be used as operands)
CMPXCHG compares and exchanges operands. (The second operand must be the accumulator AL/AX/EAX)
XADD exchanges first and then accumulates. (The result is in the first operand)
XLAT byte table lookup conversion.
── BX points to the starting point of a 256-byte table, AL is the index value of the table (0-255, i.e.
0-FFH); AL is returned as the table lookup result. ( [BX+AL]->AL )
2. Input and output port transfer instructions.
IN I/O port input. (Syntax: IN accumulator, {port number│DX})
OUT I/O port output. (Syntax: OUT {port number│DX}, accumulator)
When the input and output port is specified by immediate mode, its range is 0-255; when specified by register DX,
its range is 0-65535.
3. Destination address transfer instruction.
LEA Load effective address.
Example: LEA DX, string; store the offset address in DX.
LDS Transfer target pointer and load the pointer content into DS.
Example: LDS SI, string; store the segment address: offset address in DS: SI.
LES Transfer target pointer and load the pointer content into ES.
Example: LES DI, string; store the segment address: offset address in ES: DI.
LFS Transfer target pointer and load the pointer content into FS.
Example: LFS DI, string; store the segment address: offset address in FS: DI.
LGS Transfer target pointer and load the pointer content into GS.
Example: LGS DI, string; store the segment address: offset address in GS: DI.
LSS Transfer target pointer and load the pointer content into SS.
Example: LSS DI, string; store the segment address: offset address in SS: DI.
4. Flag transfer instruction.
LAHF Flag register transfer, load the flag into AH.
SAHF Flag register transfer, load the content of AH into the flag register.
PUSHF Push flag on the stack.
POPF Pop flag from the stack.
PUSHD Push 32-bit flag on the stack.
POPD Pop 32-bit flag from the stack.

II. Arithmetic operation
instructions──────────────────────────────────────────
  ADD Addition.
ADC Addition with carry.
INC Add 1.
AAA ASCII code adjustment for addition.
DAA Decimal adjustment for addition.
SUB Subtraction.
SBB Subtraction with borrow.
DEC Subtraction .
NEC Negate (subtract from 0).
CMP Compare. (Subtract two operands, only modify the flags, do not return the result).
AAS ASCII code adjustment for subtraction.
DAS Decimal adjustment for subtraction.
MUL Unsigned multiplication.
IMUL Integer multiplication.
For the above two operations, the results are returned to AH and AL (byte operation), or DX and AX (word operation),
AAM ASCII code adjustment for multiplication.
DIV Unsigned division.
IDIV Integer division.
For the above two operations, the results are returned:
the quotient is returned to AL, the remainder is returned to AH, (byte operation);
or the quotient is returned to AX, the remainder is returned to DX, (word operation).
AAD ASCII code adjustment for division
. CBW byte to word conversion. (Extend the sign of the byte in AL to AH)
CWD word to double word conversion. (Extend the sign of the word in AX to DX)
CWDE word to double word conversion. (Extend the sign of the word in AX to EAX)
CDQ double word extension. (Extend the sign of the word in EAX to EDX)

III. Logical operation
instructions───────────────────────────────────────
  AND AND operation.
or OR operation.
XOR Exclusive OR operation.
NOT negation.
TEST test. (AND operation of two operands, only modify the flag bit, and do not return the result).
SHL logical left shift.
SAL arithmetic left shift. (=SHL)
SHR logical right shift.
SAR Arithmetic shift right. (=SHR)
ROL Rotate left.
ROR Rotate right.
RCL Rotate left through carry.
RCR Circular right shift through carry.
The above eight shift instructions can shift up to 255 times.
When shifting once, the operation code can be used directly. For example, SHL AX,1.
When shifting >1 times, the number of shifts is given by register CL.
For example, MOV CL,04
SHL AX,CL

IV. String instructions────────────────────────────────────────
DS
 :SI Source string segment register: source string displacement.
ES:DI Destination string segment register: destination string displacement.
CX Repeat counter.
AL/AX Scan value.
D flag 0 indicates that SI and DI should be automatically incremented in the repeat operation; 1 indicates that they should be automatically decremented.
The Z flag is used to control the end of the scan or comparison operation.
MOVS String transfer.
(MOVSB ​​transfers characters. MOVSW transfers words. MOVSD transfers double words.)
CMPS String comparison.
(CMPSB compares characters. CMPSW compares words.)
SCAS String scan.
Compare the contents of AL or AX with the target string, and the comparison result is reflected in the flag.
LODS Load string.
Load the elements (words or bytes) in the source string into AL or AX one by one.
(LODSB transfers characters. LODSW transfers words. LODSD transfers double words.)
STOS Save string.
It is the reverse process of LODS.
REP Repeat when CX/ECX<>0.
REPE/REPZ Repeat when ZF=1 or the comparison result is equal, and CX/ECX<>0.
REPNE/REPNZ Repeat when ZF=0 or the comparison result is not equal, and CX/ECX<>0.
REPC Repeat when CF=1 and CX/ECX<>0.
REPNC Repeat when CF=0 and CX/ECX<>0.

V. Program transfer
instructions───────────────────────────────────────
 1> Unconditional transfer instruction (long transfer)
JMP Unconditional transfer instruction
CALL Procedure call
RET/RETF procedure return.
2> Conditional transfer instructions (short transfer, within the range of -128 to +127)
(If and only if (SF XOR OF) = 1, OP1
JA/JNBE is not less than or equal to transfer.
JAE/JNB is greater than or equal to transfer.
JB/JNAE is less than transfer.
JBE/JNA is less than or equal to transfer.
The above four items test the results of unsigned integer operations (flags C and Z).
JG/JNLE is greater than transfer.
JGE/JNL is greater than or equal to transfer.
JL/JNGE is less than transfer.
JLE/JNG is less than or equal to transfer.
The above four items test the results of signed integer operations (flags S, O and Z).
JE/JZ is equal to transfer.
JNE/JNZ is not equal to transfer.
JC is transfer when there is a carry.
JNC is transfer when there is no carry.
JNO is transfer when there is no overflow.
JNP/JPO is transfer when the parity is odd.
JNS is the sign bit "0"
JO Transfer when overflow.
JP/JPE Transfer when parity is even.
JS Transfer when the sign bit is "1".
3> Loop control instructions (short transfer)
LOOP Loop when CX is not zero.
LOOPE/LOOPZ Loop when CX is not zero and flag Z=1.
LOOPNE/LOOPNZ Loop when CX is not zero and flag Z=0.
JCXZ Transfer when CX is zero.
JECXZ Transfer when ECX is zero.
4> Interrupt instruction
INT Interrupt instruction
INTO Overflow interrupt
IRET Interrupt return
5> Processor control instruction
HLT The processor pauses and continues until an interrupt or reset signal occurs.
WAIT When the chip lead TEST is high, the CPU enters the waiting state.
ESC Transfer to the external processor.
LOCK Block the bus.
NOP No operation.
STC Set the carry flag.
CLC Clear the carry flag.
CMC Invert the carry flag.
STD Set the direction flag.
CLD Clear the direction flag.
STI sets the interrupt enable bit.
CLI clears the interrupt enable bit.

VI. Pseudo-instructions────────────────────────────────────────
DW
defines a word (2 bytes).
PROC defines a procedure.
ENDP ends a procedure.
SEGMENT defines a segment.
ASSUME establishes segment register addressing.
ENDS ends a segment.
END ends a program.

VII. Processor control instructions: 
Flag processing instructions CLC (carry position 0 instruction)
CMC (carry bit negation instruction)
STC (carry position 1 instruction)
CLD (direction flag set 1 instruction)
STD (direction flag set 1 instruction)
CLI (interrupt flag set 0 instruction)
STI (interrupt flag set 1 instruction)
NOP (no operation)
HLT (stop)
WAIT (wait)
ESC (escape)
LOCK (lock)
 
Are assembly instructions conditional?
Operation Code  Condition code mnemonics  Logo  meaning
 0000  EQ  Z=1  equal
 0001  NE (Not Equal)  Z=0  not equal
 0010  CS/HS (Carry Set/High or Same)  C=1  Unsigned greater than or equal to
 0011  CC/LO (Carry Clear/LOwer)  C=0  Unsigned number is less than
 0100  MI(MInus)  N=1  negative number
 0101  PL(PLus)  N=0  Positive number or zero
 0110  VS (oVerflow set)  V=1  overflow
 0111  VC (oVerflow clear)  V=0  No overflow
 1000  HI (HIgh)  C=1,Z=0  Unsigned number greater than
 1001  LS (Lower or Same)  C=0,Z=1  Unsigned number less than or equal to
 1010  GE (Greater or Equal)  N=V  Signed number greater than or equal to
 1011  LT (Less Than)  N!=V  Signed number is less than
 1100  GT (Greater Than)  Z=0,N=V  Signed number greater than
 1101  LE (Less or Equal)  Z=1,N!=V  Signed number less than or equal to
 1110  AL  any  Unconditional execution (default)
 1111  NV  any  Never execute

 

 
Keywords:ARM Reference address:ARM Architecture Learning 3

Previous article:ARM architecture learning 2
Next article:ARM architecture learning 4

Recommended ReadingLatest update time:2024-11-16 14:44

Android ARM Assembly Language
Introduction ARM is the acronym for Advanced RISC Machine. It can be called an embedded processor provider, a processor architecture, or a complete processor instruction set. Native Programs and ARM Assembly Language For Android phones using ARM processors, it will eventually generate the corresponding ARM e
[Microcontroller]
Difference between LDR and ADR in ARM assembly
          ldr r0, _start         adr r0, _start         ldr r0, =_start         nop         mov pc, lr _start:         nop         Set RO to 0x0c008000 when compiling ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ 0c008000 _start-0x14 : c008000: e59f000c ldr r0, ; c008014 _start c008004: e28f000
[Microcontroller]
Small wheeled robot platform based on software and hardware collaborative processing
1 Project Background and Objectives 1.1 Project Background The topic of this article originated from the mobile robot project and smart car competition of Renesas Laboratory of Huazhong University of Science and Technology. The main purpose is to design a small mobile robot platform based on embedded technology an
[Microcontroller]
Small wheeled robot platform based on software and hardware collaborative processing
Overview of the instruction set of ARM microprocessors 2 - Detailed notes on ARM application system development
A jump instruction         Jump instructions are used to implement program flow jumps. There are two ways to implement program flow jumps in ARM programs:                 - Use special jump instructions.                 - Directly write the jump address value to the program counter PC.         The jump instructio
[Microcontroller]
Analysis of embedded operating system
Embedded operating systems all have a certain degree of real-time performance and are easy to cut and scale. They can be suitable for various ARMCPUs from ARM7 to Xscale and various grades of applications. Embedded operating systems can use widely popular ARM development tools, such as ARM's SDT/ADS and RealView, etc.
[Microcontroller]
Modify the shell prompt under Linux (ARM)
1): Create a global variable file: /etc/profile        Add the following content:        PS1='Andy--#'        export PS1        Note: The variables defined in /etc/profile are global, that is, they are valid for all logged-in Linux users. In ordinary scripts, export is only valid in the current script and child pro
[Microcontroller]
The two ARM Cortex
All devices we have explored so far in the Zynq All Programmable SoC PS (Processor System) have used only one ARM Cortex-A9 processor core (Core 0), however the PS portion of the Zynq SoC contains two processor cores, and for many applications we want to use both processor cores to maximize performance. Using two proc
[Microcontroller]
The two ARM Cortex
ARM processor architecture
The ARM architecture is the foundation on which every ARM processor is built. The ARM architecture has evolved over time to include architectural features that address growing new features, high performance requirements, and the needs of emerging markets. For information on the latest announced version, see ARMv8 Ar
[Microcontroller]
ARM processor architecture
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号