CEL-324 Computer Organization and Assembly Language Lab
CEL-324 Computer Organization and Assembly Language Lab
CEL-324 Computer Organization and Assembly Language Lab
Computer Organization
Develop procedures and use them to create menu driven programs. All questions will have menus user
will choose the options and programs should process accordingly.
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.
Mnemonic Description
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
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.
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
ret:
used to pops the return address off the stack and returns control to that location
Lab Tasks:
1. Write a program that asks the user to enter number between 0 and 100. The program should
display the appropriate grade using Cmp and jmp.
2. Write a program that gets a string from the user and stores the string in a buffer. Then
scan the string and separate all small alphabets in another buffer. Then print the
buffer.
Hint:
cmp al, 13
JE En
mov [esi], al
inc esi
call scan
scan PROC
mov al,[esi]
cmp al,'a'
JB nope
cmp al, 'z'
JA nope
3. Write two procedures isCapital and isSmall which return true/ false by setting/
clearing carry flag. Use these procedures to separate mixed alphabetic string into two
strings. One containing small letters and other containing capital letters. Display the
result.
Hint:
sa byte 20 DUP(?)
ca byte 20 DUP(?)
inp byte 20 DUP(?)
InpL:
call readchar
call writechar
cmp al,13
JE En
mainL:
mov al,[edx]
clc call isSmall
JC small call isCapital
4. Write procedures IsAlpha and IsDigit. Get character form the user and check whether
that character is alphabet or digit. Use carry flag to return true or false value. Print the
appropriate message.
Hint:
clc
call isaAlpha
jc alpha
call isaDigit
jc digit
5. Write a procedure that is passed two strings and compares them if they are of same
length or not.
Hint:
cmp eax,ebx
jne ex
mov edx, offset msgyes
6. Write a procedure that checks the string if it is palindrome or not.
Hint:
mov al,[esi+edx]
cmp al,[esi+ebx]
jne nope