banner



What Register Does The Cmp Command Change

Assembly - Conditions


Conditional execution in associates linguistic communication is achieved by several looping and branching instructions. These instructions tin can change the menstruum of control in a program. Provisional execution is observed in two scenarios −

Sr.No. Conditional Instructions
1

Unconditional spring

This is performed by the JMP pedagogy. Provisional execution often involves a transfer of control to the address of an educational activity that does non follow the currently executing didactics. Transfer of control may be frontwards, to execute a new fix of instructions or backward, to re-execute the same steps.

2

Conditional jump

This is performed by a set of jump instructions j<condition> depending upon the condition. The conditional instructions transfer the command past breaking the sequential menstruum and they do information technology by changing the offset value in IP.

Let united states talk over the CMP teaching earlier discussing the conditional instructions.

CMP Instruction

The CMP instruction compares two operands. It is generally used in provisional execution. This educational activity basically subtracts one operand from the other for comparing whether the operands are equal or not. Information technology does non disturb the destination or source operands. It is used along with the provisional jump instruction for conclusion making.

Syntax

CMP destination, source        

CMP compares 2 numeric data fields. The destination operand could be either in register or in memory. The source operand could be a constant (firsthand) data, register or memory.

Example

CMP DX,	00  ; Compare the DX value with nothing JE  L7      ; If yes, then spring to label L7 . . L7: ...        

CMP is often used for comparing whether a counter value has reached the number of times a loop needs to be run. Consider the following typical condition −

INC	EDX CMP	EDX, ten	; Compares whether the counter has reached x JLE	LP1     ; If it is less than or equal to x, then bound to LP1        

Unconditional Jump

Equally mentioned before, this is performed by the JMP education. Provisional execution frequently involves a transfer of control to the address of an instruction that does not follow the currently executing instruction. Transfer of command may exist forward, to execute a new set up of instructions or backward, to re-execute the same steps.

Syntax

The JMP instruction provides a characterization name where the flow of control is transferred immediately. The syntax of the JMP instruction is −

JMP	label        

Instance

The post-obit code snippet illustrates the JMP instruction −

MOV  AX, 00    ; Initializing AX to 0 MOV  BX, 00    ; Initializing BX to 0 MOV  CX, 01    ; Initializing CX to 1 L20: Add together  AX, 01    ; Increment AX Add  BX, AX    ; Add AX to BX SHL  CX, 1     ; shift left CX, this in turn doubles the CX value JMP  L20       ; repeats the statements        

Conditional Jump

If some specified condition is satisfied in conditional spring, the command flow is transferred to a target instruction. There are numerous conditional jump instructions depending upon the condition and data.

Following are the conditional leap instructions used on signed information used for arithmetics operations −

Didactics Description Flags tested
JE/JZ Spring Equal or Jump Nada ZF
JNE/JNZ Spring not Equal or Jump Non Null ZF
JG/JNLE Jump Greater or Bound Not Less/Equal OF, SF, ZF
JGE/JNL Jump Greater/Equal or Bound Not Less OF, SF
JL/JNGE Jump Less or Jump Not Greater/Equal OF, SF
JLE/JNG Jump Less/Equal or Bound Not Greater OF, SF, ZF

Following are the conditional jump instructions used on unsigned data used for logical operations −

Instruction Clarification Flags tested
JE/JZ Jump Equal or Bound Zero ZF
JNE/JNZ Leap not Equal or Jump Non Cipher ZF
JA/JNBE Jump Above or Jump Not Beneath/Equal CF, ZF
JAE/JNB Bound Above/Equal or Jump Not Beneath CF
JB/JNAE Bound Below or Jump Not To a higher place/Equal CF
JBE/JNA Jump Below/Equal or Jump Non Above AF, CF

The post-obit conditional jump instructions have special uses and check the value of flags −

Instruction Description Flags tested
JXCZ Jump if CX is Zero none
JC Jump If Acquit CF
JNC Jump If No Carry CF
JO Leap If Overflow OF
JNO Jump If No Overflow OF
JP/JPE Spring Parity or Jump Parity Even PF
JNP/JPO Jump No Parity or Jump Parity Odd PF
JS Jump Sign (negative value) SF
JNS Jump No Sign (positive value) SF

The syntax for the J<status> fix of instructions −

Case,

CMP	AL, BL JE	EQUAL CMP	AL, BH JE	EQUAL CMP	AL, CL JE	EQUAL NON_EQUAL: ... EQUAL: ...        

Example

The post-obit program displays the largest of iii variables. The variables are double-digit variables. The three variables num1, num2 and num3 accept values 47, 22 and 31, respectively −

section	.text    global _start         ;must be declared for using gcc  _start:	                 ;tell linker entry bespeak    mov   ecx, [num1]    cmp   ecx, [num2]    jg    check_third_num    mov   ecx, [num2]     	check_third_num:     cmp   ecx, [num3]    jg    _exit    mov   ecx, [num3]     	_exit:        mov   [largest], ecx    mov   ecx,msg    mov   edx, len    mov   ebx,i	;file descriptor (stdout)    mov   eax,4	;system telephone call number (sys_write)    int   0x80	;call kernel 	    mov   ecx,largest    mov   edx, 2    mov   ebx,1	;file descriptor (stdout)    mov   eax,4	;system call number (sys_write)    int   0x80	;call kernel         mov   eax, one    int   80h  section	.data        msg db "The largest digit is: ", 0xA,0xD     len equ $- msg     num1 dd '47'    num2 dd '22'    num3 dd '31'  segment .bss    largest resb 2        

When the above code is compiled and executed, information technology produces the following result −

The largest digit is:  47        

Useful Video Courses


Assembly Programming For All Platforms, Learn To Code

Video

VLSI, PLC, Microcontrollers, and Assembly Language

Video

Source: https://www.tutorialspoint.com/assembly_programming/assembly_conditions.htm

Posted by: gilbertgratting.blogspot.com

0 Response to "What Register Does The Cmp Command Change"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel