Comparing Instruction

Data Handling

W. Bolton , in Programmable Logic Controllers (Sixth Edition), 2015

12.2.two Data Comparing

The information comparison instruction gets the PLC to compare ii data values. Thus it might exist to compare a digital value read from some input device with a second value contained in a annals. For example, we might want some activeness to exist initiated when the input from a temperature sensor gives a digital value that is less than a prepare value stored in a data register in the PLC. PLCs generally can make comparisons for less than (< or LT or LES), equal to (= or = = or EQ or EQU), less than or equal to (≤ or .<= or LE or LEQ), greater than (> or GT or GRT), greater than or equal to (≥ or >= or GE or GEQ), and not equal to (≠ or <> or NE or NEQ). The parentheses alongside each of the terms indicates mutual abbreviations used in programming. Every bit an illustration, in structured text we might have:

(*Bank check that boiler pressure P2 is less than pressure P1*)

Output := P2 < P1;

With ladder programs, for data comparing the typical instruction will contain the data-transfer educational activity to compare data, the source (S) address from which the data is to be obtained for the comparing, and the destination (D) address of the data against which it is to be compared. The instructions commonly used for the comparing are the terms indicated in the preceding parentheses. Figure 12.4 shows the type of formats used by three manufacturers using the greater-than form of comparison. Like forms apply to the other forms of comparison. In Figure 12.4a the format is that used by Mitsubishi, South indicating the source of the data value for the comparison and D the destination or value against which the comparison is to exist made. Thus if the source value is greater than the destination value, the output is 1. In Effigy 12.4b the Allen-Bradley format has been used. Here the source of the data being compared is given as the accumulated value in timer 4.0 and the data confronting which it is being compared is the number 400. Figure 12.4c shows the Siemens format. The values to be compared are at inputs IN1 and IN2 and the upshot of the comparing is at the output: one if the comparison is successful, otherwise 0. The R is used to signal real numbers, that is, floating point numbers, I being used for integers, that is, fixed-betoken numbers involving 16 bits, and D for fixed-point numbers involving 32 bits. Both the inputs need to be of the aforementioned information type, such as REAL.

Figure 12.iv. Greater than comparing: (a) Mitsubishi, (b) Allen-Bradley, and (c) Siemens.

As an illustration of the employ of such a comparison, consider the task of sounding an alert if a sensor indicates that a temperature has risen higher up some value, say, 100°C. The alarm is to remain sounding until the temperature falls below ninety°C. Figure 12.5 shows the ladder diagram that might exist used. When the temperature rises to get equal to or greater than 100°C, the greater-than comparing element gives a 1 output and and so sets an internal relay. In that location is then an output. This output latches the greater-than comparison element, so the output remains on, even when the temperature falls below 100°C. The output is non switched off until the less-than 90°C chemical element gives an output and resets the internal relay.

Figure 12.5. Alarm programme.

Another example of the apply of comparison is when, say, 4 outputs demand to be started in sequence, that is, output ane starts when the initial switch is closed, followed sometime later by output 2, sometime afterwards by output 3, and sometime later by output 4. Though this could be done using three timers, another possibility is to use one timer with greater-than or equal elements. Figure 12.6 shows a possible ladder diagram. When the X401 contacts close, the output Y430 starts. The timer is also started. When the timer-accumulated value reaches five   southward, the greater-than or equal-to element switches on Y431. When the timer-accumulated value reaches 15   s, the greater-than or equal-to chemical element switches on Y432. When the timer reaches 25   south, its contacts switch on Y433.

Figure 12.half dozen. Sequential switching on.

Read full chapter

URL:

https://www.sciencedirect.com/science/article/pii/B9780128029299000121

INTRODUCTION TO THE ARM Pedagogy Ready

ANDREW N. SLOSS , ... CHRIS WRIGHT , in ARM System Developer's Guide, 2004

3.9 SUMMARY

In this chapter we covered the ARM instruction set. All ARM instructions are 32 bits in length. The arithmetics, logical, comparisons, and motion instructions can all use the inline barrel shifter, which pre-processes the 2nd register Rm earlier it enters into the ALU.

The ARM instruction ready has three types of load-store instructions: unmarried-annals load-store, multiple-register load-store, and swap. The multiple load-shop instructions provide the push-pop operations on the stack. The ARM-Thumb Procedure Telephone call Standard (ATPCS) defines the stack as being a full descending stack.

The software interrupt teaching causes a software interrupt that forces the processor into SVC mode; this instruction invokes privileged operating system routines. The program status register instructions write and read to the cpsr and spsr. There are also special pseudoinstructions that optimize the loading of 32-bit constants.

The ARMv5E extensions include count leading zeros, saturation, and improved multiply instructions. The count leading zeros instruction counts the number of binary zeros before the outset binary ane. Saturation handles arithmetic calculations that overflow a 32-bit integer value. The improved multiply instructions provide amend flexibility in multiplying 16-chip values.

Most ARM instructions can exist conditionally executed, which can dramatically reduce the number of instructions required to perform a specific algorithm.

Read full chapter

URL:

https://www.sciencedirect.com/science/commodity/pii/B9781558608740500046

Floating point

Larry D. Pyeatt , William Ughetta , in ARM 64-Scrap Assembly Linguistic communication, 2020

ix.seven.6 Compare

The compare education subtracts the value in

Image 70

from the value in

Image 60

and sets the flags in the

Image 100

annals based on the effect. The condition code meanings after an

Image 101

didactics are shown in Table ix.ane . The comparing instructions are:

fcmp

Compare,

fcmpe

Compare with Exception,

fccmp

Conditional Compare, and

fccmpe

Provisional Compare with Exception.

Table 9.i. Condition code meanings for ARM and FP/NEON.

&lt;cond&gt; ARM data processing didactics FP fcmp instruction
AL Always Always
EQ Equal Equal
NE Not Equal Not equal, or unordered
GE Signed greater than or equal Greater than or equal
LT Signed less than Less than, or unordered
GT Signed greater than Greater than
LE Signed less than or equal Less than or equal, or unordered
Hello Unsigned higher Greater than, or unordered
LS Unsigned lower or same Less than or equal
HS Bear prepare/unsigned higher or same Greater than or equal, or unordered
CS Aforementioned every bit HS Aforementioned as HS
LO Carry clear/ unsigned lower less than
CC Aforementioned equally LO Aforementioned equally LO
MI Negative Less than
PL Positive or aught Greater than or equal, or unordered
VS Overflow Unordered (at least one NaN operand)
VC No overflow Not unordered

ix.7.6.1 Syntax

For the

Image 103
and
Image 104
instructions, an exception is raised if whatever child of NaN is encountered. Otherwise an exception is raised but for signaling NaNs.
Image 105
is ane of the 2 grapheme condition codes from Table iii.2.
Image 106
is a value that is used to set up the NZCV flags if
Image 105
is not truthful.

9.vii.six.2 Operations

Name Event Description
fcmp{e} PSTATE ←flags(Fn −Fm) Compare two registers
fcmp{e} PSTATE ←flags(Fn − 0) Compare to zero
fccmp{e}
Conditional compare 2 registers
fccmp{e}
Conditional compare to zero

9.seven.vi.3 Examples

Read full chapter

URL:

https://world wide web.sciencedirect.com/scientific discipline/commodity/pii/B978012819221400016X

Data processing and other instructions

Larry D. Pyeatt , William Ughetta , in ARM 64-Scrap Assembly Language, 2020

iv.2.10 Conditional operations

These conditional select operations prepare the destination register to the outset operand,

Image 39

if the condition is true, and to the second operand optionally incremented, inverted, or negated if the condition is imitation:

csel

Conditional Select,

csinc

Conditional Select Increase,

csinv

Conditional Select Capsize,

csneg

Conditional Select Negate.

There are five aliases that are derived from the previous instructions:

cinc

Conditional Increment,

cinv

Conditional Capsize,

cneg

Provisional Negate,

cset

Conditional Set, and

csetm

Conditional Set Mask.

Conditional comparing instructions allow

Image 30

to be set to either a comparison or an firsthand, depending on the flags in

Image 30

:

ccmp

Conditional Compare,

ccmn

Conditional Compare Negative.

