{"id":338,"date":"2018-07-27T09:26:17","date_gmt":"2018-07-27T09:26:17","guid":{"rendered":"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/?post_type=chapter&#038;p=338"},"modified":"2018-07-27T11:19:47","modified_gmt":"2018-07-27T11:19:47","slug":"arm-instruction-set","status":"publish","type":"chapter","link":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/chapter\/arm-instruction-set\/","title":{"rendered":"ARM instruction Set"},"content":{"raw":"<div>\r\n\r\n<strong>About the module:<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Thismodule aims at exploring ARM instruction set to design an embedded application. The core part of any program will always consist of arithmetic and logical operations. In this module,we start with Instruction set classification, diving into details of data processing instructions and the representation of data.<\/p>\r\n&nbsp;\r\n\r\n<strong>Learning Outcomes:<\/strong>\r\n\r\n&nbsp;\r\n<ul>\r\n \t<li>Able to understand the nuances of ARM programming.<\/li>\r\n \t<li>Should be able to write an ARM program incorporating the arithmetic and logicalinstruction.<\/li>\r\n<\/ul>\r\n&nbsp;\r\n\r\n<strong>1.1 <\/strong><strong>ARM ISA Features<\/strong>\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">ARM is a RISC based processor with LoadStore architecture. Load and store instructions are the memory access instructions. The load instruction reads data from memory address space and store instruction writes into it.The ALU operations are performed on the values that are stored in the register file. Except for load and store, all the other categories of instruction access data from the registers. Few features of ARM ISA are listed below.<\/p>\r\n&nbsp;\r\n\r\nFixed-length 32-bit instructions. 3-address instruction formats.\r\n\r\n&nbsp;\r\n\r\nLoad and store multiple registers.\r\n\r\n&nbsp;\r\n\r\nShift and ALU operationsare performed in a single instruction.\r\n\r\n&nbsp;\r\n\r\nOpen instruction set extension through the coprocessor instruction. Very dense 16-bit compressed instruction set (Thumb).\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\n<strong>1.1.1<\/strong>\u00a0\u00a0\u00a0\u00a0 <strong>Coprocessor<\/strong>\r\n\r\n&nbsp;\r\n\r\nOne of the additional feature of ARM is the coprocessor extension.\r\n\r\n<\/div>\r\n<div>\r\n\r\n<img class=\"aligncenter size-full wp-image-342\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-197.png\" alt=\"\" width=\"588\" height=\"415\" \/>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">ARM can be interfaced with another processor which expands the functionality of the ARM (Figure 1.1).Up to sixteen coprocessors can be defined and interfaced with ARM. The coprocessor interface expands the ARM instruction set. In the decode stage if the processor identifies the coprocessor instruction, it hands it over to the relevant coprocessor; otherwise it raises an undefined instruction exception. ARM has instructions to access registers in the coprocessor. Each coprocessor can have up to sixteen private registers of any reasonable size.<\/p>\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\n<strong>1.2 <\/strong><strong>ARM INSTRUCTION SET<\/strong>\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Instruction set is the neural schema of any processor which enables any embedded programmer to understand and utilize a processor. In general, the ARM processor classifies its instruction set into two categories: 1. ARM instruction set and 2. Thumb instruction set. The ARM instructions are 32-bits(word) wide and word-aligned.Thumb instructions are 16 bits(half-word) or 32-bits (word) wide.It is aligned on 2 byte(8bits = 1 byte)or 4 byte(word) boundaries. The Thumb is the subset of ARM and most of its operation maps to the ARM instruction set. The thumb set was introduced to reduce the code size. The processor can execute either the Arm instruction or the Thumb instruction by switching the T bit in the status register CPSR. If the T-bit is set, the processor is in Thumb state and executes Thumb instructions. If the T-bit is reset, the processor is said be in ARM state. Most of the privileged resources are accessed by ARM instructions. The processor executes exception handlers always in the ARM state.We start with exploring the ARM instruction set.Figure 1.2 shows the format of ARM instruction. The instruction is of three address format. An example mnemonic ADD d1,s1,s2 performs addition on source operand s1 and s2 and stores the result in destination d1. The 32 bits are divided\u00a0<span style=\"font-size: 1em;text-align: initial\">among the function(operation) to be performed and the addresses of three operands. The number of bits allocated for addressing operands depends on the addressing mode. For example, if the operands use register addressing mode, we need four bits to address individual operands.<\/span><\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n<img class=\"aligncenter size-full wp-image-343\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-198.png\" alt=\"\" width=\"621\" height=\"186\" \/>\r\n\r\n<strong>1.3 ARM DATA TYPES<\/strong>\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">To understand the ARM instruction set, we list the different data sizes the ARM processor supports. Based on the sizes there are six datatypes. Largely speaking, the data is processed in word, half-word and bytes. By default the instruction processes the operand with a word size. The instructions are appended with alphabet \u2018b\u2019 and \u2018h\u2019 to indicate the data size of byte and half word. Each data size can have signed or an unsigned representation. Following are the categories of data types used in the ARM ISA:<\/p>\r\n&nbsp;\r\n\r\n1.\u00a0\u00a0\u00a0 8-bits signed and unsigned bytes\r\n\r\n&nbsp;\r\n\r\n2.\u00a0\u00a0\u00a0 16-bits signed and unsigned half-word, aligned on 2-byte boundaries\r\n\r\n&nbsp;\r\n\r\n3.\u00a0\u00a0\u00a0 32-bits signed and unsigned words, aligned on 4-byte boundaries\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\n<strong>1.4 ARM INSTRUCTION ENCODING<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">ARM instruction has a fixed length coding of 32 bits. Both the operation and the operands with its addressing mode are encoded within 32 bits. Figure 1.3 shows the encoding format for the different categories of instruction in ARM. The 4 MSB bitsindicate various conditions needed for the instruction execution. By default the instruction executes as always keeping the 4 bits as zeros. 8 bits are assigned for the operation representation and 4 bits each for the three operands.<\/p>\r\n\r\n<\/div>\r\n<span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0<img class=\"aligncenter size-full wp-image-344\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-199.png\" alt=\"\" width=\"683\" height=\"469\" \/><\/span>\r\n<div>\r\n\r\n&nbsp;\r\n\r\n<strong>Conditional Execution<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Most of the processor executes branch instruction conditionally. The status flags are verified to decide the flow of execution. However by reusing the condition evaluation hardware to all instruction, ARM effectively increases the performance and code density. Every instruction contains a condition field which determines whether the CPU will execute it. The Non-executed instruction will still take up 1 cycle and allow other stages in the pipeline to complete. The conditional execution reduces the number of branches which would stall the pipeline. The dense in-line code reduces the number of pipeline flushes. The time penalty of not executing several conditional instructions is frequently less than the overhead of the branch or instruction call that would otherwise be needed to be redone.<\/p>\r\n&nbsp;\r\n\r\n<strong>Condition mnemonics<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Conditional execution depends on two components: the condition field and the condition flags. As explained earlier the field is in the instruction. The condition flags are located in the current program status register (cpsr). The different conditions and the corresponding status flags used for verification are shown in Table 1.1.<\/p>\r\n\r\n<\/div>\r\n&nbsp;\r\n<div>\r\n\r\n<strong>Table 1.1Instruction condition and flags<\/strong>\r\n<table class=\"aligncenter\" style=\"width: 60%\" border=\"1\">\r\n<tbody>\r\n<tr>\r\n<td style=\"width: 73px\"><strong>Suffix<\/strong><\/td>\r\n<td style=\"width: 210px\"><strong>Description<\/strong><\/td>\r\n<td style=\"width: 111px\"><strong>Flags tested<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 73px\"><strong>EQ<\/strong><\/td>\r\n<td style=\"width: 210px\">Equal<\/td>\r\n<td style=\"width: 111px\"><strong>Z=1<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 73px\"><strong>NE<\/strong><\/td>\r\n<td style=\"width: 210px\">Not equal<\/td>\r\n<td style=\"width: 111px\"><strong>Z=0<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 73px\"><strong>CS\/HS<\/strong><\/td>\r\n<td style=\"width: 210px\">Unsigned higher or same<\/td>\r\n<td style=\"width: 111px\"><strong>C=1<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 73px\"><strong>CC\/LO<\/strong><\/td>\r\n<td style=\"width: 210px\">Unsigned lower<\/td>\r\n<td style=\"width: 111px\"><strong>C=0<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 73px\"><strong>MI<\/strong><\/td>\r\n<td style=\"width: 210px\">Minus<\/td>\r\n<td style=\"width: 111px\"><strong>N=1<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 73px\"><strong>PL<\/strong><\/td>\r\n<td style=\"width: 210px\">Positive or Zero<\/td>\r\n<td style=\"width: 111px\"><strong>N=0<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 73px\"><strong>VS<\/strong><\/td>\r\n<td style=\"width: 210px\">Overflow<\/td>\r\n<td style=\"width: 111px\"><strong>V=1<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 73px\"><strong>VC<\/strong><\/td>\r\n<td style=\"width: 210px\">No overflow<\/td>\r\n<td style=\"width: 111px\"><strong>V=0<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 73px\"><strong>HI<\/strong><\/td>\r\n<td style=\"width: 210px\">Unsigned higher<\/td>\r\n<td style=\"width: 111px\"><strong>C=1 &amp; Z=0<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 73px\"><strong>LS<\/strong><\/td>\r\n<td style=\"width: 210px\">Unsigned lower or same<\/td>\r\n<td style=\"width: 111px\"><strong>C=0 or Z=1<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 73px\"><strong>GE<\/strong><\/td>\r\n<td style=\"width: 210px\">Greater or equal<\/td>\r\n<td style=\"width: 111px\"><strong>N=V<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 73px\"><strong>LT<\/strong><\/td>\r\n<td style=\"width: 210px\">Less than<\/td>\r\n<td style=\"width: 111px\"><strong>N!=V<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 73px\"><strong>GT<\/strong><\/td>\r\n<td style=\"width: 210px\">Greater than<\/td>\r\n<td style=\"width: 111px\"><strong>Z=0 &amp; N=V<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 73px\"><strong>LE<\/strong><\/td>\r\n<td style=\"width: 210px\">Less than or equal<\/td>\r\n<td style=\"width: 111px\"><strong>Z=1 or N=!V<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td style=\"width: 73px\"><strong>AL<\/strong><\/td>\r\n<td style=\"width: 210px\">Always<\/td>\r\n<td style=\"width: 111px\"><\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n&nbsp;\r\n\r\n<strong>Using and Updating the Condition<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">To execute an instruction conditionally, we simply postfix it with the appropriate condition. Consider the example of add instruction which verifies the zero flag. For example, an add instruction takes the form<\/p>\r\n&nbsp;\r\n\r\nADD r0, r1, r2\u00a0\u00a0\u00a0\u00a0 ; r0 = r1 + r2 (ADDAL)\r\n\r\n&nbsp;\r\n\r\nTo execute this only if the zero flag is set, we use\r\n\r\n&nbsp;\r\n\r\nADDEQ r0, r1, r2\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ; r0 = r1 + r2 if zero flag set\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The flags are the reflection of the previous execution. By default, data processing operations do not affect the condition flags. The only instruction that updates the condition flags is \u2018<strong>compare\u2019<\/strong>. To cause the condition flags to be updated, the S bit of the instruction needs to be set by postfixing the instruction (and any condition codes) with an \u201cS\u201d.<\/p>\r\n&nbsp;\r\n\r\nFor example, to add two numbers and set the condition flags:\r\n\r\n&nbsp;\r\n\r\nADDS r0, r1, r2 ; r0 = r1 + r2 and set flags\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The conditional execution helps to reduce the number of instructions needed to write a program for a specific algorithm.<\/p>\r\n&nbsp;\r\n\r\n<strong>1.5 ARM INSTRUCTION TYPE<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The ARM instruction is a three operand format with two source registers(Rn&amp;Rm ) and one destination(Rd) register. The instruction syntax is \u201coperation&lt;Rd , Rn , Rm&gt;\u201d.The instructionsetis classified into the five categories listed below:<\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n\u00a0 \u00a0 1.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Data processing instructions\r\n\r\n&nbsp;\r\n\r\n2.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Control flow instructions Branch instruction\r\n\r\n&nbsp;\r\n\r\n3.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Data transfer instructions\r\n\r\n&nbsp;\r\n\r\nLoad-store instruction\r\n\r\n&nbsp;\r\n\r\n4.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Software Interrupt instruction\r\n\r\n&nbsp;\r\n\r\n5.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Program status register instruction\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\n<strong>1.5.1<\/strong>\u00a0\u00a0\u00a0\u00a0 <strong>Data Processing Instructions<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Data processing instructions are the ones that process, manipulate and compute the data available in registers. These instructions have three operands, except for the move instruction which has two operands. One of the source operand will be inregister; the second operand may be a register\/ shifted register or an immediate value. All operands are 32-bit wide; and they come from registers or are specified as literal in the instruction itself. One of its input operands is processed using barrel shifter and then sent to the ALU.The 32-bit result is placed in a register.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">A long multiply instruction produces a 64-bit result. Any register from the user set can be used as operand.The Program Counter (PC) may be used as a source operand (address of the instruction plus 8) except when a register shift amount is performed. In case of branch instruction PC may be specified as the destination register.<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">The status flags in cpsr are updated whenever the instruction are suffixed with \u2018S\u2019. It is the 20th bit in the 32 bits opcode of an instruction as shown in Figure 1.4. If S=0 the condition codes are unaffected. The suffix of S in the instruction turns S=1 and allows direct control of the condition codes with respect to the type of instruction executed. Following are the flags with the values they reflect based on the result of the instruction executed.<\/p>\r\n&nbsp;\r\n\r\n\u2013\u00a0\u00a0 N = 1 if the result is negative; 0 otherwise (i.e. N = bit 31 of the result)\r\n\r\n&nbsp;\r\n\r\n\u2013\u00a0\u00a0 Z = 1 if the result is zero; 0 otherwise\r\n\r\n&nbsp;\r\n\r\n\u2013 C = 1 carry out from the ALU when ADD, ADC, SUB, SBC, RSB, RSC, CMP, or CMN; carry out from the shifter\r\n\r\n&nbsp;\r\n\r\n\u2013 V = 1 if overflow from bit 30 to bit 31; 0 if no overflow(V is preserved in non-arithmetic operations)\r\n\r\n<\/div>\r\n<div>\r\n\r\n<img class=\"aligncenter size-full wp-image-345\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-200.png\" alt=\"\" width=\"556\" height=\"505\" \/>\r\n\r\n&nbsp;\r\n\r\nThe data processing instructions are grouped based on the operation it executes. Following are the five sets:\r\n\r\n&nbsp;\r\n\r\n1.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Arithmetic Instructions (ADD, ADC, SUB, SBC, RSB)\r\n\r\n&nbsp;\r\n\r\n2.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Logical Instructions(BIC, AND, ORR, EOR)\r\n\r\n&nbsp;\r\n\r\n3.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Compare Instructions (CMP, TST,CMN, TEQ)\r\n\r\n&nbsp;\r\n\r\n4.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Register movement Instructions (MOV, MVN)\r\n\r\n&nbsp;\r\n\r\n5.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Multiply Instructions (MLA, MUL)\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\n<strong>1.5.2\u00a0\u00a0\u00a0 Arithmetic Instructions<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\"><span style=\"font-size: 1em;text-align: initial\">The addition and subtraction operation on 32-bit signed and unsigned values are grouped under arithmetic instructions. The syntax of the instruction is:<\/span><\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n\u2013\u00a0 \u00a0&lt;Operation&gt;{&lt;cond&gt;}{S} Rd, Rn, Operand2\r\n\r\n&nbsp;\r\n\r\nThe Table 1.2 shows the six arithmetic operations with their mnemonic and explanation.\r\n\r\n&nbsp;\r\n\r\n<strong>Table 1.2Arithmetic Instructions<\/strong>\r\n\r\n&nbsp;\r\n\r\n<img class=\"aligncenter size-full wp-image-346\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-201.png\" alt=\"\" width=\"665\" height=\"269\" \/>\r\n<p style=\"text-align: justify\">The logical instructions perform bitwise logical operation on the two source registers. The syntax of logical instruction is: &lt;Operation&gt;{&lt;cond&gt;}{S} Rd, Rn, Operand2<\/p>\r\n&nbsp;\r\n\r\nThe Table 1.3 shows the four logical operations with their mnemonic and explanation.\r\n\r\n&nbsp;\r\n\r\n<strong>Table 1.3Logical Instructions<\/strong>\r\n<table class=\"aligncenter\" style=\"width: 60%\" border=\"1\">\r\n<tbody>\r\n<tr>\r\n<td>Mnemonic<\/td>\r\n<td>Operation<\/td>\r\n<td>Comment<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>AND r0,r1,r2<\/td>\r\n<td>r0:=r1&amp;r2<\/td>\r\n<td>And two 32-bit values<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>ORR r0,r1,r2<\/td>\r\n<td>r0:=r1|r2<\/td>\r\n<td>OR of two 32-bit values<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>EOR r0,r1,r2<\/td>\r\n<td>r0:=r1^r2<\/td>\r\n<td>Exclusive OR of two 32-bit values<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>BIC r0,r1,r2<\/td>\r\n<td>r0:=r1&amp; ~r2<\/td>\r\n<td>Logical bit clear AND NOT<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n&nbsp;\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The AND, OR and Ex-OR are trivial logical operations. Let us consider the execution of BIC instruction. Assume, pre-execution nibble values for simplicity. Let r1=0b1111 and r2= 0b1010. Post execution of the instruction BIC r0, r1,r2;<\/p>\r\n&nbsp;\r\n<p style=\"text-align: justify\">r0= 0b0101. The implication of the result is that every binary one in r2 register clears a corresponding bit location in r0 register.<\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n&nbsp;\r\n\r\n<strong>1.5.4<\/strong>\u00a0\u00a0\u00a0\u00a0 <strong>Register Movement Operations<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Move instruction copies source content into the destination location. It omits the 1st source operand from the format. This instruction is used to initialize data into the special function register and copy values between registers. The syntax of the instruction is &lt;Operation&gt;{&lt;cond&gt;}{S} Rd, Operand2<\/p>\r\n&nbsp;\r\n\r\nThe Table 1.4 shows the two transfer operations with their mnemonic and explanation.\r\n\r\n&nbsp;\r\n\r\n<strong>Table 1.4Move Instructions<\/strong>\r\n<table class=\"aligncenter\" style=\"width: 60%\" border=\"1\">\r\n<tbody>\r\n<tr>\r\n<td>Mnemonic<\/td>\r\n<td>Operation<\/td>\r\n<td>Comment<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>MOV r0,r2<\/td>\r\n<td>r0:=r2<\/td>\r\n<td>move 32-bit value into a register<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>MVN r0,r2<\/td>\r\n<td>r0:=~r2<\/td>\r\n<td>move the complement of 32-bit<\/td>\r\n<\/tr>\r\n<tr>\r\n<td><\/td>\r\n<td><\/td>\r\n<td>value into a register<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\nExamples :\r\n\r\n&nbsp;\r\n\r\n\u2013\u00a0\u00a0 MOVS r2, r3\/\/ transfer data from r3 to r2\r\n\r\n&nbsp;\r\n\r\n\u2013\u00a0\u00a0\u00a0\u00a0 MVNEQ r1, r2\u00a0 \/\/negates the r2 value and then transfers it to r1\r\n\r\n&nbsp;\r\n\r\n<strong>1.5.5<\/strong>\u00a0\u00a0\u00a0\u00a0 <strong>Comparison Operations<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Compare instruction is used to compare or test a 32 bit value.The execution of these instructions affects the status flags without affecting the operands. It just sets the Condition Code(CC) bits (N, Z, C and V) in CPSR. The outcome of this instruction is used to change the flow of a program execution. These instructions affect the flag without the suffix of the S bit. Since it does not produce any result; the destination filed is omitted from the format. The syntax of the instruction is<\/p>\r\n&lt;Operation&gt;{&lt;cond&gt;} Rn, Operand2\r\n\r\n&nbsp;\r\n\r\nThe Table 1.5 shows the four comparison operations with their mnemonic and explanation.\r\n\r\n&nbsp;\r\n\r\n<strong>Table 1.5Comparison Instructions<\/strong>\r\n<table class=\"aligncenter\" style=\"width: 60%\" border=\"1\">\r\n<tbody>\r\n<tr>\r\n<td>Mnemonic<\/td>\r\n<td>Operation<\/td>\r\n<td>Comment<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>CMPr1,r2<\/td>\r\n<td>r1-r2<\/td>\r\n<td>Compare two 32-bit values<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>CMNr1,r2<\/td>\r\n<td>r1-(-r2)<\/td>\r\n<td>Compare negated<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>TSTr1,r2<\/td>\r\n<td>r0:=r1&amp;r2<\/td>\r\n<td>Test bits of a 32-bit values<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>TEQr1,r2<\/td>\r\n<td>r0:=r1^r2<\/td>\r\n<td>Test for equality of two 32bits<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n<\/div>\r\n&nbsp;\r\n<div>\r\n\r\n<strong>1.5.6\u00a0\u00a0\u00a0 Immediate operands<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Immediate addressing mode puts the raw 32 bits as one of the operands. It replaces the second source operand with an immediate value, which is a literal constant, preceded by \u201c#\u201d. Consider the two examples containing immediate operands.<\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\nADD r3,r3,#1 ;r3:=r3+1\r\n\r\n<\/div>\r\n<span style=\"text-align: initial;font-size: 1em\">AND r8,r7,#&amp;FF\u00a0<\/span><span style=\"text-align: initial;font-size: 1em\">;r8:=r7[7:0], &amp;:hexadecimal<\/span>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">Since the immediate value is coded within the 32 bits of the instruction, it is not possible to enter every possible 32-bit value as an immediate. The bit layout Figure 1.4 shows only 12 bits are allowed for immediate value. Keeping 12 bits, the maximum value could be 4096. To accommodate larger value 8 bits are allocated to describe the base value and 4 bits are used for the rotate. Different ranges of data can be written by varying the n(4 bits). Following are few examples of varying n which leads to different immediate values. This can be even achieved by rotate right operation with the help of the barrel shifter. The following are a few examples of the values of immediate data obtained for rotation of different values of n. The first number shows the range for 8 bit number without rotation. The second row shows the range of values for n=1, where the rotation is in steps of four. Likewise is the next two rows with n=2 and n=3, with rotation in steps of 16 and 64.<\/span><\/p>\r\n\r\n<div>\r\n\r\nImmediate = (0 \u2192 255) \u00d7 22<em>n<\/em> where 0&lt;=n&lt;=12\r\n<table class=\"aligncenter\" style=\"width: 60%\" border=\"1\">\r\n<tbody>\r\n<tr>\r\n<td>\u2013<\/td>\r\n<td>0 - 255<\/td>\r\n<td>[0 - 0xff]<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>\u2013<\/td>\r\n<td>256,260,264,..,1020<\/td>\r\n<td>[0x100-0x3fc, step 4, 0x40-0xff ror 30]<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>\u2013<\/td>\r\n<td>1024,1040,1056,..,4080<\/td>\r\n<td>[0x400-0xff0, step 16, 0x40-0xff ror 28]<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n\u2013\u00a0\u00a0 4096,4160, 4224,..,16320[0x1000-0x3fc0, step 64, 0x40-0xff ror 26]\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Following are few examples for loading immediate value. For example consider the immediate value of 4096(decimal) or 1000(Hex):<\/p>\r\n&nbsp;\r\n\r\n\u2013\u00a0\u00a0\u00a0\u00a0 MOV r0, #0x40,26\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ; =&gt; MOV r0, #0x1000\u00a0\u00a0\u00a0 (ie 4096)\r\n\r\n&nbsp;\r\n\r\nThe assembler will convert the required constant of hex or decimal into the rotate format:\r\n\r\n&nbsp;\r\n\r\n\u2013\u00a0\u00a0\u00a0\u00a0 MOV r0, #4096\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ; =&gt; MOV r0, #0x1000\u00a0\u00a0\u00a0 (ie 0x40 ror 26)\r\n\r\n&nbsp;\r\n\r\nOn a similar concept, the bitwise complements can also be formed using MVN as shown in the example below:\r\n\r\n&nbsp;\r\n\r\n\u2013\u00a0\u00a0\u00a0\u00a0 MOV r0, #0xFFFFFFFF\u00a0\u00a0\u00a0 ; assembles to MVN r0, #0\r\n\r\n&nbsp;\r\n\r\nIn case the required constant cannot be generated, an error will be reported by the processor.\r\n\r\n<\/div>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">To summarize ARM instruction cannot load a 32-bit immediate constant directly into a register. ARM instructions are encoded using 32-bits and only 12 bits are allocated for immediate values. The data processing instruction format has 12 bits available for operand 2. If used directly, this would only give a range of 4096. Instead it is used to store 8-bit constants, giving a range of 0-255. These 8 bits can then be rotated right through an even number of positions. This gives a much larger range of constants that can be directly loaded, though some constants will still need to be loaded from memory.<\/span><\/p>\r\n\r\n<div>\r\n\r\n&nbsp;\r\n\r\n<strong>1.5.6.1 Logical and Arithmetic shift operands<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">Before executing an instruction in the ALU, ARM has the capability to preprocess the data in one of the operand with the help of barrel shifter. In general each instruction is executed in a single cycle. Consider the ADD example given below, where the r1 register is shifted 3 bits left prior to addition.<\/p>\r\n&nbsp;\r\n\r\nADD r3,r2,r1,LSL#3\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ; r3 := r2 + 8 * r1\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The barrel shifter implements five types of shift operations shown in Figure 1.5. The LSL: Logical Shift Left shift bits left by 0 to 31 places, 0 filled at the LSB end. On similar lines we have LSR, ASL (Arithmetic Shift Left), ASR, ROR (Rotate Right), RRX (Rotate Right eXtended by 1 place). Consider the two examples of LSL and ROR where a register is used to define the amount of shift. Each left shift is equivalent to multiplying the operand by 2. Hence the r3,LSL r2 (left shift r2 times)is equivalent tor3*2<strong>r2.<\/strong><\/p>\r\n&nbsp;\r\n\r\nADD r5,r5,r3,LSL r2 ; r5:=r5+r3*2<strong>r2<\/strong>\r\n\r\n&nbsp;\r\n\r\nMOV r12,r4,ROR r3\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ;r12:=r4 rotated right by value of r3\r\n\r\n<\/div>\r\n<div>\r\n\r\n<img class=\"aligncenter size-full wp-image-347\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-202.png\" alt=\"\" width=\"635\" height=\"473\" \/>\r\n\r\n&nbsp;\r\n\r\n<strong>1.5.6.2 Barrel Shifter<\/strong>\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The second operand is the one that passes through the barrel shifter. Figure 1.6 shows the connection of barrel shifter and ALU in ARM processor. The barrel shifter has the ability to shift 32bits right or left by specific number of positions. Register uses the shift operation optionally. The Shift value can be either5-bit unsigned integer or specified in bottom byte of another register. The shift operation is also used for multiplication by constant. We had earlier discussed about immediate value, where the 8-bit number, with a range of 0 \u2013 255 is rotated right through even number of positions. This preprocessing allows increased range of 32-bit constants that can be loaded directly into registers. Thus barrel shifter brings in a unique and powerful feature for ARM processor.<\/p>\r\n\r\n<\/div>\r\n<div>\r\n\r\n<img class=\"aligncenter size-full wp-image-348\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-203.png\" alt=\"\" width=\"490\" height=\"237\" \/>\r\n\r\n<strong>1.5.7<\/strong>\u00a0\u00a0\u00a0\u00a0 <strong>Multiply Instructions<\/strong>\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">The multiply instruction multiplies the pair of registersRm,Rs(MUL) and occasionally accumulates the product with register Rn (MLA). The final result is stored in register or a pair of registers. The syntax of both the instructions is given below:<\/p>\r\n&nbsp;\r\n\r\n\u2013\u00a0\u00a0 MUL{&lt;cond&gt;}{S} Rd,Rm,Rs\r\n\r\n&nbsp;\r\n\r\n\u2013\u00a0\u00a0 MLA{&lt;cond&gt;}{S} Rd,Rm,Rs,Rn\r\n\r\n&nbsp;\r\n<table class=\"aligncenter\" style=\"width: 60%\" border=\"1\">\r\n<tbody>\r\n<tr>\r\n<td>MUL r4,r3,r2;<\/td>\r\n<td>r4:=(r3*r2)[31:0]<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>MLA r4,r3,r2,r1;<\/td>\r\n<td>r4:=((r3*r2)+r1)[31:0]<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n&nbsp;\r\n<p style=\"text-align: justify\">Table 1.6 shows the six types of multiplication instructions. The syntax for 64-bit multiplication with signed and unsigned register is listed below:<\/p>\r\n&nbsp;\r\n\r\n\u2013\u00a0\u00a0 &lt;mul&gt;{&lt;cond&gt;}{S} RdHi,RdLo,Rm,Rs\r\n\r\n&nbsp;\r\n\r\n\u2013\u00a0\u00a0 &lt;mul&gt; is UMULL,UMLAL,SMULL,SMLAL\r\n<table class=\"aligncenter\" style=\"width: 60%\" border=\"1\">\r\n<tbody>\r\n<tr>\r\n<td><\/td>\r\n<td><\/td>\r\n<td><strong>Table 1.5Multiply Instructions<\/strong><\/td>\r\n<td><\/td>\r\n<\/tr>\r\n<tr>\r\n<td><strong>Opco de<\/strong><\/td>\r\n<td><strong>Mnemo ni c<\/strong><\/td>\r\n<td><strong>Meani ng<\/strong><\/td>\r\n<td><strong>Effect<\/strong><\/td>\r\n<\/tr>\r\n<tr>\r\n<td><strong>[2 3 :2 1 ]<\/strong><\/td>\r\n<td><\/td>\r\n<td><\/td>\r\n<td><\/td>\r\n<\/tr>\r\n<tr>\r\n<td>000<\/td>\r\n<td>MUL<\/td>\r\n<td>Multiply (32-bit result)<\/td>\r\n<td>Rd := (Rm * Rs) [31:0]<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>001<\/td>\r\n<td>MLA<\/td>\r\n<td>Multiply-accumulate (32-bit result)<\/td>\r\n<td>Rd := (Rm * Rs + Rn) [31:0]<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>100<\/td>\r\n<td>UMULL<\/td>\r\n<td>Unsigned multiply long<\/td>\r\n<td>RdHi:RdLo := Rm * Rs<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>101<\/td>\r\n<td>UMLAL<\/td>\r\n<td>Unsigned multiply-accumulate long<\/td>\r\n<td>RdHi:RdLo += Rm * Rs<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>110<\/td>\r\n<td>SMULL<\/td>\r\n<td>Signed multiply long<\/td>\r\n<td>RdHi:RdLo := Rm * Rs<\/td>\r\n<\/tr>\r\n<tr>\r\n<td>111<\/td>\r\n<td>SMLAL<\/td>\r\n<td>Signed multiply-accumulate long<\/td>\r\n<td>RdHi:RdLo += Rm * Rs<\/td>\r\n<\/tr>\r\n<\/tbody>\r\n<\/table>\r\n&nbsp;\r\n<p style=\"text-align: justify\"><strong>Booth\u2019s algorithm <\/strong>is used to perform integer multiplication. Booth\u2019s recoding basically looks into the transition of 1 to 0 and 0 to 1 in the binary pattern of the register (multiplier). ARM7TDMI <em>Mul<\/em> will execute in minimum of 2 clock cycles and maximum of 5 clock cycles. There are a few restrictions on the use of registers for this operation:<\/p>\r\n&nbsp;\r\n\r\n1. Rd and Rm cannot be the same register (can be avoided by swapping over Rm and Rs \u2013 multiplication is commutative)\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">2. Cannot use PC\u00a0<span style=\"text-align: initial;font-size: 1em\">Multiplication by a constant equal to a ((power of 2) +\/- 1) can be done in a single cycleusing MOV, ADD or RSB with an inline shift. We can also combine several instructions to carry out other multiplications. The table 1.7 shows the different variants of MUL implementation.<\/span><\/p>\r\n\r\n<\/div>\r\n&nbsp;\r\n\r\n<img class=\"aligncenter size-full wp-image-349\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-204.png\" alt=\"\" width=\"694\" height=\"169\" \/>\r\n\r\n&nbsp;\r\n\r\n<strong>1.6 Summary<\/strong>\r\n\r\n&nbsp;\r\n\r\n&nbsp;\r\n<p style=\"text-align: justify\">In this lecture we have discussed ARM Instructions set format and classification of instruction set. A detailed discussion on data processing instruction with examples and syntax was explored. We studied the impact made by barrel shifter on data pre-processing.<\/p>\r\n&nbsp;\r\n\r\n&nbsp;\r\n\r\n<strong>2. References<\/strong>\r\n<ol>\r\n \t<li><em><a href=\"http:\/\/www.arm.com\/\">www.<strong>arm<\/strong>.com<\/a><\/em><\/li>\r\n \t<li><em>en.wikipedia.org\/wiki\/<strong>ARM<\/strong>_architecture<\/em><\/li>\r\n \t<li>Andrew N Sloss, D. Symes, C. Wright, \u201d Arm system developers guide\u201d, Morgan Kauffman\/ Elsevier, 2006.<\/li>\r\n<\/ol>","rendered":"<div>\n<p><strong>About the module:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Thismodule aims at exploring ARM instruction set to design an embedded application. The core part of any program will always consist of arithmetic and logical operations. In this module,we start with Instruction set classification, diving into details of data processing instructions and the representation of data.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Learning Outcomes:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li>Able to understand the nuances of ARM programming.<\/li>\n<li>Should be able to write an ARM program incorporating the arithmetic and logicalinstruction.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><strong>1.1 <\/strong><strong>ARM ISA Features<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">ARM is a RISC based processor with LoadStore architecture. Load and store instructions are the memory access instructions. The load instruction reads data from memory address space and store instruction writes into it.The ALU operations are performed on the values that are stored in the register file. Except for load and store, all the other categories of instruction access data from the registers. Few features of ARM ISA are listed below.<\/p>\n<p>&nbsp;<\/p>\n<p>Fixed-length 32-bit instructions. 3-address instruction formats.<\/p>\n<p>&nbsp;<\/p>\n<p>Load and store multiple registers.<\/p>\n<p>&nbsp;<\/p>\n<p>Shift and ALU operationsare performed in a single instruction.<\/p>\n<p>&nbsp;<\/p>\n<p>Open instruction set extension through the coprocessor instruction. Very dense 16-bit compressed instruction set (Thumb).<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>1.1.1<\/strong>\u00a0\u00a0\u00a0\u00a0 <strong>Coprocessor<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>One of the additional feature of ARM is the coprocessor extension.<\/p>\n<\/div>\n<div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-342\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-197.png\" alt=\"\" width=\"588\" height=\"415\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-197.png 588w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-197-300x212.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-197-65x46.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-197-225x159.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-197-350x247.png 350w\" sizes=\"auto, (max-width: 588px) 100vw, 588px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">ARM can be interfaced with another processor which expands the functionality of the ARM (Figure 1.1).Up to sixteen coprocessors can be defined and interfaced with ARM. The coprocessor interface expands the ARM instruction set. In the decode stage if the processor identifies the coprocessor instruction, it hands it over to the relevant coprocessor; otherwise it raises an undefined instruction exception. ARM has instructions to access registers in the coprocessor. Each coprocessor can have up to sixteen private registers of any reasonable size.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>1.2 <\/strong><strong>ARM INSTRUCTION SET<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Instruction set is the neural schema of any processor which enables any embedded programmer to understand and utilize a processor. In general, the ARM processor classifies its instruction set into two categories: 1. ARM instruction set and 2. Thumb instruction set. The ARM instructions are 32-bits(word) wide and word-aligned.Thumb instructions are 16 bits(half-word) or 32-bits (word) wide.It is aligned on 2 byte(8bits = 1 byte)or 4 byte(word) boundaries. The Thumb is the subset of ARM and most of its operation maps to the ARM instruction set. The thumb set was introduced to reduce the code size. The processor can execute either the Arm instruction or the Thumb instruction by switching the T bit in the status register CPSR. If the T-bit is set, the processor is in Thumb state and executes Thumb instructions. If the T-bit is reset, the processor is said be in ARM state. Most of the privileged resources are accessed by ARM instructions. The processor executes exception handlers always in the ARM state.We start with exploring the ARM instruction set.Figure 1.2 shows the format of ARM instruction. The instruction is of three address format. An example mnemonic ADD d1,s1,s2 performs addition on source operand s1 and s2 and stores the result in destination d1. The 32 bits are divided\u00a0<span style=\"font-size: 1em;text-align: initial\">among the function(operation) to be performed and the addresses of three operands. The number of bits allocated for addressing operands depends on the addressing mode. For example, if the operands use register addressing mode, we need four bits to address individual operands.<\/span><\/p>\n<\/div>\n<div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-343\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-198.png\" alt=\"\" width=\"621\" height=\"186\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-198.png 621w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-198-300x90.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-198-65x19.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-198-225x67.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-198-350x105.png 350w\" sizes=\"auto, (max-width: 621px) 100vw, 621px\" \/><\/p>\n<p><strong>1.3 ARM DATA TYPES<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">To understand the ARM instruction set, we list the different data sizes the ARM processor supports. Based on the sizes there are six datatypes. Largely speaking, the data is processed in word, half-word and bytes. By default the instruction processes the operand with a word size. The instructions are appended with alphabet \u2018b\u2019 and \u2018h\u2019 to indicate the data size of byte and half word. Each data size can have signed or an unsigned representation. Following are the categories of data types used in the ARM ISA:<\/p>\n<p>&nbsp;<\/p>\n<p>1.\u00a0\u00a0\u00a0 8-bits signed and unsigned bytes<\/p>\n<p>&nbsp;<\/p>\n<p>2.\u00a0\u00a0\u00a0 16-bits signed and unsigned half-word, aligned on 2-byte boundaries<\/p>\n<p>&nbsp;<\/p>\n<p>3.\u00a0\u00a0\u00a0 32-bits signed and unsigned words, aligned on 4-byte boundaries<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>1.4 ARM INSTRUCTION ENCODING<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">ARM instruction has a fixed length coding of 32 bits. Both the operation and the operands with its addressing mode are encoded within 32 bits. Figure 1.3 shows the encoding format for the different categories of instruction in ARM. The 4 MSB bitsindicate various conditions needed for the instruction execution. By default the instruction executes as always keeping the 4 bits as zeros. 8 bits are assigned for the operation representation and 4 bits each for the three operands.<\/p>\n<\/div>\n<p><span style=\"text-align: initial;font-size: 1em\">\u00a0 \u00a0<img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-344\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-199.png\" alt=\"\" width=\"683\" height=\"469\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-199.png 683w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-199-300x206.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-199-65x45.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-199-225x155.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-199-350x240.png 350w\" sizes=\"auto, (max-width: 683px) 100vw, 683px\" \/><\/span><\/p>\n<div>\n<p>&nbsp;<\/p>\n<p><strong>Conditional Execution<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Most of the processor executes branch instruction conditionally. The status flags are verified to decide the flow of execution. However by reusing the condition evaluation hardware to all instruction, ARM effectively increases the performance and code density. Every instruction contains a condition field which determines whether the CPU will execute it. The Non-executed instruction will still take up 1 cycle and allow other stages in the pipeline to complete. The conditional execution reduces the number of branches which would stall the pipeline. The dense in-line code reduces the number of pipeline flushes. The time penalty of not executing several conditional instructions is frequently less than the overhead of the branch or instruction call that would otherwise be needed to be redone.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Condition mnemonics<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Conditional execution depends on two components: the condition field and the condition flags. As explained earlier the field is in the instruction. The condition flags are located in the current program status register (cpsr). The different conditions and the corresponding status flags used for verification are shown in Table 1.1.<\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<div>\n<p><strong>Table 1.1Instruction condition and flags<\/strong><\/p>\n<table class=\"aligncenter\" style=\"width: 60%\">\n<tbody>\n<tr>\n<td style=\"width: 73px\"><strong>Suffix<\/strong><\/td>\n<td style=\"width: 210px\"><strong>Description<\/strong><\/td>\n<td style=\"width: 111px\"><strong>Flags tested<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 73px\"><strong>EQ<\/strong><\/td>\n<td style=\"width: 210px\">Equal<\/td>\n<td style=\"width: 111px\"><strong>Z=1<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 73px\"><strong>NE<\/strong><\/td>\n<td style=\"width: 210px\">Not equal<\/td>\n<td style=\"width: 111px\"><strong>Z=0<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 73px\"><strong>CS\/HS<\/strong><\/td>\n<td style=\"width: 210px\">Unsigned higher or same<\/td>\n<td style=\"width: 111px\"><strong>C=1<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 73px\"><strong>CC\/LO<\/strong><\/td>\n<td style=\"width: 210px\">Unsigned lower<\/td>\n<td style=\"width: 111px\"><strong>C=0<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 73px\"><strong>MI<\/strong><\/td>\n<td style=\"width: 210px\">Minus<\/td>\n<td style=\"width: 111px\"><strong>N=1<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 73px\"><strong>PL<\/strong><\/td>\n<td style=\"width: 210px\">Positive or Zero<\/td>\n<td style=\"width: 111px\"><strong>N=0<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 73px\"><strong>VS<\/strong><\/td>\n<td style=\"width: 210px\">Overflow<\/td>\n<td style=\"width: 111px\"><strong>V=1<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 73px\"><strong>VC<\/strong><\/td>\n<td style=\"width: 210px\">No overflow<\/td>\n<td style=\"width: 111px\"><strong>V=0<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 73px\"><strong>HI<\/strong><\/td>\n<td style=\"width: 210px\">Unsigned higher<\/td>\n<td style=\"width: 111px\"><strong>C=1 &amp; Z=0<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 73px\"><strong>LS<\/strong><\/td>\n<td style=\"width: 210px\">Unsigned lower or same<\/td>\n<td style=\"width: 111px\"><strong>C=0 or Z=1<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 73px\"><strong>GE<\/strong><\/td>\n<td style=\"width: 210px\">Greater or equal<\/td>\n<td style=\"width: 111px\"><strong>N=V<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 73px\"><strong>LT<\/strong><\/td>\n<td style=\"width: 210px\">Less than<\/td>\n<td style=\"width: 111px\"><strong>N!=V<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 73px\"><strong>GT<\/strong><\/td>\n<td style=\"width: 210px\">Greater than<\/td>\n<td style=\"width: 111px\"><strong>Z=0 &amp; N=V<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 73px\"><strong>LE<\/strong><\/td>\n<td style=\"width: 210px\">Less than or equal<\/td>\n<td style=\"width: 111px\"><strong>Z=1 or N=!V<\/strong><\/td>\n<\/tr>\n<tr>\n<td style=\"width: 73px\"><strong>AL<\/strong><\/td>\n<td style=\"width: 210px\">Always<\/td>\n<td style=\"width: 111px\"><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p><strong>Using and Updating the Condition<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">To execute an instruction conditionally, we simply postfix it with the appropriate condition. Consider the example of add instruction which verifies the zero flag. For example, an add instruction takes the form<\/p>\n<p>&nbsp;<\/p>\n<p>ADD r0, r1, r2\u00a0\u00a0\u00a0\u00a0 ; r0 = r1 + r2 (ADDAL)<\/p>\n<p>&nbsp;<\/p>\n<p>To execute this only if the zero flag is set, we use<\/p>\n<p>&nbsp;<\/p>\n<p>ADDEQ r0, r1, r2\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ; r0 = r1 + r2 if zero flag set<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The flags are the reflection of the previous execution. By default, data processing operations do not affect the condition flags. The only instruction that updates the condition flags is \u2018<strong>compare\u2019<\/strong>. To cause the condition flags to be updated, the S bit of the instruction needs to be set by postfixing the instruction (and any condition codes) with an \u201cS\u201d.<\/p>\n<p>&nbsp;<\/p>\n<p>For example, to add two numbers and set the condition flags:<\/p>\n<p>&nbsp;<\/p>\n<p>ADDS r0, r1, r2 ; r0 = r1 + r2 and set flags<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The conditional execution helps to reduce the number of instructions needed to write a program for a specific algorithm.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>1.5 ARM INSTRUCTION TYPE<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The ARM instruction is a three operand format with two source registers(Rn&amp;Rm ) and one destination(Rd) register. The instruction syntax is \u201coperation&lt;Rd , Rn , Rm&gt;\u201d.The instructionsetis classified into the five categories listed below:<\/p>\n<\/div>\n<div>\n<p>\u00a0 \u00a0 1.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Data processing instructions<\/p>\n<p>&nbsp;<\/p>\n<p>2.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Control flow instructions Branch instruction<\/p>\n<p>&nbsp;<\/p>\n<p>3.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Data transfer instructions<\/p>\n<p>&nbsp;<\/p>\n<p>Load-store instruction<\/p>\n<p>&nbsp;<\/p>\n<p>4.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Software Interrupt instruction<\/p>\n<p>&nbsp;<\/p>\n<p>5.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Program status register instruction<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>1.5.1<\/strong>\u00a0\u00a0\u00a0\u00a0 <strong>Data Processing Instructions<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Data processing instructions are the ones that process, manipulate and compute the data available in registers. These instructions have three operands, except for the move instruction which has two operands. One of the source operand will be inregister; the second operand may be a register\/ shifted register or an immediate value. All operands are 32-bit wide; and they come from registers or are specified as literal in the instruction itself. One of its input operands is processed using barrel shifter and then sent to the ALU.The 32-bit result is placed in a register.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">A long multiply instruction produces a 64-bit result. Any register from the user set can be used as operand.The Program Counter (PC) may be used as a source operand (address of the instruction plus 8) except when a register shift amount is performed. In case of branch instruction PC may be specified as the destination register.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The status flags in cpsr are updated whenever the instruction are suffixed with \u2018S\u2019. It is the 20th bit in the 32 bits opcode of an instruction as shown in Figure 1.4. If S=0 the condition codes are unaffected. The suffix of S in the instruction turns S=1 and allows direct control of the condition codes with respect to the type of instruction executed. Following are the flags with the values they reflect based on the result of the instruction executed.<\/p>\n<p>&nbsp;<\/p>\n<p>\u2013\u00a0\u00a0 N = 1 if the result is negative; 0 otherwise (i.e. N = bit 31 of the result)<\/p>\n<p>&nbsp;<\/p>\n<p>\u2013\u00a0\u00a0 Z = 1 if the result is zero; 0 otherwise<\/p>\n<p>&nbsp;<\/p>\n<p>\u2013 C = 1 carry out from the ALU when ADD, ADC, SUB, SBC, RSB, RSC, CMP, or CMN; carry out from the shifter<\/p>\n<p>&nbsp;<\/p>\n<p>\u2013 V = 1 if overflow from bit 30 to bit 31; 0 if no overflow(V is preserved in non-arithmetic operations)<\/p>\n<\/div>\n<div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-345\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-200.png\" alt=\"\" width=\"556\" height=\"505\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-200.png 556w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-200-300x272.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-200-65x59.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-200-225x204.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-200-350x318.png 350w\" sizes=\"auto, (max-width: 556px) 100vw, 556px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>The data processing instructions are grouped based on the operation it executes. Following are the five sets:<\/p>\n<p>&nbsp;<\/p>\n<p>1.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Arithmetic Instructions (ADD, ADC, SUB, SBC, RSB)<\/p>\n<p>&nbsp;<\/p>\n<p>2.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Logical Instructions(BIC, AND, ORR, EOR)<\/p>\n<p>&nbsp;<\/p>\n<p>3.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Compare Instructions (CMP, TST,CMN, TEQ)<\/p>\n<p>&nbsp;<\/p>\n<p>4.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Register movement Instructions (MOV, MVN)<\/p>\n<p>&nbsp;<\/p>\n<p>5.\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Multiply Instructions (MLA, MUL)<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>1.5.2\u00a0\u00a0\u00a0 Arithmetic Instructions<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><span style=\"font-size: 1em;text-align: initial\">The addition and subtraction operation on 32-bit signed and unsigned values are grouped under arithmetic instructions. The syntax of the instruction is:<\/span><\/p>\n<\/div>\n<div>\n<p>\u2013\u00a0 \u00a0&lt;Operation&gt;{&lt;cond&gt;}{S} Rd, Rn, Operand2<\/p>\n<p>&nbsp;<\/p>\n<p>The Table 1.2 shows the six arithmetic operations with their mnemonic and explanation.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Table 1.2Arithmetic Instructions<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-346\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-201.png\" alt=\"\" width=\"665\" height=\"269\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-201.png 665w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-201-300x121.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-201-65x26.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-201-225x91.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-201-350x142.png 350w\" sizes=\"auto, (max-width: 665px) 100vw, 665px\" \/><\/p>\n<p style=\"text-align: justify\">The logical instructions perform bitwise logical operation on the two source registers. The syntax of logical instruction is: &lt;Operation&gt;{&lt;cond&gt;}{S} Rd, Rn, Operand2<\/p>\n<p>&nbsp;<\/p>\n<p>The Table 1.3 shows the four logical operations with their mnemonic and explanation.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Table 1.3Logical Instructions<\/strong><\/p>\n<table class=\"aligncenter\" style=\"width: 60%\">\n<tbody>\n<tr>\n<td>Mnemonic<\/td>\n<td>Operation<\/td>\n<td>Comment<\/td>\n<\/tr>\n<tr>\n<td>AND r0,r1,r2<\/td>\n<td>r0:=r1&amp;r2<\/td>\n<td>And two 32-bit values<\/td>\n<\/tr>\n<tr>\n<td>ORR r0,r1,r2<\/td>\n<td>r0:=r1|r2<\/td>\n<td>OR of two 32-bit values<\/td>\n<\/tr>\n<tr>\n<td>EOR r0,r1,r2<\/td>\n<td>r0:=r1^r2<\/td>\n<td>Exclusive OR of two 32-bit values<\/td>\n<\/tr>\n<tr>\n<td>BIC r0,r1,r2<\/td>\n<td>r0:=r1&amp; ~r2<\/td>\n<td>Logical bit clear AND NOT<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The AND, OR and Ex-OR are trivial logical operations. Let us consider the execution of BIC instruction. Assume, pre-execution nibble values for simplicity. Let r1=0b1111 and r2= 0b1010. Post execution of the instruction BIC r0, r1,r2;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">r0= 0b0101. The implication of the result is that every binary one in r2 register clears a corresponding bit location in r0 register.<\/p>\n<\/div>\n<div>\n<p>&nbsp;<\/p>\n<p><strong>1.5.4<\/strong>\u00a0\u00a0\u00a0\u00a0 <strong>Register Movement Operations<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Move instruction copies source content into the destination location. It omits the 1st source operand from the format. This instruction is used to initialize data into the special function register and copy values between registers. The syntax of the instruction is &lt;Operation&gt;{&lt;cond&gt;}{S} Rd, Operand2<\/p>\n<p>&nbsp;<\/p>\n<p>The Table 1.4 shows the two transfer operations with their mnemonic and explanation.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Table 1.4Move Instructions<\/strong><\/p>\n<table class=\"aligncenter\" style=\"width: 60%\">\n<tbody>\n<tr>\n<td>Mnemonic<\/td>\n<td>Operation<\/td>\n<td>Comment<\/td>\n<\/tr>\n<tr>\n<td>MOV r0,r2<\/td>\n<td>r0:=r2<\/td>\n<td>move 32-bit value into a register<\/td>\n<\/tr>\n<tr>\n<td>MVN r0,r2<\/td>\n<td>r0:=~r2<\/td>\n<td>move the complement of 32-bit<\/td>\n<\/tr>\n<tr>\n<td><\/td>\n<td><\/td>\n<td>value into a register<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Examples :<\/p>\n<p>&nbsp;<\/p>\n<p>\u2013\u00a0\u00a0 MOVS r2, r3\/\/ transfer data from r3 to r2<\/p>\n<p>&nbsp;<\/p>\n<p>\u2013\u00a0\u00a0\u00a0\u00a0 MVNEQ r1, r2\u00a0 \/\/negates the r2 value and then transfers it to r1<\/p>\n<p>&nbsp;<\/p>\n<p><strong>1.5.5<\/strong>\u00a0\u00a0\u00a0\u00a0 <strong>Comparison Operations<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Compare instruction is used to compare or test a 32 bit value.The execution of these instructions affects the status flags without affecting the operands. It just sets the Condition Code(CC) bits (N, Z, C and V) in CPSR. The outcome of this instruction is used to change the flow of a program execution. These instructions affect the flag without the suffix of the S bit. Since it does not produce any result; the destination filed is omitted from the format. The syntax of the instruction is<\/p>\n<p>&lt;Operation&gt;{&lt;cond&gt;} Rn, Operand2<\/p>\n<p>&nbsp;<\/p>\n<p>The Table 1.5 shows the four comparison operations with their mnemonic and explanation.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Table 1.5Comparison Instructions<\/strong><\/p>\n<table class=\"aligncenter\" style=\"width: 60%\">\n<tbody>\n<tr>\n<td>Mnemonic<\/td>\n<td>Operation<\/td>\n<td>Comment<\/td>\n<\/tr>\n<tr>\n<td>CMPr1,r2<\/td>\n<td>r1-r2<\/td>\n<td>Compare two 32-bit values<\/td>\n<\/tr>\n<tr>\n<td>CMNr1,r2<\/td>\n<td>r1-(-r2)<\/td>\n<td>Compare negated<\/td>\n<\/tr>\n<tr>\n<td>TSTr1,r2<\/td>\n<td>r0:=r1&amp;r2<\/td>\n<td>Test bits of a 32-bit values<\/td>\n<\/tr>\n<tr>\n<td>TEQr1,r2<\/td>\n<td>r0:=r1^r2<\/td>\n<td>Test for equality of two 32bits<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<p>&nbsp;<\/p>\n<div>\n<p><strong>1.5.6\u00a0\u00a0\u00a0 Immediate operands<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Immediate addressing mode puts the raw 32 bits as one of the operands. It replaces the second source operand with an immediate value, which is a literal constant, preceded by \u201c#\u201d. Consider the two examples containing immediate operands.<\/p>\n<\/div>\n<div>\n<p>ADD r3,r3,#1 ;r3:=r3+1<\/p>\n<\/div>\n<p><span style=\"text-align: initial;font-size: 1em\">AND r8,r7,#&amp;FF\u00a0<\/span><span style=\"text-align: initial;font-size: 1em\">;r8:=r7[7:0], &amp;:hexadecimal<\/span><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">Since the immediate value is coded within the 32 bits of the instruction, it is not possible to enter every possible 32-bit value as an immediate. The bit layout Figure 1.4 shows only 12 bits are allowed for immediate value. Keeping 12 bits, the maximum value could be 4096. To accommodate larger value 8 bits are allocated to describe the base value and 4 bits are used for the rotate. Different ranges of data can be written by varying the n(4 bits). Following are few examples of varying n which leads to different immediate values. This can be even achieved by rotate right operation with the help of the barrel shifter. The following are a few examples of the values of immediate data obtained for rotation of different values of n. The first number shows the range for 8 bit number without rotation. The second row shows the range of values for n=1, where the rotation is in steps of four. Likewise is the next two rows with n=2 and n=3, with rotation in steps of 16 and 64.<\/span><\/p>\n<div>\n<p>Immediate = (0 \u2192 255) \u00d7 22<em>n<\/em> where 0&lt;=n&lt;=12<\/p>\n<table class=\"aligncenter\" style=\"width: 60%\">\n<tbody>\n<tr>\n<td>\u2013<\/td>\n<td>0 &#8211; 255<\/td>\n<td>[0 &#8211; 0xff]<\/td>\n<\/tr>\n<tr>\n<td>\u2013<\/td>\n<td>256,260,264,..,1020<\/td>\n<td>[0x100-0x3fc, step 4, 0x40-0xff ror 30]<\/td>\n<\/tr>\n<tr>\n<td>\u2013<\/td>\n<td>1024,1040,1056,..,4080<\/td>\n<td>[0x400-0xff0, step 16, 0x40-0xff ror 28]<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u2013\u00a0\u00a0 4096,4160, 4224,..,16320[0x1000-0x3fc0, step 64, 0x40-0xff ror 26]<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Following are few examples for loading immediate value. For example consider the immediate value of 4096(decimal) or 1000(Hex):<\/p>\n<p>&nbsp;<\/p>\n<p>\u2013\u00a0\u00a0\u00a0\u00a0 MOV r0, #0x40,26\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ; =&gt; MOV r0, #0x1000\u00a0\u00a0\u00a0 (ie 4096)<\/p>\n<p>&nbsp;<\/p>\n<p>The assembler will convert the required constant of hex or decimal into the rotate format:<\/p>\n<p>&nbsp;<\/p>\n<p>\u2013\u00a0\u00a0\u00a0\u00a0 MOV r0, #4096\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ; =&gt; MOV r0, #0x1000\u00a0\u00a0\u00a0 (ie 0x40 ror 26)<\/p>\n<p>&nbsp;<\/p>\n<p>On a similar concept, the bitwise complements can also be formed using MVN as shown in the example below:<\/p>\n<p>&nbsp;<\/p>\n<p>\u2013\u00a0\u00a0\u00a0\u00a0 MOV r0, #0xFFFFFFFF\u00a0\u00a0\u00a0 ; assembles to MVN r0, #0<\/p>\n<p>&nbsp;<\/p>\n<p>In case the required constant cannot be generated, an error will be reported by the processor.<\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><span style=\"text-align: initial;font-size: 1em\">To summarize ARM instruction cannot load a 32-bit immediate constant directly into a register. ARM instructions are encoded using 32-bits and only 12 bits are allocated for immediate values. The data processing instruction format has 12 bits available for operand 2. If used directly, this would only give a range of 4096. Instead it is used to store 8-bit constants, giving a range of 0-255. These 8 bits can then be rotated right through an even number of positions. This gives a much larger range of constants that can be directly loaded, though some constants will still need to be loaded from memory.<\/span><\/p>\n<div>\n<p>&nbsp;<\/p>\n<p><strong>1.5.6.1 Logical and Arithmetic shift operands<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Before executing an instruction in the ALU, ARM has the capability to preprocess the data in one of the operand with the help of barrel shifter. In general each instruction is executed in a single cycle. Consider the ADD example given below, where the r1 register is shifted 3 bits left prior to addition.<\/p>\n<p>&nbsp;<\/p>\n<p>ADD r3,r2,r1,LSL#3\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ; r3 := r2 + 8 * r1<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The barrel shifter implements five types of shift operations shown in Figure 1.5. The LSL: Logical Shift Left shift bits left by 0 to 31 places, 0 filled at the LSB end. On similar lines we have LSR, ASL (Arithmetic Shift Left), ASR, ROR (Rotate Right), RRX (Rotate Right eXtended by 1 place). Consider the two examples of LSL and ROR where a register is used to define the amount of shift. Each left shift is equivalent to multiplying the operand by 2. Hence the r3,LSL r2 (left shift r2 times)is equivalent tor3*2<strong>r2.<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>ADD r5,r5,r3,LSL r2 ; r5:=r5+r3*2<strong>r2<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>MOV r12,r4,ROR r3\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 ;r12:=r4 rotated right by value of r3<\/p>\n<\/div>\n<div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-347\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-202.png\" alt=\"\" width=\"635\" height=\"473\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-202.png 635w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-202-300x223.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-202-65x48.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-202-225x168.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-202-350x261.png 350w\" sizes=\"auto, (max-width: 635px) 100vw, 635px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>1.5.6.2 Barrel Shifter<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The second operand is the one that passes through the barrel shifter. Figure 1.6 shows the connection of barrel shifter and ALU in ARM processor. The barrel shifter has the ability to shift 32bits right or left by specific number of positions. Register uses the shift operation optionally. The Shift value can be either5-bit unsigned integer or specified in bottom byte of another register. The shift operation is also used for multiplication by constant. We had earlier discussed about immediate value, where the 8-bit number, with a range of 0 \u2013 255 is rotated right through even number of positions. This preprocessing allows increased range of 32-bit constants that can be loaded directly into registers. Thus barrel shifter brings in a unique and powerful feature for ARM processor.<\/p>\n<\/div>\n<div>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-348\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-203.png\" alt=\"\" width=\"490\" height=\"237\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-203.png 490w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-203-300x145.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-203-65x31.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-203-225x109.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-203-350x169.png 350w\" sizes=\"auto, (max-width: 490px) 100vw, 490px\" \/><\/p>\n<p><strong>1.5.7<\/strong>\u00a0\u00a0\u00a0\u00a0 <strong>Multiply Instructions<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">The multiply instruction multiplies the pair of registersRm,Rs(MUL) and occasionally accumulates the product with register Rn (MLA). The final result is stored in register or a pair of registers. The syntax of both the instructions is given below:<\/p>\n<p>&nbsp;<\/p>\n<p>\u2013\u00a0\u00a0 MUL{&lt;cond&gt;}{S} Rd,Rm,Rs<\/p>\n<p>&nbsp;<\/p>\n<p>\u2013\u00a0\u00a0 MLA{&lt;cond&gt;}{S} Rd,Rm,Rs,Rn<\/p>\n<p>&nbsp;<\/p>\n<table class=\"aligncenter\" style=\"width: 60%\">\n<tbody>\n<tr>\n<td>MUL r4,r3,r2;<\/td>\n<td>r4:=(r3*r2)[31:0]<\/td>\n<\/tr>\n<tr>\n<td>MLA r4,r3,r2,r1;<\/td>\n<td>r4:=((r3*r2)+r1)[31:0]<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">Table 1.6 shows the six types of multiplication instructions. The syntax for 64-bit multiplication with signed and unsigned register is listed below:<\/p>\n<p>&nbsp;<\/p>\n<p>\u2013\u00a0\u00a0 &lt;mul&gt;{&lt;cond&gt;}{S} RdHi,RdLo,Rm,Rs<\/p>\n<p>&nbsp;<\/p>\n<p>\u2013\u00a0\u00a0 &lt;mul&gt; is UMULL,UMLAL,SMULL,SMLAL<\/p>\n<table class=\"aligncenter\" style=\"width: 60%\">\n<tbody>\n<tr>\n<td><\/td>\n<td><\/td>\n<td><strong>Table 1.5Multiply Instructions<\/strong><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td><strong>Opco de<\/strong><\/td>\n<td><strong>Mnemo ni c<\/strong><\/td>\n<td><strong>Meani ng<\/strong><\/td>\n<td><strong>Effect<\/strong><\/td>\n<\/tr>\n<tr>\n<td><strong>[2 3 :2 1 ]<\/strong><\/td>\n<td><\/td>\n<td><\/td>\n<td><\/td>\n<\/tr>\n<tr>\n<td>000<\/td>\n<td>MUL<\/td>\n<td>Multiply (32-bit result)<\/td>\n<td>Rd := (Rm * Rs) [31:0]<\/td>\n<\/tr>\n<tr>\n<td>001<\/td>\n<td>MLA<\/td>\n<td>Multiply-accumulate (32-bit result)<\/td>\n<td>Rd := (Rm * Rs + Rn) [31:0]<\/td>\n<\/tr>\n<tr>\n<td>100<\/td>\n<td>UMULL<\/td>\n<td>Unsigned multiply long<\/td>\n<td>RdHi:RdLo := Rm * Rs<\/td>\n<\/tr>\n<tr>\n<td>101<\/td>\n<td>UMLAL<\/td>\n<td>Unsigned multiply-accumulate long<\/td>\n<td>RdHi:RdLo += Rm * Rs<\/td>\n<\/tr>\n<tr>\n<td>110<\/td>\n<td>SMULL<\/td>\n<td>Signed multiply long<\/td>\n<td>RdHi:RdLo := Rm * Rs<\/td>\n<\/tr>\n<tr>\n<td>111<\/td>\n<td>SMLAL<\/td>\n<td>Signed multiply-accumulate long<\/td>\n<td>RdHi:RdLo += Rm * Rs<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\"><strong>Booth\u2019s algorithm <\/strong>is used to perform integer multiplication. Booth\u2019s recoding basically looks into the transition of 1 to 0 and 0 to 1 in the binary pattern of the register (multiplier). ARM7TDMI <em>Mul<\/em> will execute in minimum of 2 clock cycles and maximum of 5 clock cycles. There are a few restrictions on the use of registers for this operation:<\/p>\n<p>&nbsp;<\/p>\n<p>1. Rd and Rm cannot be the same register (can be avoided by swapping over Rm and Rs \u2013 multiplication is commutative)<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">2. Cannot use PC\u00a0<span style=\"text-align: initial;font-size: 1em\">Multiplication by a constant equal to a ((power of 2) +\/- 1) can be done in a single cycleusing MOV, ADD or RSB with an inline shift. We can also combine several instructions to carry out other multiplications. The table 1.7 shows the different variants of MUL implementation.<\/span><\/p>\n<\/div>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-349\" src=\"http:\/\/csp13.epgpbooks.inflibnet.ac.in\/wp-content\/uploads\/sites\/62\/2018\/07\/2-204.png\" alt=\"\" width=\"694\" height=\"169\" srcset=\"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-204.png 694w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-204-300x73.png 300w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-204-65x16.png 65w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-204-225x55.png 225w, https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-content\/uploads\/sites\/62\/2018\/07\/2-204-350x85.png 350w\" sizes=\"auto, (max-width: 694px) 100vw, 694px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>1.6 Summary<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: justify\">In this lecture we have discussed ARM Instructions set format and classification of instruction set. A detailed discussion on data processing instruction with examples and syntax was explored. We studied the impact made by barrel shifter on data pre-processing.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><strong>2. References<\/strong><\/p>\n<ol>\n<li><em><a href=\"http:\/\/www.arm.com\/\">www.<strong>arm<\/strong>.com<\/a><\/em><\/li>\n<li><em>en.wikipedia.org\/wiki\/<strong>ARM<\/strong>_architecture<\/em><\/li>\n<li>Andrew N Sloss, D. Symes, C. Wright, \u201d Arm system developers guide\u201d, Morgan Kauffman\/ Elsevier, 2006.<\/li>\n<\/ol>\n","protected":false},"author":2,"menu_order":27,"template":"","meta":{"pb_show_title":"on","pb_short_title":"","pb_subtitle":"","pb_authors":["dr-selvi-ravindran"],"pb_section_license":""},"chapter-type":[],"contributor":[59],"license":[],"class_list":["post-338","chapter","type-chapter","status-publish","hentry","contributor-dr-selvi-ravindran"],"part":3,"_links":{"self":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/pressbooks\/v2\/chapters\/338","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/pressbooks\/v2\/chapters"}],"about":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/wp\/v2\/types\/chapter"}],"author":[{"embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/wp\/v2\/users\/2"}],"version-history":[{"count":5,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/pressbooks\/v2\/chapters\/338\/revisions"}],"predecessor-version":[{"id":351,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/pressbooks\/v2\/chapters\/338\/revisions\/351"}],"part":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/pressbooks\/v2\/parts\/3"}],"metadata":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/pressbooks\/v2\/chapters\/338\/metadata\/"}],"wp:attachment":[{"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/wp\/v2\/media?parent=338"}],"wp:term":[{"taxonomy":"chapter-type","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/pressbooks\/v2\/chapter-type?post=338"},{"taxonomy":"contributor","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/wp\/v2\/contributor?post=338"},{"taxonomy":"license","embeddable":true,"href":"https:\/\/ebooks.inflibnet.ac.in\/csp13\/wp-json\/wp\/v2\/license?post=338"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}