CEL-324 Computer Organization and Assembly Language Lab
CEL-324 Computer Organization and Assembly Language Lab
Computer Organization
Tools Used:
Visual Studio
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.
Sign Flag (SF) is set when the result of an arithmetic operation generates negative result. High-order bit
of result.
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
Following table shows a list of jumps based on specific CPU flags values.
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
Mnemonic Description
When we are dealing with signed number than CMP Instruction change the sign, Zero, overflow flag
status.
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
JE Jump if equal(leftop=rightop)
dec:
dec instruction is used for decrementing an operand by one. It works on a single operand that can be
inc:
inc instruction is used for incrementing an operand by one .It works on a single operand that can be
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