Sem 6‎ > ‎MPRC LAB‎ > ‎

P4: Larger/Smaller of two 8 bit numbers.

posted Mar 29, 2013, 6:30 AM by Neil Mathew   [ updated Mar 29, 2013, 6:32 AM by Neil Mathew ]

Since the basic idea is understood, I am now directly writing the programs now.
Finding the LARGER of the two 8 bit numbers. the CMP would perform the following:

@2001 - @2000
reg A - reg B

So, if @2001 is greater, no carry. However, if @2001 is NOT greater, a carry/borrow is generated.

So, if carry/borrow is generated, then reg B is greater, and therefore, move the value of B back to A and print or store A as the greater of the two. 
if carry/borrow is not generated, reg A is already the greater and is directly stored as greater of two.

A condition is required to perform the underline if there is a carry/borrow.

The compare instruction (CMP) in the 8085 subtracts the two operands but does not store the results. What it does do is set flags, in particular, zero, negative, carry, parity, and auxillary carry, so you can follow up the instruction with a conditional branch or call instruction to perform some operation based on the comparison of those two numbers.



 
 LDA 2000H

 
 MOV B,A

 
 LDA 2001H

 
 CMP B

 
 JNC GO

 
 MOV A,B

 GO
 STA 2002H



IF THERE IS CARRY, MOVE CONTENT OF B TO A.
OTHERWISE, JUMP TO GO, AND STORE CONTENTS OF A.



To find the SMALLER of the two numbers, conveniently change the JNC to JC and reverse the meaning altogether.


 
 LDA 2000H

 
 MOV B,A

 
 LDA 2001H

 
 CMP B

 
 JC GO

 
 MOV A,B

 GO
 STA 2002H



IF THERE IS NO CARRY, MOVE CONTENT OF B TO A.
OTHERWISE, JUMP TO GO, AND STORE CONTENTS OF A.



JNC : LARGER
JC   : SMALLER

Comments