Microprocessor Lab Programs


_____________________________________

Separation of even numbers from given no's

Source program :
  • LXI H, 2200H : Initialize memory pointer l
  • LXI D, 2300H : Initialize memory pointer2
  • MVI C, 32H : Initialize counter
  • BACK:MOV A, M : Get the number
  • ANI 0lH : Check for even number
  • JNZ SKIP : If ODD, don't store
  • MOV A, M : Get the number
  • STAX D : Store the number in result list
  • INX D : Increment pointer 2
  • SKIP: INX H : Increment pointer l
  • DCR C : Decrement counter
  • JNZ BACK : If not zero, repeat
  • HLT : Stop





 _____________________________________________________


Find the largest of given numbers

Source program :
  • LDA 2200H
  • MOV C, A : Initialize counter
  • XRA A : Maximum = Minimum possible value = 0
  • LXI H, 2201H : Initialize pointer
  • BACK: CMP M : Is number> maximum
  • JNC SKIP : Yes, replace maximum
  • MOV A, M
  • SKIP: INX H
  • DCR C
  • JNZ BACK
  • STA 2300H : Store maximum number
  • HLT : Terminate program execution

Sample problem 1:
 
(2200H) =  04
(2201H) = 34H
(2202H) = A9H
(2203H) = 78H
(2204H) =56H
Result = (2202H) = A9H

_____________________________________________________________________________________
  
Arrange in ascending order :

Source program :
  • MVI B, 09 : Initialize counter     
  • START : LXI H, 2200H: Initialize memory pointer
  • MVI C, 09H : Initialize counter 2
  • BACK: MOV A, M : Get the number
  • INX H : Increment memory pointer
  • CMP M : Compare number with next number
  • JC SKIP : If less, don't interchange
  • JZ SKIP : If equal, don't interchange
  • MOV D, M
  • MOV M, A
  • DCX H
  • MOV M, D
  • INX H : Interchange two numbers
  • SKIP:DCR C : Decrement counter 2
  • JNZ BACK : If not zero, repeat
  • DCR B : Decrement counter 1
  • JNZ START
  • HLT : Terminate program execution
_____________________________________________________________________________________

Program to generate Fibonacci number

Source program :
  • MVI D, COUNT : Initialize counter
  • MVI B, 00 : Initialize variable to store previous number
  • MVI C, 01 : Initialize variable to store current number
  • MOV A, B :[Add two numbers]
  • BACK: ADD C :[Add two numbers]
  • MOV B, C : Current number is now previous number
  • MOV C, A : Save result as a new current number
  • DCR D : Decrement count
  • JNZ BACK : if count  0 go to BACK
  • HLT : Stop.
_____________________________________________________________________________________

    Data transfer from one memory block to other memory block.

    • LXI H, 4150 : Initialize memory pointer
    • MVI B, 08 : count for 8-bit
    • MVI A, 54
    • LOOP : RRC
    • JC LOOP1
    • MVI M, 00 : store zero it no carry
    • JMP COMMON
    • LOOP2: MVI M, 01 : store one if there is a carry
    • COMMON:  INX H
    • DCR B : check for carry
    • JNZ LOOP
    • HLT : Terminate the program
     _____________________________________________________________________________________


    Add contents of two memory locations

    Source program:

    LXI H, 4000H :HL Points 4000H
    MOV A, M :Get first operand
    INX H :HL Points 4001H
    ADD M :Add second operand
    INX H :HL Points 4002H
    MOV M, A :Store the lower byte of result at 4002H
    MVIA, 00 :Initialize higher byte result with 00H
    ADC A :Add carry in the high byte result
    INX H :HL Points 4003H
    MOV M, A :Store the higher byte of result at 4003H
    HLT :Terminate program execution

    Sample problem:
     
    (4000H) = 7FH
    (400lH)  = 89H
    Result   = 7FH + 89H = lO8H (4002H) = 08H
    (4003H) = 0lH
     ______________________________________________________________________________________