0% found this document useful (0 votes)
111 views

CEL-324 Computer Organization and Assembly Language Lab

The document discusses flags and procedures in assembly language, describing status flags like carry, overflow, zero, and sign flags, and how they are set by arithmetic operations, as well as jump instructions based on specific flag values. It also covers procedures for string manipulation, comparing and reversing arrays, and incrementing/decrementing values using instructions like CMP, INC, DEC. Lab tasks are outlined for students to write assembly code demonstrating the use of procedures, flags, and array/string manipulation.

Uploaded by

Muhammad Osama
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)
111 views

CEL-324 Computer Organization and Assembly Language Lab

The document discusses flags and procedures in assembly language, describing status flags like carry, overflow, zero, and sign flags, and how they are set by arithmetic operations, as well as jump instructions based on specific flag values. It also covers procedures for string manipulation, comparing and reversing arrays, and incrementing/decrementing values using instructions like CMP, INC, DEC. Lab tasks are outlined for students to write assembly code demonstrating the use of procedures, flags, and array/string manipulation.

Uploaded by

Muhammad Osama
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/ 7

CEL-324

Computer Organization

and Assembly Language Lab

Department of Computer Science

Bahria University, Islamabad


Lab # 05: Flags and Procedures
Objectives:

Introduction to Flags and Procedures in assembly Language

Tools Used:

Visual Studio

Specific Flag values

Status Flags

The status flags reflect the outcomes of arithmetic and logical operations performed by the CPU. They
are Overflow, sign, zero, auxiliary carry, carry, parity.

Carry Flag (CF) is set when the result of unsigned arithmetic operation is too large to fit into the
destination.

Overflow Flag (OF) is set when the result of a signed arithmetic operation is too wide to fit into
destination.

Range of 8-, 16-, and 32-bit signed numbers


Size Range
8 bits − 128 to +127
16 bits − 32,768 to +32,767
32 bits −2,147,483,648 to +2,147,483,647

Sign Flag (SF) is set when the result of an arithmetic operation generates negative result. High-order bit
of result.

1 -- Negative signed number.


0 -- positive signed number.

Zero Flag (ZF) is set when the result of arithmetic operation generates a result of zero.

Auxiliary carry Flag is set when an arithmetic operation causes a carry from bit 3 to bit 4 in an 8-bit
operand.

Parity Flag is set when sums the result of bits that are set in a number and indicate whether the sum is
even or odd. Count the number of 1 in binary if it’s odd then PF=0 otherwise its 1.

Example:
Main proc
mov al,255
add al,1
call DumpRegs ; you can also use Debugger to check FLAGS

exit
main endp
In above example

CF=1 ZF=1 AF=1 SF=0 OF =0 PF=1

Following table shows a list of jumps based on specific CPU flags values.

Mnemonics Description Flags

JZ Jump if zero ZF=1

JNZ Jump if not zero ZF=0

JC Jump if carry CF=1

JNC Jump if not carry CF=0

JO Jump if Overflow OF=1

JNO Jump if not overflow OF=0

JS Jump if sign SF=1

JNS Jump if not sign SF=0

JP Jump if parity(even) PF=1

JNP Jump if not parity PF=0

Comparisons of unsigned operands

Jumps based specifically on comparisons of unsigned integer shown in following table


Mnemonic Description

JA Jump if above (if leftOp>rightOp)

JNBE Jump if not below or equal (same as


JA)

JAE Jump if above or equal (if


leftOp>=rightOp)

JNB Jump if not below (same as JAE)

JB Jump if below (if leftOp<rightOp)

JNAE Jump if not above or equal (same as


JB)

JBE Jump if below or equal (if


leftOp_<=rightOp)

JNA Jump if not above (same as JBE)

CMP: The compare instruction performs an implied subtraction of a source operand from the destination
operand. Neither operand is modified. The CMP instruction changes the flag status.

CMP Result ZF CF

Destination<source 0 1

Destination>source 0 0

Destination=source 1 0

Comparisons of signed operands:

Mnemonic Description

JG Jump if greater (if leftOp>rightOp)


JNLE Jump if not less or equal (same as
JG)

JGE Jump if greater than or equal (if


leftOp>=rightOp)

JNL Jump if not less (same as JGE)

JL Jump if less (if leftOp<rightOp)

JNGE Jump if not greater than or equal


(same as JL)

JLE Jump if less than or equal (if


leftOp_<=rightOp)

JNG Jump if not greater (same as JLE)

When we are dealing with signed number than CMP Instruction change the sign, Zero, overflow flag
status.

CMP Result Flags

Destination<source SF≠OF

Destination>source SF=OF

Destination=source ZF=1

Equality comparisons:

These jump instructions based on evaluating either the equality of two operands or the value of cx,ecx.

Syntax

CMP leftop ,rightop


Mnemonics Description

JE Jump if equal(leftop=rightop)

JNE Jump if not equal(leftop≠rightop)

JCXZ Jump if cx=0

JECXZ Jump if ecx=0

dec:

dec instruction is used for decrementing an operand by one. It works on a single operand that can be

either in a register or in memory.

inc:

inc instruction is used for incrementing an operand by one .It works on a single operand that can be

either in a register or in memory.


Lab Tasks:

1. Write a program in which first you display a prompt message “Please enter your name:” on
screen using WriteChar procedure. Then you get the name in a buffer in your program by using
ReadChar procedure. After that you display a greeting “Welcome to Assembly language Lab”
followed by name entered , using WriteChar.’
Hint:
mov ecx, lengthof arr
mov esi, offset arr
l1:
mov al, [esi]
call writechar
inc esi
ret -> used to pops the return address off the stack and returns control to that location.
2. Write a procedure that reverses the given string and stores in another buffer area.
Hint:
dec esi
mov al, [ebx+esi]

3. Write a program to access and print an array of 16 bit integers using base index mode also
print the sum of the array.
Hint:
add al, [ebx+esi]
inc esi
dec ecx
Jnz L1

4. Write a program to access and print the string array using base index mode.
Hint:
inc esi
dec ecx
call writechar
JNZ L1

5. Write a program to reverse an array using base index mode.


Hint:
dec ecx
call writechar
Jnz rev

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy