Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
34 views

Source Program 1

The document contains code for several programs: 1) A program to calculate the sum of squares of two numbers by repeatedly adding them in registers. 2) A subroutine to rotate a stepper motor clockwise by 360 degrees by sending an excitation code sequence 50 times. 3) A subroutine to delay the main program by decrementing a counter in a loop. 4) A program to store the squares of numbers in a lookup table and copy them to another memory location. 5) A program to arrange an array of numbers in ascending order by comparing and interchanging adjacent numbers in a loop.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Source Program 1

The document contains code for several programs: 1) A program to calculate the sum of squares of two numbers by repeatedly adding them in registers. 2) A subroutine to rotate a stepper motor clockwise by 360 degrees by sending an excitation code sequence 50 times. 3) A subroutine to delay the main program by decrementing a counter in a loop. 4) A program to store the squares of numbers in a lookup table and copy them to another memory location. 5) A program to arrange an array of numbers in ascending order by comparing and interchanging adjacent numbers in a loop.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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