MICROPROCESSOR LAB Contents: |
Sem 6 >
MPRC LAB
MICROPROCESSOR LAB |
P9 Largest of a series.
Program:
|
P8: Sum of two 16 bit numbers with carry.
This program uses the following instructions which I haven't used in the other ones. Use of LHLD <16bit memory> instruction to load the 16 bit number stored in two separate 8 bit memory locations to the H and L Register. SHLD <16bit memory> for storing ans. Use of DAD rp instruction to add the contents of the H-L pair with the specified Register pair. Use of XCHG instruction to swap values of DE pair and HL pair. PROGRAM:
|
P7: Sort in ascending and descending order
This pic should help. Two loops are there in a bubble sort. One inner loop to go through the elements and push the largest number to the end (while the other numbers like bubbles float towards the top) and the Outer loop which reduce the set of numbers, removing the last largest number from the set.
Four Registers required: A is used as a temporary register while traversing the series. B is used as a temporary register to swap numbers. C is used as the iterator for the outer loop D is used as the iterator for the inner loop Program:
FOR DESCENDING ORDER, USE JNC in place of JC.
|
P6: Division of two 8 bit numbers.
Division.
Clarify the terms Divisor, Dividend, Quotient and Remainder:
Like I explained in multiplication, division is nothing but repeated subtraction. However, the programming is handled differently. In multiplication, the loop continued n number of times (for multiplication m x n). This was done by decrementing the register holding the value n and a condition when it would become zero. (JNZ).
In division however, we need to count the number of possible subtractions/deductions that can take place and therefore we increment a register to record the quotient. And this should be in an unconditional loop(JMP), broken only when the divisor is smaller than the divident. We'll use the accumulator as the dividend which will later hold the remainder once the loop is over.
We need 3 registers in this case.
A for storing the divident, which later holds the remainder.
B for storing the divisor
C for storing the quotient
PROGRAM:
|
P5: Multiplication of two 8 bit numbers.
A little intro before I just type the program. What is multiplication exactly?
Repeated addition of the number.
So if I was to perform 2 x 3, I'd get the answer by adding 2 three times. 2 + 2 + 2.
Take 4 registers. Say A, B, C, D.
A (Accumulator) should store the Product.
B should store the carry, if any.
C should store the first number. (like 2)
D should store the second number. (like 3)
PROGRAM:
RST1 is a software interrupt which can be used by programmers to interrupt the program. Preferred over HLT because that requires a reset using one of the physical buttons of the kit.
|
P4: Larger/Smaller of two 8 bit numbers.
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.
To find the SMALLER of the two numbers, conveniently change the JNC to JC and reverse the meaning altogether.
|
P3: 1's compliment and and 2's compliment of 16 bit number.
1's Compliment. 16 bit numbers. That's the main difference here. Before for 8 bit numbers, we used LDA and STA. LXI H ,2050H Loads BC pair with value 2050H H-> 20H L-> 50H Its similar to 2 MVI instruction ie MVI H,20H MVI L,50H which eventually implies..HL -> 2050H the advantage of LXI over MVI is that LXI is 3 byte and requires 10T states.Two MVI instruction is 4Byte and require 14Tstates... INX increments (and DCX decrements) the 16 bit register pairs H-L pair holds the address of the location pointed by the memory pointer M. M can be used to access the actual values of H-L pair. What I understand is that it shifts the address where the register H is pointing at to the next concurrent memory space. (This way, it can be used to access concurrent data like in an array using LXI H, INX H commands.)
OUTPUT: 2500 FF 2501 FF After execution of program: 2502 00 2503 00 'Cause compliment of the hexadecimal 0 is F. 0000 (0) <==> 1111 (F) 2's Compliment. A condition comes into play in this case. In the previous case of an 8 bit number, we increment the value after complimenting it to get the 2's compliment. But for 16 bit numbers, there are two parts: LSB, MSB. First, we compliment the LSB, then add one to it. (using ADI 01 instead of INR A, so as to affect the carrys for our jump statement to work properly) ADI affects all status flags while INR affects all status flags except the carry flag. Second, if the LSB on getting incremented by 1 yields a carry, that carry should be passed on to the MSB. If no carry is generated, then MSB should not be incremented by 1.
JNC (Jump if Not Carry) label This moves program control to the location specified by the label if there is no carry, (CY = 0). I prefer to think of it this way: If there is a carry, execute the command immediately after. Similarly for JC (JUMP if CARRY) USED usually in the opposite sense. If there is NO carry, execute the command immediately after. OUTPUT: 2500 FF 2501 FF After execution of program: 2502 01 (LSB) 2503 00 (MSB) |
P2: 1's compliment and and 2's compliment of 8 bit number.
ALGO: 2's compliment
|
P0: 8085 Basics
For eg: MOV A,B takes 1 byte (8 bits) of memory. However, LDA 2000H takes 3 bytes since the complete string takes exactly one byte (represented by an opcode later) and each 8 bit operand takes one byte. So, LDA 20 00 = 3 bytes. |
P1: 8085 Program to add/subtract two 8 bit numbers.
ALGO TO ADD:
ALGO TO SUBTRACT:
OUTPUT: (ADD) 2000 01 2001 04 After execution of program: 2003 05 OUTPUT: (SUB) 2000 01 2001 04 After execution of program: 2003 03 Note the first number is stored at Reg B and the second one into Accumulator. Hence, when the SUB B command is executed, the first number is subtracted FROM the second number. The memory address states the location where we are entering the hexadecimal Opcode. After this, we supply the two inputs (to add) at 2000H and 2001H. (Say, 01 is entered at 2000H and maybe 04 is entered at 2001H). The location of the start of the program would be at 2500H) Execute the program at 2500H. And on execution, check the value at location 2002H. (Answer should be 05). Hexadecimal addition even allows the following: 0 B ( 0 11) 1 3 ( 1 03)
___
1 E
|
1-10 of 10