MCES_Unit_1_2_ARM_2023
MCES_Unit_1_2_ARM_2023
ARM – stands for “Advanced RISC Machine” , ARM based microcontrollers are very
popular in 32 bit embedded market, occupying the major share of the market. ARM7 was
the first commercial success, used extensively in products like PDAs, IPods, hard disks, set-
top boxex, mobile phones etc.
ARM Supports Data bus width of 32bits, supporting very high data bandwidth, so reading
and writing 32 bit data in one cycle.
It is the chip which has in-built cpu core (some version of ARMcore, like ARM7/9/11) and
the necessary large set of peripherals and memory to perform as a system. Hence, it is
referred as System On chip (SoC) .
ARM7TDMI-S , it is based on ARM 7 core, and has features like Thumb instructions
set (T), JTAG debugger (D), fast multiplier (M) and the embedded ICE (I) [ICE- in
circuit emulator, useful while debugging hardware & software], S – synthesizable
Operating Modes : ARM has seven operating modes, i.e it exists in any one of these
modes when the processor is running,
i) User mode: simplest mode with least privileges (or also referred as Unprivileged
mode), this is the mode under which most applications run, User mode is used for
the execution of programs and applications.
ii) FIQ Mode (Fast interrupt request): Entered this mode on request from FIQ
interrupts
iii) IRQ Mode (Interrupt Request): Entered this mode on IRQ request
iv) Supervisor: Entered on Reset and when a software interrupt instruction (SWI) is
executed, and is generally the mode in which the operating system kernel
operates in.
v) Abort: Used to handle memory access violations, Abort is entered after a failed
memory access
vi) Undef: Used to handle undefined instructions, Undefined is entered if the
instruction is not defined (invalid opcodes)
vii) System: This is highly privileged mode used by operating systems to manipulate
and control the activities of the processor, System mode is a special version of
user mode that allows full read write access to the CPSR
Register Set: ARM has 37 registers of size 32bits each, they are
R0-R12 - general purpose registers, used for holding both data and address
R13 - Stack pointer (SP)
R14 - Link register (LR)
R15 - Program counter
R14 i.e link register, a special register, used to hold the contents of PC when branching
due to procedural call or interrupts occur. On return PC is loaded back with the contents
of link register. This avoids the overhead of using the stack, i.e basically memory access
(as memory located outside the ARM core)
But not all registers are seen at once. The processor state and operating mode decide
which registers are available to the programmer, At any time only 16 of the 31 general
purpose registers are available to the programmer.
Mode Switching: When the processor switches the mode, say from the user mode to FIQ
mode (on receiving the FIQ interrupt) some of the user mode registers are replaced by
another set of registers, here R8 to R14 are replaced by another set of registers, and names
of these registers are suffixed by FIQ, like R14_FIQ,R12_FIQ and so on.
Why is it that FIQ uses another set of Registers? Note that this mode is entered on a ‘fast
interrupt’ which means it requires fast action. One action during interrupts would be to
save the contents of the currently used registers. This saving takes some time. To ensure
fast operation, in the case of being switched to the FIQ mode, new registers are used. No
time is spent on saving the contents of register R8 to R14 of the user mode. Once the FIQ
mode is entered, those registers are just swapped out, and replaced by a set of new
registers. Not all registers are swapped out. In IRQ mode, only R13 and R14 are replaced
by new registers. In the IRQ mode response need not to be as fast as in the FIQ mode,
there is sufficient time to save contents of most of the registers before mode switching is
done. This also applies to modes ‘undef, supervisor and abort’ , here also only two
registers are swapped out and replaced with the new once.
CPSR – Current Program Status Register, is a very important register, and there is only
one such register for the processor. The CPSR contains the information about the current
state of the processor. It has bits which specify the mode, control bits to enable or disable
FIQ/IRQ interrupts ,THUMB/ARM mode in use and the conditional flags
(Sign,Overflow,Carry,Zero – meaning is same as that of 8086/8051).
[ Bit allocation and Definition of CPSR register
C, CY flag – This flag is set whenever there is a carry out from the D31 bit. This flag bit is affected after a
32 bit addition or subtraction
Z, Zero Flag – The zero flag reflects the result of arithmetic or logic operation. If the result is zero, then
Z=1. (Z=0 , if the result is not zero).
N, Negative flag (Sign flag): Signed numbers uses D31 as the sign bit. The negative flag reflects the result
of an arithmetic operation. If the D31 bit of the result is zero, then N=0 and result is positive. If the D31 bit
is ‘1’ , then N=1, the result is negative.
V,Overflow Flag – This flag is set whenever the result of a signed number operation is too large, causing
the high order bit to overflow into the sign bit.
The V and N flags are used for signed number arithmetic operations.
T – The T flag is used to indicate the ARM is in Thumb state.
I - Used to enable / disable IRQ interrupt.
F – Used to enable / disable FIQ interrupt
M4-M0 – Indicate CPU operating Mode
]
It also provides Sticky overflow flag, this flag indicates overflow itself, but it is ‘sticky’
in the sense that it remains set until explicitly cleared. The contents of this register can be
modifiable only in system mode.
SPSR –Saved Program Status Register: There are five saved program status registers,
that is, one for each of the exception modes of operation. When an exception, that is, an
interrupt occurs, the corresponding SPSR saves the current CPSR value into it (so as to be
able to retrieve it on returning to the previous mode). The system mode and user modes
do not have SPSRs because they are not entered through the mechanism of interrupts.
ARM generates predefined interrupt vector (i.e starting address of ISR), whenever
a) Exceptions are generated (Undefined instruction, prefetch abort, data abort)
b) on execution of SWI, software interrupt
c) on RESET
d) on receiving IRQ or FIQ
These addresses/vectors, holds the ISR code or code to branch to ISR (interrupt handlers).
Shift and Rotate operations can be part of other Register Transfer / Arithmetic / Logic
operations. One of the operand can be operated by shift/rotate operations using barrel
shifter.
MOV R0, #2
MOV R1, #3
ADD R2, R1, R0, LSL #1
Example : Write the output of the following program, after execution of each instruction
MOVS R0, #0
Conditional Execution : Suffixing condition codes is possible for any data processing
and branch instructions, if condition code satisfies instruction works, else it is a NOP
instruction. There are 15 such condition codes.
Ex: MOVEQ R0, #10 ; 10 is moved to R0, if Zero flag is set else it is a NOP
Other Commonly used Condition codes :
EQ Z=1 zero flag set
NE Z=0 zero flag clear
CS C=1 carry flag set
CC C=0 carry flag clear
MI N=1 Sign/Negative flag set (number is MINUS)
PL N=0 Sign/Negative flag is clear(number is POSITIVE)
Case 1:
MOVS R0,#0
MOVEQ R0,#10
Answer - R0 = 10
Case 2:
MOV R0,#0
MOVEQ R0,#10
Answer – R0 = 0
MOV R0,#0X0FF
MOV R1,#0X010
CMP R0,R1
MOVCS R2,R0
MOVCC R2,R1
ARITHMETIC INSTRUCTIONS
Format:
ADD REG, REG, (REG/IMM)
SUB REG, REG, (REG/IMM)
RSB REG, REG, (REG/IMM)
(Similar instructions:
ADC(Addition with Carry), SUB (Substation), SBC (Subtraction with Carry),
RSB(Reverse Subtraction), RSC(Reverse subtraction with borrow).
STOP B STOP
END
Format:
AND REG, REG, (REG/IMM)
EOR REG, REG, (REG/IMM)
ORR REG, REG, (REG/IMM)
BIC REG, REG, (REG/IMM)
MOV R1,#00100011B
Ex: BIC R0, R0, R1 ; to clear bit 0,1 and 5 of the Register R0
The CPSR register contains four flags Negative(sign flag),Zero,Carry and Overflow flags,
which are affected by the execution of following instructions. Flags are also affected by
using suffix S to the other data processing instructions.
Format:
CMP REG, (REG/IMM)
TST REG, (REG/IMM)
TEQ REG, (REG/IMM)
Format:
MUL REG , REG, REG
MLA REG , REG, REG, REG
Examples:
MUL R1 , R2 , R3 - Multiply R1 R2 x R3
MLA R4 , R3 , R2 , R1 - Multiply and Accumulate; R4 (R3 x R2) + R1
BRANCH INSTRUCTIONS
PROC1 ;logic
;logic
MOV PC , LR ; contents of LR copied back to PC, hence RET is executed
Use procedure to compute square of a number
MOV R0,#2
BL SQU
STOP B STOP
These are the only instructions are available to access memory, LDR instruction used for
loading the data from memory to registers and STR instruction is used to store the data
from registers to memory. Memory is organized as bytes, hence 32 bit number requires 4
bytes (4 contiguous addresses).
ARM supports both the base-index and base-offset addressing modes for load and store
instructions. It has additional support for shifting the index register by treating it as a
shifter operand. It has additional support for loading and storing bytes(8bit) and half-
words(16bit) (default is 32 bits).
Format:
Ex:
LDR R1, [R0] ; contents of memory(32 bit number – 4 bytes) pointed by R0 is loaded
into R1
STR R1, [R0] ; contents of R1(32bit number-4 bytes) is stored in memory pointed by
R0.
LDR R1, [R0,R2,LSL #2] ; the effective memory address is obtained by adding R0 and
shifted R2. The 32 bit number is loaded to R1 from the new effective address. (This kind
of addressing is referred as base addressing; one register can point to the base address and
the other register contents can be used to index from the base address. It is used to access
data structures like arrays). Load & Store also supports pre and post indexed addressing
modes with auto-update].
AREA RESET,CODE,READONLY
ENTRY
LDR R0,=NUMS
LDR R1,[R0]
LDR R2,[R0,#4]
LDR R0,=RES
ADD R1,R1,R2
STR R1,[R0]
STOP B STOP
NUMS DCD &1,&2
AREA MEMORY,DATA
RES SPACE 4
END
Compute the outputs after executing following code snippets
Examples:
1. Translate the following code in C to the ARM instruction set. Assume variables
are 32bit integers represented in Registers.
A=B+ C+D
MOV R0,#00 ; A
MOV R1,#NUM1 ; B
MOV R2,#NUM2 ; C
MOV R3,#NUM3; D
ADD R0,R2,R1
ADD R0,R0,R3
A = 2*A + B
MOV R0,#NUM1 ; A
MOV R1,#NUM2; B
ADD R0,R1,R0,LSL #2
MOV R0,#0X04
MOV R1,#0x02
ORR R0, R0, R1, LSL #1
Ans – 0x04
MOV R0,#0x02
ADDS R0,R0,R0,ASR R0
Ans – 0x02
MOV R0,#1
MOV R1,#2
MUL R3,R0,R0
MLA R3,R1,R0,R3
Ans – R3 : 0x03
[EXTRA INFORMATION:
The branch instructions have an L bit to specify if the return address needs to be saved or
not. They use PC-relative addressing and have a 24 bit signed offset. The hardware
assumes that instructions are aligned to 4 byte boundaries, and treats this offset as a
distance in terms of memory words. It thus left shifts the offset by 2 positions.
These are the only instructions are available to access memory, LDR instruction used for
loading the data from memory to registers and STR instruction is used to store the data
from registers to memory. Memory is organized as bytes, hence 32 bit number requires 4
bytes (4 contiguous addresses).
ARM supports both the base-index and base-offset addressing modes for load and store
instructions. It has additional support for shifting the index register by treating it as a
shifter operand. It has additional support for loading and storing bytes(8bit) and half-
words(16bit) (default is 32 bits).
Format:
Ex:
LDR R1, [R0] ; contents of memory(32 bit number – 4 bytes) pointed by R0 is loaded
into R1
STR R1, [R0] ; contents of R1(32bit number-4 bytes) is stored in memory pointed by
R0.
LDR R1, [R0,R2,LSL #2] ; the effective memory address is obtained by adding R0 and
shifted R2. The 32 bit number is loaded to R1 from the new effective address. (This kind
of addressing is referred as base addressing; one register can point to the base address and
the other register contents can be used to index from the base address. It is used to access
data structures like arrays). Load & Store also supports pre and post indexed addressing
modes with auto-update].
Encoding of Instructions:
Ex: for data processing instruction: Allocation of 32 bits from MSB is indicated below
with the bit allocation.
Condition code,[4bit]
Instruction type – 00 [2],
I – Immediate operand yes/no,[1bit]
Opcode –Type of data processing instruction [4 bits]
S – update CPSR [1 bit],
Rs – Register representing 1st source operand [4 bits-16regs]
Rd – Register representing destination operand[4bits]
Shifter register Operand / Immediate [12 bits]
12bits allocated to represent immediate operand. These 12 bits are split into two parts – a
4 bit constant(rot), and an 8bit payload (payload).
Using Stack:
MOV R0,#00 ; A
MOV R1,#NUM1 ; B
MOV R2,#NUM2 ; C
MOV R3,#NUM3; D
ADD R0,R2,R1
SUB R0,R0,R3
STOP B STOP
END
A = 2*A + B
MOV R0,#NUM1 ; A
MOV R1,#NUM2; B
ADD R0,R1,R0,LSL #2
STOP B STOP
END
AIM: Write an ARM ALP to perform addition and subtraction of two 32-bit and
64bit numbers.
MSB:LSB
Value1 = R1 : R2
Value2 = R3 : R4
Result = R5 : R6
Program:
AREA RESET, CODE
ENTRY
LDR R0,=VALUE1
LDR R1,[R0]
LDR R2,[R0,#4]
LDR R0,=VALUE2
LDR R3,[R0]
LDR R4,[R0,#4]
ADDS R6,R2,R4
ADC R5,R1,R3
LDR R0,=RESULT
STR R5,[R0]
STR R6,[R0,#4]
STOP S STOP
Algorithm:
1) Initialize first element as smallest [R1] and number of elements n = n-1
2) Loop through all the n [R4] elements. If the current element is smaller than the
smallest, then update smallest.
AIM: Write an ARM ALP to find smallest and largest of N- 32 bit numbers.
AREA RESET,CODE
ENTRY
LDR R0,=DATA1
LDR R3,=0X40000000 ; memory location for storing answer
MOV R4,#05 ; //N- number of elements
LDR R1,[R0],#04; assume first no. as smaller no & increment R0 by 4
SUB R4,R4,#01 ; compare with n-1 elements
BACK
LDR R2,[R0] ; get next number & compare with small
CMP R1,R2
BLS LESS ; // If R1 < R2 , BRANCH
MOV R1,R2 ; update with new smaller no
LESS
ADD R0, R0,#04 ; increment pointer to next number
SUB R4,R4,#01
CMP R4,#00
BNE BACK
STR R1, [R3] ; // SMALLEST VALUE STORED IN MEMORY LOCATION
STOP B STOP
AREA DATA,CODE
DATA1 DCD &64,&05,&96,&10,&65
END
Sample Output:
Experiment No 3A:
Algorithm:
1) Initialize sum = 0
2) Loop through all the n elements. Add the current element to sum.
Program:
MOV R3,#0
MOV R4, #0
LDR R0, =INPUTS
LDR R1, =OUTPUTS
CONT
LDR R2, [R0]
ADD R4, R4, R2
ADD R0, R0, #4
ADD R3, R3, #1
CMP R3, #5
BNE CONT
MOV R2, #5
MOV R3, #0
REPT SUBS R4, R4, R2
ADDPL R3, R3, #1
BPL REPT
ADDMI R4, R4, R2
STR R3, [R1]
STOP B STOP
END
Sample Output:
Experiment No 4A:
AIM: Write an ARM ALP to count the occurrences of the given 32-bit number in a
List using Linear Search algorithm
Algorithm:
Linear Search ( array A, key x)
{
for i =0 to n
if A[i] = x then
increment element found count
}
Program:
AREA RESET, CODE, READWRITE
ENTRY
LDR R0,=ARR
MOV R1, #0 ; Loop Iterator
MOV R7, #0 ; Number Of occurrences in The Array
MOV R4, #4 ; key
CONT
LDR R3,[R0]
CMP R3, R4
BNE SKIP
ADD R7, R7,#1
SKIP
ADD R0, #4
ADD R1, #1
CMP R1, #10 ; no of elements
BNE CONT
STOP B STOP
ARR DCD 0,5,1,4,100,4,0,8,7,20
END
Sample Output:
Experiment No 5A(i):
AIM: Write an ARM ALP to compute number of 1’s in a given 32 bit number and
check the parity of the given number
Program:
AREA RESET,CODE
ENTRY
LDR R0,=DATA1
LDR R1,[R0] ;Stores 32bit number-16 ones
MOV R2,#0 ;loop counter, 32 times(32bits)
MOV R4,#0 ;number of 1's counter
MOV R3,#1
LOOP
MOVS R1,R1,LSR #1
ADDCS R4,R4,#1
ADD R2,#1
CMP R2,#32 ; check for 32 bits
BNE LOOP
STOP B STOP
AREA DATA,CODE
DATA1 DCD 0xAAAAAAAA
END
Sample Output:
Experiment No 5A(ii):
AIM: Write an ARM ALP to compute GCD of two given 32-bit numbers.
Algorithm:
int gcd(int x,int y){
while(x!=y)
{
if(x>y)
return gcd(x-y,y);
else
return gcd(x,y-x);
}
return x;
}
Program:
AREA RESET,CODE
ENTRY
MOV R0,#30 ; test values
MOV R1,#45 ; test values
LOOP CMP R0,R1
BEQ EXIT
BGT COND1
SUB R1,R0
B LOOP
COND1 SUB R0,R1
B LOOP
EXIT LDR R0,=GCD
STR R1,[R0]
STOP B STOP
AREA RESULT,DATA
GCD SPACE 4
END
Sample Output:
Experiment No 6A:
AIM: Write an ARM ALP to compute the factorial of a given 32-bit number using
procedure.
Algorithm:
fact(int n)
{
Read number n.
Initialize i =n and fact to 1.
Repeat while i is not equal to 0.
{
fact = fact * i
i = i -1
}
Return fact
}
Program:
AREA RESET,CODE
ENTRY
LDR R0,=INPUT
BL FACT ; CALL SUBROUTINE FACT
LDR R1,=0X40000000 ; RAM area
STR R3,[R1] ; store result in R3 to RAM
STOP B STOP
;subroutine-begin
FACT
LDR R2,[R0] ; get num in R2
CMP R2,#00
BEQ END1
MOV R3,R2 ; result = num
LOOP
SUB R2,#01 ; num = num - 1
CMP R2,#00
MULNE R3,R2,R3 ;result = result * num
BNE LOOP
MOV PC,LR
END1
MOV R3,#01 ; return R3=1, if num=0
END2
MOV PC,LR ; return from subroutine
;subroutine-end
MOVEQ R0,#10
MOVEQ R0,#10
Write the value in R0 (32 bit number) after the execution of following instructions.
(Write Ans: Hex with caps,use zero key for typing ‘0’ Ex: F0FFFF82)
MOV R0,#0X06
MOV R0,R0,ROR #31
MOV R1,#0x02
ORR R0, R0, R1
Write the value in R0 after executing the following instructions:
(Write Ans: Hex with caps,use zero key for typing ‘0’ Ex: F0FFFF82)
MOV R0,#1
MOV R0,R0,LSL #31
MOV R1,R0,ASR #2
Write the value in R0 after executing the following instructions:
(Write Ans: Hex with caps,use zero key for typing ‘0’ Ex: F0FFFF82)
MOV R0,#0X0FF
MOV R1,#0X010
CMP R0,R1
MOVCS R2,R0
MOVCC R2,R1
Write the value in R3 after executing the following instructions:
MOVS R1,#1
MOVS R0,#0
MOVEQS R0,#5
MOVEQ R1,#5
MOV R4,R1,LSL R0
MLA R3,R0,R1,R4
ARM Assembly Language Programming Fundamentals :
1. Actual instructions, like MOV,ADD.. which are converted to binary form and
executed by the ARM processor.
2. Instructions to Assembler, like AREA,END..which are used by the assembler in the
process of generation of binary/hex file. They are not converted to machine codes but
instructs the assembler like where the program is beginning, naming the memory
locations, allocation of memory,end of the assembly program. Etc.
Example:
CONT ADD R1,R2,R3 ; adding two registers
Assembly directives:
AREA :
used to name/define memory area for code and data.
Example1: AREA RESET,CODE ,READONLY ; used to name the memory area
RESET, which is meant for storing code and it is of type READONLY (it is optional).
(Note: In Keil, the starting program area to be named as RESET).
Example2: AREA TABLE,DATA ; refers to the memory area by name TABLE used to
store read-write data. We use DATA attribute along with AREA to refer SRAM memory.
ENTRY :
This directive, indicates the first instruction to be executed. An application can have only
one ENTRY point. Hence it can be used in only one source module.
END :
This is an instruction to the assembler, indicating end of the assembly program. Any
instructions written after this, will not be assembled. This will be the last line of any ASM
program and it is compulsory.
DCD :
This directive is used to define, one or more words( a word refers to 32 bit number in
ARM architecture) in code memory.
Example: NUMS DCD 10 , 0X9234ABCD
Here the starting memory location, used store the words are referred by name, NUMS.
Four bytes (i.e 4 addressees) are required to store one 32 bit number. Here the first
number, 10 represented in decimal is stored at NUM, and the second number,
0x9234ABCD,represented in hexadecimal is stored at the memory location, NUM+4. The
actual memory addresses are allocated by the assembler ( it can be checked in the List file,
extension LST, optionally generated by the assembler).
In the above case, if assembler allocates,say 0x00000100 for NUM, then first number is
stored at: 0x0000 0100 and second number is stored at 0x0000 0104
DCB : used to define/allocate memory space in bytes. One byte(one address) for one
number.
NUM DCB 8,0X10
DCW: used to define/allocate memory space in half words. Two bytes (two memory
addresses) are allocated for each number.
NUM DCW 10,0X34
EQU :
This directive is used to equate/name the constants (like macros in C). Constants refers to
numbers represented either in decimal/hex/any other base),characters, strings and Boolean.
Example: CORN_FACTR EQU 2
BASE_ADDR EQU 0X40000000
AREA RESET,CODE
ENTRY
MOV R0,#BASE_ADDR
MOV R1,#CORN_FACTR
RN :
Using this directive we can name the ARM Registers R0 TO R15 ( O TO 15) to user
comprehendible names like x,y,res etc and use these names while writing ASM programs.
It looks easy to the programmer to write programs by referring these names, rather than
Register numbers.
NUM_A RN 0
NUM_ B RN 1
RES RN 2
AREA RESET,CODE
MOV NUM_A ,#1
MOV NUM_B ,#20
ADD RES, NUM_A , NUM_B
Data Types :
ARM can operate on 32 bit data, referred as WORD. It can also operate on 16 bit data
(referred as double word) and 8 bit data (referred as byte operand).
Little Endian and Big Endian storage: Intel processors store the data in little endian
format, (i.e LSB first,MSB last). Motorola processors store data in big endian format
(MSB first,LSB last). One of the special feature of ARM is, it supports storage in both
these formats, suitably can be configured by the initialization code. By default, we are
using little endian format, while writing our ASM programs using Keil.
Ex: Indicate the data and memory addresses, assume little endian format
LDR R0,=0X4000 0000
LDR R1,#0X12345678
STR R1,[R0]
0x4000 0000 0x78
0x4000 0000 0x56
0x4000 0000 0x34
0x4000 0000 0x12
Data Alignment
ARM 7 core is a 32 bit machine and it has 32 bit data bus. Hence, it can read 32 bit
number (1 Word) from memory in one cycle. But memory is organized in bytes, meaning
every memory address refers to one byte of data, so four memory addresses contributes to
32 bit data. Since, all the four bytes of data are required to put on the data bus
simultaneously, memory is organised into banks, as shown in the below figure.
Next numbers in the memory is stored at address 0x4000 0004,0x4000 0008..we can
observe the last two bits are always zero. It is referred as, 32 bit data alignment . If last
two bits are zero, then we say it is aligned address, for accessing 32 bit data. If we are
referring memory address in the instruction which is not aligned, say 0x4000 0001, then
we require two memory cycles to load the data from memory. In the first cycle, we access
3 bytes and then in second cycle we access one byte. Hence taking more time, and not
optimised.
Most of the ARM tools ensure that the data is stored in aligned locations, so as to avoid
unnecessary extra cycles of operation.
Note: for half-word (16 bit access), the specified address should have its LSB bit 0, for
alignment.
Storing (and loading also) of 4 bytes in memory can be done in one cycle, because the
processor has a 32 bit data bus. When 32 bit data is stored in memory, four addresses are
needed. We need to specify only one address in our instruction; but there is an aspect
called ‘alignment’. For 32-bit data,’alignment’ implies that the last two bits of this address
are zero. For example, the address 0x00001200 is an aligned address. When this address is
used to store 32 bit data, this address and the next three addresses are automatically
accessed. This is because of the way memory is organized, as four banks.
Conditional Codes and Corresponding Flag Status
0000 EQ EQUAL Z =1
0001 NE NOT EQUAL Z=0
0010 CS/HS CARRY SET/UNSIGNED >= C=1
0011 CC/LO CARRY CLEAR/UNSIGNED < C=0
0100 MI MINUS/NEGATIVE N=1
0101 PL PLUS/POSITIVE OR ZERO N=0
0110 VS OVERFLOW V=1
0111 VC NO OVERFLOW V=0
1000 HI UNSIGNED HIGHER C=1 AND Z=0
1001 LS UNSIGNED LOWER/EQU C=0 OR Z=1
1010 GE SIGNED >= N=0
1011 LT SIGNED< N=1
1100 GT SIGNED > Z=0 AND N=0
1101 LE SIGNED<= Z=1 OR N=1
1110 AL ALWAYS (ALWAYS EXECUTE)
1111 RESERVED
Conditions for signed and unsigned numbers are different. For unsigned numbers we use
the mnemonic ‘higher’ or ‘lower, while for signed numbers, the conditions are specified as
‘greater than’ or ‘lower than’.
For unsigned numbers, carry flag( also called as borrow flag, when we do
substraction/comparision) and zero flag is used.
MOV R0,#num1
CMP R0,#num2
BHI SKIP ;
MOV R1,#0 ; num1 < num2
SKIP
MOV R1,#1 ; num1 > num2