The conditional compare and compare negative instructions check the

Image 30

flags for the given condition. If information technology is truthful, then it sets the

Image 30

flags to the comparison of

Image 39

and either

Image 16

or

Image 109

. If it is false, it sets the

Image 30

flags to an firsthand iv bit value representing

Image 54

.

4.2.ten.1 Syntax

Image 32
is one of
Image 111
,
Image 112
,
Image 113
, or
Image 114
.
Image 34
is one of
Image 115
,
Image 116
, or
Image 117
.
Image 118
is
Image 119
or
Image 120
.

The

Image 121
is whatever one of the codes from Table 3.two on page 59.

The

Image 122
is any number 0-15 (0x0-0xf). Information technology is four bits representing the N, Z, C, and V flags.

The

Image 109
is an unsigned 5-bit immediate.

4.ii.x.2 Operations

4.2.10.iii Examples

The following C function will flip the parity of a number and alternate betwixt two values if its output is re-used equally the input:

The AArch64 translation uses conditional choice instead of branching to implement the if-else statement. The input

Image 125

is in

Image 126

and is besides returned in

Image 126

every bit the output:

This works because instead of testing if the role is even with division and remainders equally in the C lawmaking,

Image 128

, the assembly does a conditional bitwise AND with 0x1 considering the least significant chip volition always be 0 for an fifty-fifty number and 1 for an odd number in binary. The value

Image 129

is placed in

Image 45

. If

Image 125

is odd, which means that the

Image 130

flag in

Image 30

is 0, and so

Image 126

is set to the value of

Image 45

. Otherwise, if

Image 125

is even, so the

Image 130

flag is 1 and

Image 126

is set to the value of

Image 131

since it is the conditional select increment didactics.

Read full chapter

URL:

https://world wide web.sciencedirect.com/scientific discipline/article/pii/B9780128192214000110

The Linux/ARM embedded platform

Jason D. Bakos , in Embedded Systems, 2016

one.6 Assembly Optimization #1: Sorting

The adjacent two sections walk through ARM assembly programming, optimization, and performance analysis for two examples. The first example is a bubble sort.

1.6.1 Reference implementation

Begin by writing a reference implementation in C in the file bubble_sort.c :

ane   #define   North   32768

ii

three   int data[N];

4

v   int primary () {

6   int i,j,temp;

7

8   for (i=0;i<(Due north-1);i++)

9   for (j=0;j<(Northward-1);j++)

x   if (data[j]>data[j+one]) {

eleven   temp=data[j];

12   data[j]=data[j+one];

xiii   data[j+1]=temp;

xiv   }

15   return 1;

16   }

The offset iii lines allocate an array of 32K integers in global memory. For now the program will not initialize this array.

Recall that the bubble sort compares each sequent pair of values n    1 times, where n is the number of elements. Later on each comparison, the values are swapped if they are in nonsorted order. Each individual value tin can move at most one position toward the outset of the array per iteration of the outermost loop, which can be thought of equally bubbling slowing ascension to the top of a liquid.

Salvage this file as bubble_sort.c and compile with gcc, using the "-O3" flag to tell the compiler to utilise maximum optimization:

gcc bubble_sort.c –O3 –o bubble_sort

Execute and fourth dimension the program using:

time ./bubble_sort

On an ARM Cortex A15, the program requires iv.0   s of user CPU fourth dimension to execute. From this it is possible to brand rough estimations regarding the efficiency of the compiler.

The program compares n 2  =   twoxv  ×   iififteen  =   230 pairs of values, meaning the processor needs approximately 4.0/230  =   3.7   ps per comparison.

At our clock charge per unit of two.3   GHz (usually found in /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq ), this translates into

2.three e 9 × 3.7 eastward 9 = 8.5 cycles per comparison

This includes both the cycles required to execute the comparison instructions and the time needed for the transactions with memory (cache miss stalls). Is this reasonable?

To find out, allow us write a pure associates implementation in the file bubble_sort_asm.s .

1.6.two Associates implementation

Use the " .equ " assembler directive to ascertain the constant N :

one   .equ   N,32768

