0% found this document useful (0 votes)
804 views4 pages

Assembly Language Conditional Processing

This document discusses conditional loop and conditional structure instructions in assembly language. It explains the LOOPZ, LOOPE, LOOPNZ and LOOPNE instructions, which perform a loop if certain conditions regarding the zero flag and ECX register are met. It then provides examples of implementing conditional logic using assembly language instructions like CMP, JA, JNA, JBE, and others. It shows how to translate pseudocode involving conditional expressions like if-else statements into equivalent assembly code segments.

Uploaded by

Mr hacks
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
804 views4 pages

Assembly Language Conditional Processing

This document discusses conditional loop and conditional structure instructions in assembly language. It explains the LOOPZ, LOOPE, LOOPNZ and LOOPNE instructions, which perform a loop if certain conditions regarding the zero flag and ECX register are met. It then provides examples of implementing conditional logic using assembly language instructions like CMP, JA, JNA, JBE, and others. It shows how to translate pseudocode involving conditional expressions like if-else statements into equivalent assembly code segments.

Uploaded by

Mr hacks
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Islamic University – Gaza

Engineering Faculty
Department of Computer Engineering
ECOM 2025: Assembly Language Discussion

Chapter 6 (Part b)
Conditional Processing

Eng. Eman R. Habib


April, 2014
2 Assembly Language Discussion

6.4 Conditional Loop Instructions


 LOOPZ and LOOPE Instructions
- The LOOPZ (loop if zero) instruction works just like the LOOP instruction except that it
has one additional condition: the Zero flag must be set in order for control to transfer to
the destination label. The syntax is:
LOOPZ destination
- LOOPE (Loop if Equal) instruction is equivalent to LOOPZ.
- They perform the following tasks:
ECX = ECX - 1
if ECX > 0 and ZF = 1, jump to destination

 LOOPNZ and LOOPNE Instructions


- The LOOPNZ (loop if not zero) instruction is the counterpart of LOOPZ. The loop
continues while the unsigned value of ECX is greater than zero (after being
decremented) and the Zero flag is clear. The syntax is:
LOOPNZ destination
- LOOPNE (Loop if Not Equal) instruction is equivalent to LOOPNZ.
- They perform the following tasks:
ECX = ECX - 1
if ECX > 0 and ZF = 0, jump to destination

 Section 6.4 Review

1. (True/False): The LOOPE instruction jumps to a label when (and only when) the Zero
flag is clear.
2. (True/False): The LOOPNZ instruction jumps to a label when ECX is greater than zero
and the Zero flag is clear.

6.5 Conditional Structures


 Section 6.5 Review
Notes: In all compound expressions, use short-circuit evaluation. Assume that val1 and X are
32-bit variables.

1. Implement the following pseudocode in assembly language:

if ebx > ecx then


X = 1

cmp ebx,ecx
jna next
mov X,1
next:
3 Assembly Language Discussion

2. Implement the following pseudocode in assembly language:

if edx <= ecx then


X = 1
else
X = 2

cmp edx,ecx
jnbe else
mov X,1
jmp next
else: mov X,2
next:

3. Implement the following pseudocode in assembly language:

if( val1 > ecx ) AND ( ecx > edx ) then


X = 1
else
X = 2;

cmp val1,ecx
jna else
cmp ecx,edx
jna else
mov X,1
jmp next
else: mov X,2
next:

4. Implement the following pseudocode in assembly language:

if( ebx > ecx ) OR ( ebx > val1 ) then


X = 1
else
X = 2

cmp ebx,ecx
ja L1
cmp ebx,val1
ja L1
mov X,2
jmp next
L1: mov X,1
next:
4 Assembly Language Discussion

5. Implement the following pseudocode in assembly language:

if( ebx > ecx AND ebx > edx) OR ( edx > eax ) then
X = 1
else
X = 2

cmp ebx,ecx ; ebx > ecx?


jna L1 ; no: try condition after OR
cmp ebx,edx ; yes: is ebx > edx?
jna L1 ; no: try condition after OR
jmp L2 ; yes: set X to 1
;-----------------OR(edx > eax) ------------------------
L1: cmp edx,eax ; edx > eax?
jna else ; no: set X to 2
L2: mov X,1 ; yes:set X to 1
jmp next ; and quit
else: mov X,2 ; set X to 2
next:

 Best Wishes 

You might also like