You are on page 1of 3

Source program 1:

MVI B, Data#1 ; Data #1 is stored in register B MOV C, B ; Copy of Data #1 is made in register C MVI D, Data#2 ; Data #2 is stored in register D MOV E,D ; Copy of Data #2 is made in register E XRA A ; Accumulator content is cleared Again: ADD B DCR C JNZ Again ] MOV H,A ; Calculated A2 value is stored in register H XRA A ; Accumulator content is cleared Loop: ADD D DCR E ] ]

} A2 is calculated by repeated Addition

} B2 is calculated by repeated Addition

JNZ Loop ] ADD H ; A2+ B2 is determined, by adding result in A and register content H

Stepper Motor Control Program:


6000H Excite code DB 03H, 06H, 09H, OCH : This is the code sequence for clockwise rotation

Subroutine to rotate a stepper motor clockwise by 360 - Set the counts:


MVI C, 32H : Set repetition count to 50 START: MVI B, 04H : Counts excitation sequence LXI H, 6000H : Initialize pointer BACK1: MOV A, M : Get the Excite code OUT PORTA : Send Excite code CALL DELAY : Wait INX H : Increment pointer DCR B : Repeat 4 times JNZ BACK l

Delay Subroutine:

Delay: LXI D, Count Back: DCX D MOV A, D ORA E JNZ Back RET

Find the square of given number


Source program :

LXI H, 6200H : Initialize lookup table pointer LXI D, 6100H : Initialize source memory pointer LXI B, 7000H : Initialize destination memory pointer BACK: LDAX D : Get the number MOV L, A : A point to the square MOV A, M : Get the square STAX B : Store the result at destination memory location INX D : Increment source memory pointer INX B : Increment destination memory pointer MOV A, C CPI 05H : Check for last number JNZ BACK : If not repeat HLT : Terminate program execution

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

You might also like