Utilise the " .comm " assembler directive to allocate infinite for the data array. This creates the array with proper noun "data," size Northward*4, and whose starting address is aligned on the 4-byte boundary (evenly divisible by 4).

2   .comm   data,N*four,4

Next, use the ".global" directive to tell the assembler to export the main function (divers later) so it can be statically linked and chosen by Linux's runtime environment:

iii   .global   chief

Finally, use the ".arch" directive to tell the assembler to generate ARMv7-A motorcar language:

4   .arch   armv7-a

Brainstorm the main office with the "primary" label, using the kickoff instructions to set register r1 up to be the iteration limit for both the outer and inner for-loops. Our offset instructions will perform the following:

one.

load the value defined as Northward into register r1 and

two.

decrement this register past 1

5   main:   ldr   r1,=N

half-dozen   sub   r1,r1,#1   @ r1 = N-1

Brainstorm the outer for-loop by assigning the outer loop counter—the i variable—to register 5 and initialize it to 0:

7   mov   r5,#0   @ i = 0

Both the outer and inner loops are for-loops. For-loops are pretest loops, so they begin with a test to determine if the loop body should be executed. In this case, compare the value of the outer loop counter to the limit, which is assigned to registers r5 and r1, respectively. If these values are equal, get out the loop:

8   oloop:cmp   r5,r1   @ i == Due north-i ?

ix   beq   exito

The outer loop body will consist of the inner loop, which tin exist ready exactly equally for the outer loop. Use annals iii for the inner loop counter:

x   mov   r3,#0   @ j = 0

In addition to initializing our loop counter to 0, initialize a base of operations register for the assortment:

11   ldr   r2,=data   @ r2 = &information

In a literal translation of the C code, the inner loop will load elements j and j  +   i into two registers, compare them, and store them back in reverse order if necessary. But every iteration of the inner loop needs just to load element j  +   1, since element j would have been available in the previous iteration.

The inner loop allocates register r11 for element j and register r10 for element j  +   ane. The annals numbers are in reverse lodge and then use a store-multiple ( stm ) instruction to store the registers in order when swapping the values in memory (a requirement of the stm instruction).

Before starting the inner loop the programme must pre-load the first element.

12   ldr   r11,[r2]

Add our loop test:

13   iloop:cmp   r3,r1   @ j == N-1 ?

14   beq   exiti

The inner loop body loads one value from the array (respective to chemical element j  +   1), compares it with element j, and stores them back to the array in contrary order if necessary.

Utilize register 2 equally the base register for the current position in the array. When loading element j  +   one, apply the pre-increment addressing mode that will load the second value and update register 2 to the address of the second value:

