SBN

Conditionals and Jump Instructions

Introduction

This article will briefly discuss conditionals and jump instructions. Conditionals are commonly used in assembly for comparison so that other instructions can make use of the output resulting from these. Jump instructions in assembly are a way to permanently transfer the execution to another instruction located at a different memory address. 

Let us explore how all these concepts fit together in assembly, specifically x86.

What are conditionals?

Making a decision based on the result of a comparison operation is possible in any programming language. Assembly is no different, and it is possible to make comparisons and make decisions based on the comparisons in assembly language too. 

TEST and CMP are the instructions that are commonly used for comparison in x86, and these instructions are known as conditionals.

TEST instruction

The TEST instruction computes the bitwise logical AND of first operand and the second operand. According to the result, the status flags SF, ZF and PF will be set.

 It should be noted that the TEST instruction doesn’t make any changes to the operands used with the instruction. The following is an example of a TEST instruction.

Example: TEST EAX, EAX

CMP instruction

The CMP instruction is another example of conditionals. A CMP instruction performs a subtract operation on both operands, and the status flags ZF and CF will be set according to the result. 

It should be noted that the CMP instruction also does not affect the operands. When the destination operand and source operand are equal, ZF will be set to 1. If the destination operand is less than the source operand, CF will be set to 1. In all the remaining conditions, the respective flags will be set to 0. 

Following is an example of CMP instruction.

Example: CMP EAX, 1

Let’s see (Read more...)

*** This is a Security Bloggers Network syndicated blog from Infosec Resources authored by Srinivas. Read the original post at: http://feedproxy.google.com/~r/infosecResources/~3/1GOaglTr16k/