15   ldr   r10,[r2,#4]

Compare these values. The status of element j beingness greater than the element j  +   1 value will serve as the predicate for storing the values back in contrary social club.

Apply the store-multiple education when storing the elements.

16   cmp   r11,r10   @ compare values

17   stmgt   r2,{r10,r11}   @ store in reverse order

If the program stored the values back in reverse order, the current value of r11 , which originally represented element j, will now take moved up one position in the assortment to effectively become element j  +   1. This value will be treated at element j in the next iteration so the plan can leave information technology in register r11 for the next iteration.

If the values were not swapped, copy the value in register r10 to annals r11 for the next iteration of the loop. The condition for this is less than or equal (le), the logical complement of greater than.

19   movle   r11,r10

After the inner loop body, increment the assortment index register and inner loop counter, and so co-operative back to the beginning of the loop.

xx   add   r2,r2,#iv

21   add   r3,r3,#1   @ j++

22   b   iloop

Upon exiting the inner loop, do the aforementioned for the outer loop:

23   exiti:add   r5,r5,#one   @ i++

24   b   oloop

Upon exiting the outer loop, return from the main function past jumping to the location stored in the link register:

25   exito:bx   lr

Assemble this code using gcc and fourth dimension its execution by:

gcc bubble_sort_asm.southward -o bubble_sort -O3

time ./bubble_sort_asm

The time required by this assembly implementation requires 3.half-dozen   south, a speedup of xi% over the compiler-generated version.

1.6.three Result verification

Assembly code is less readable than C lawmaking, making it more than prone to programming errors. Every bit such, when testing an optimized implementation yous should always validate its results confronting a second, reference implementation and compare the results. Executing both implementations provides the power to perform performance comparisons, and bugs are revealed by mismatches in the output data.

In guild to motility forward, convert the reference implementation into a function. This requires deleting the code relating to the array and the value of N, changing the proper name of the role from main to "bubble_sort", and using arguments to pass in the arrow to the assortment and its size:

1   int bubble_sort (int *data,int n) {

2   int i,j,temp;

3   for (i=0;i<n-i;i++)

four   for (j=0;j<n-1;j++)

5   if (data[j]>data[j+1]) {

6   temp=data[j];

7   data[j]=data[j+1];

8   data[j+1]=temp;

9   }

ten   return 1;

11 }

Side by side, convert the associates implementation into a function. To practise this, remove the " .equ " and " .comm " directives, alter the name of the exported symbol to "bubble_sort_asm", and add a new directive that specifies this equally a office:

1   .global   bubble_sort_asm

2   .arch   armv7-a

3   .blazon   bubble_sort_asm, %function

The function arguments, the pointer to the array and its size, will arrive in registers r0 and r1 , respectively. Every bit such, remove the instruction " ldr r1,=N " that initializes the size of the assortment. Likewise, modify the instruction that initializes the base register for the array in the outer loop body from " ldr r2,=information " to " mov r2,r0 ".

Lastly, set the render value in register r0 just before returning to the caller:

exito:   mov   r0,#1

  bx   lr

Now write a driver that volition call both functions. The driver will as well be responsible for allocating the arrays and verifying the results.

i   #include <   stdio.h   >

two   #include <   stdlib.h   >

3   #define   North   32768

4

5   int bubble_sort (int *data,int due north);

6   int bubble_sort_asm (int *data,int northward);

7

8   int main () {

nine   int i,*data1,*data2;

10

11   data1 = (int *)malloc(Due north*sizeof (int));

12   data2 = (int *)malloc(North*sizeof (int));

13

14   srand(eleven);

15   for (i=0;i<Due north;i++) data1[i]=data2[i]=rand();

16   bubble_sort(data1,N);

17   bubble_sort_asm(data2,N);

eighteen

19   for (i=0;i<Due north;i++)

20   if (data1[i] != data2[i]) {

21   fprintf(stderr,"mismatch on element %d\n",i);

22   return 0;

23   }

24

25   return one;

26   }

Compile this code with gcc:

gcc main2.c bubble_sort.c bubble_sort_asm.south -o primary

If the program runs without validation errors, information technology is reasonable to assume that the assembly implementation is functionally correct and implements the same algorithm as the compiler-generated code. But what accounts for the functioning divergence?

Recall that functioning is impacted by many factors, including:

number of instructions executed,

stalls from information dependencies and branch mispredictions,

data dependencies and resources constraints that foreclose multiple-issue, and

stalls from cache misses.

All of these factors, including the cache miss rate, can potentially exist changed in a mode that improves performance by changing the associates lawmaking implementation of the algorithm.

ane.6.iv Analysis of compiler-generated lawmaking

In order to explore how associates implementation affects these performance factors, examine the compiler-generated assembly (using) and compare information technology with the hand-written associates. Use gcc'south " -Southward " switch to generate the associates, the " -O3 " switch to enable maximum compiler optimization, and the " -marm " switch to generate ARM-manner assembly (as opposed to Pollex-mode).

The bubble sort part begins with r0 containing the accost of the data array ( data ) and r1 containing the size of the assortment (north).

Compute n     1 and go out the function if the result equals 0.

1   sub   lr, r1, #1

2   cmp   lr, #0

3   ble   .L2

Compute the effective address of the end of the assortment, which is data + n *4. Note that "ip" is register r12, which is defined every bit the "intra procedure scratch annals."

four   add   ip, r0, r1, asl #ii

Gear up r4 = data + 4 and initialize i = ( r0 ) = 0

five   add   r4, r0, #four

6   mov   r0, #0

Begin outer loop; reset r3 to point to the first of the assortment

7   .L3:

8   mov   r3, r4

Brainstorm inner loop; load two elements into r2 and r1 . Note that r3 begins at iv bytes into the assortment, so the start load offsets past −   iv bytes and the second load uses mail-increment to increment r3 .

9   .L6:

10   ldr   r2, [r3, #-4]

Compare the values and bandy (using the store multiple educational activity) if necessary.

xi   ldr   r1, [r3], #four

12   cmp   r2, r1

xiii   stmgtdb   r3, {r1, r2}

Compare r3 with the end of the array and loop; if not equal repeat inner loop.

14   cmp   r3, ip

fifteen   bne   .L6

Once finished with inner loop, increment counter, compare counter with n , and if not equal repeat output loop.

16   add   r0, r0, #i

17   cmp   r0, lr

18   bne   .L3

The ".L2" characterization is the exit betoken.

19   .L2:

The inner loop is comprised of only six instructions, while ours has 9 instructions, so we must assume our inner loop required less than 2/3 of the cycles as compared to the compiler-generated inner loop.

Read full chapter

URL:

https://www.sciencedirect.com/science/article/pii/B9780128003428000018

Early Intel® Architecture

In Power and Operation, 2015

1.1.three Instructions

Continuing the scenario described in the introductory department, once the #RESET pivot is asserted and deasserted, the processor initializes the programme registers to their predefined values. This includes the predefined value of the teaching arrow, providing the BIU the first location to fetch and decode for the execution unit.

This first location is always the concluding sixteen bytes in the physical address infinite. For a xvi-bit processor with xx-scrap physical addresses, this is 0xFFFF0. This provides just enough room for a JMP to the BIOS's real initialization code.

To empathise the reasoning behind this, consider that the very commencement instructions executed, which are responsible for initializing the system and preparing a standardized execution environment before booting the operating organisation, belong to the BIOS. The BIOS is mapped into the concrete address space, but information technology doesn't reside in physical memory. Instead, the BIOS is stored in a ROM bit, located on the motherboard, connected with a Depression Pin Count (LPC) Bus. This ROM is retention mapped at the very top of the concrete address space, such that the last byte of the ROM is at the very acme. Therefore, differently sized ROMs have dissimilar starting addresses inside retention. For example, a 1-KB ROM would get-go at 0xFFFFF − 0ten400 + 1 = 0xFFC00, where as 4-KB ROM would start at 0xFFFFF − 0101000 + one = 0xFF000. These showtime instructions executed, the last bytes of the BIOS ROM, are the only address guaranteed to contain valid BIOS lawmaking, and since it belongs to the BIOS, it is guaranteed to know where in concrete memory the residual of the initialization code resides.

From this indicate on, the processor continues its loop of fetching new instructions, decoding those instructions, so executing those instructions. Each instruction defines an functioning that transitions the state motorcar from one state to another.

Each individual instruction is comprised of one or more forms, that is, diverse encodings treatment different operand types. An operand is simply a parameter for the education, defining what aspect of the land should be acted upon. Examples of operands include a specific register, memory accost, or an immediate, that is, a constant value at the fourth dimension of assembly. Every bit mentioned before, operands can be either explicit or implicit.

To illustrate this, consider the ADD educational activity, which at the time of the 8086, had six unique forms. These forms are listed in Table 1.1. Notice how the beginning five forms are explicit, whereas the last form has an implicit operand, AX.

Table 1.1. Forms for the ADD Instruction on the Intel® 8086

Operand Form Example Note
register, register add together %ax, %dx dx = ax + dx
register, memory add %ax, (%dx) *(short *)dx = *(short *)dx + ax;
memory, register add (%dx), %ax ax = ax + *(short *)dx;
immediate, annals add $10, %ax ax = ax + ten;
immediate, memory add $10, (%bx) *(short *)bx = *(brusk *)bx + x;
immediate add $10 ax = ax + 10;

The 8086 had an pedagogy set comprising of nigh one hundred unique instructions, non bookkeeping for different forms. These instructions tin be divided into five logical groupings. For a full reference of the available instructions, along with their meanings and operands, see the Intel SDM.

Data movement

The get-go grouping contains instructions that movement information from one operand to another. This includes instructions similar MOV, which can move data from one operand to another, PUSH and Popular, which pushes an operand onto the stack or pops the pinnacle of the stack into the operand, and XCHG, which atomically swaps the contents of two operands.

Integer arithmetics

The 2d group contains instructions that perform integer arithmetics. This includes instructions that perform the standard familiar arithmetic operations, such every bit ADD, SUB, MUL, and DIV.

Additionally, x86 supports instructions for performing these operations "with carry" or "with borrow." This is used for implementing these operations over an arbitrarily large number of bytes. In the case of a carry, the bit in EFLAGS is preserved for the next instruction to translate. For case, each ADC, add with comport, instruction uses this bit to determine whether the issue should be incremented past one, in order to borrow the bit carried from the previous ADC operation.

Typically each of these instructions sets the relevant status bits in the EFLAGS register. This often obviates the need to consequence an explicit comparison instruction for some checks, like checks for zero, or less than zero. Instead, the flag tin can but be reused from the arithmetic operation.

Every bit mentioned earlier, the AX annals is designated the accumulator register, so almost arithmetic instructions take implicit forms that perform operations on, and store the issue in AX.

Boolean logic

The third group contains instructions that perform boolean logic. This includes instructions like AND, which only sets $.25 in the result that are set in both operands, OR, which only sets bits in the consequence that are set in at to the lowest degree one of the operands, and XOR, which only sets bits in the result that are set in one operand and not the other.

Similar to the arithmetics group, these instructions also favor AX for their results. Additionally, they set the same bits in EFLAGS, sans the comport bits.

Flow command

The 4th grouping contains instructions that modify the plan period. Different a high level language, there are no if statements or for loop constructs. Instead, arithmetics and logical instructions set up bits in the EFLAGS register, which tin can then exist acted upon by control catamenia instructions. For example, consider the post-obit two equivalent code snippets:

Listing 1.1. C version.

Listing one.ii. x86.

In the assembly version, the CMP instruction checks the contents of the register operand, AX, against an immediate, that is, a constant at assemble fourth dimension, and sets the status flags in the EFLAGS register accordingly. While the JMP instruction unconditionally performs the spring, there are likewise conditional bound instructions. These instructions take the form of Jcc, where cc is a condition lawmaking. A status code represents a predefined set of ane or more conditions based on the status of EFLAGS. For example, the JNZ instruction just performs the leap if the Zero Flag (ZF) is not fix. In the list above, the JLE educational activity just jumps to .Lskip_saturation when AX is less than or equal to 255, thereby skipping the saturation that occurs on line iii.

Cord

The 5th group contains instructions designed to operate on strings. This includes instructions for loading, LODS, storing, STOS, searching, SCAS, and comparison, CMPS, strings.

The string instructions are designed to heavily apply implicit operands. The current character, either being loaded from, stored to, or scanned for, is held in AX. The source and destination pointers to strings are stored in DS:SI and ES:DI, respectively. The length of the strings are typically held in CX.

For case, the LODS instruction loads the byte at DS:SI into the AX register and so decrements or increments, depending on the status of the direction flag in EFLAGS, SI. Conversely, the STOS educational activity stores the byte in AX into the memory location ES:DI, so updates the pointer accordingly.

The SCAS pedagogy compares the value of AX to the byte located at the retentiveness location pointed to past ES:DI, updates the EFLAGS register accordingly, and then autoincrements or autodecrements DI. The CMPS teaching, designed for fast cord comparison, compares the bytes located at ES:DI and DS:SI, updates the EFLAGS register, so autoincrements or autodecrements both DI and SI.

While these string instructions perform one stage of their respective operations, they tin can exist extended to perform the total operation by combining them with the REP prefix. This prefix repeats the instruction until the given status is satisfied. This condition is specified through the suffix of the REP prefix. Table 1.two lists the bachelor REP prefixes and their subsequent meanings.

Table 1.two. Meanings of the REP Prefix (Intel Corporation, 2013)

Prefix Significant
REP Repeat until CX = 0
REPE/REPZ Repeat until EFLAGS.ZF != 0
REPNE/REPNZ Echo until EFLAGS.ZF == 0

Read full chapter

URL:

https://www.sciencedirect.com/science/commodity/pii/B978012800726600001X