PROGRAM-1-SUM OF "N" NUMBERS:-
LDA 4200H
MOV C, A : Initialize counter
SUB A : sum = 0
LXI H, 420l : Initialize pointer
BACK:ADD M : SUM = SUM + data
INX H : increment pointer
DCR C : Decrement counter
JNZ BACK : if counter 0 repeat
STA 4300H : Store sum
HLT : Terminate program execution
PROGRAM-2:-
MOV C, A : Initialize counter
LXI H, 4201H : Initialize pointer
SUB A :Sum low = 0
MOV B, A : Sum high = 0
BACK: ADD M : Sum = sum + data
JNC SKIP
INR B : Add carry to MSB of SUM
SKIP: INX H :Increment pointer
DCR C : Decrement counter
JNZ BACK : Check if counter 0 repeat
STA 4300H : Store lower byte
MOV A, B
STA 4301H : Store higher byte
HLT :Terminate program execution
PROGRAM-3-SORTING THE ELEMENTS OF THE ARRAY:-
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-4-COUNT THE NUMBER OF 1's IN A STRING:-
MVI B, 00H
MVI C, 08H
MOV A, D
BACK: RAR
JNC SKIP
INR B
SKIP: DCR C
JNZ BACK
HLT
PROGRAM-5-FIND THE SQUARE ROOT:-
LDA 4200H : Get the given data(Y) in A register
MOV B,A : Save the data in B register
MVI C,02H : Call the divisor(02H) in C register
CALL DIV : Call division subroutine
to get initial value(X) in D-reg
REP: MOV E,D : Save the initial value in E-reg
MOV A,B : Get the dividend(Y) in A-reg
MOV C,D : Get the divisor(X) in C-reg
CALL DIV : Call division subroutine
to get initial value(Y/X) in D-reg
MOV A, D : Move Y/X in A-reg
ADD E : Get the((Y/X) + X) in A-reg
MVI C, 02H : Get the divisor(02H) in C-reg
CALL DIV : Call division subroutine to
get ((Y/X) + X)/2 in D-reg.This is XNEW
MOV A, E : Get Xin A-reg
CMP D : Compare X and XNEW
JNZ REP : If XNEW is not equal to X, then repeat
STA 4201H : Save the square root in memory
HLT : Terminate program execution
Subroutine Program:
DIV: MVI D, 00H : Clear D-reg for Quotient
NEXT: SUB C : Subtract the divisor from dividend
INR D : Increment the quotient
CMP C : Repeat subtraction until the
JNC NEXT : divisor is less than dividend
RET : Return to main program
PROGRAM-6-SQUARE OF THE GIVEN NUMBER:-
- 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
PROGRAM-7-SUM OF ODD NUMBERS:-
LDA 2200H
- MOV C, A : Initialize counter
- LXI H, 2201H : Initialize pointer
- MVI E, 00 : Sum low = 0
- MOV D, E : Sum high = 0
- BACK: MOV A, M : Get the number
- ANI 0lH : Mask Bit 1 to Bit7
- JZ SKIP : Don't add if number is even
- MOV A, E : Get the lower byte of sum
- ADD M : Sum = sum + data
- MOV E, A : Store result in E register
- JNC SKIP
- INR D : Add carry to MSB of SUM
- SKIP: INX H : Increment pointer
PROGRAM-8-TO ADD TWO 8-BIT DATA
LDA 000
MOV B,A
LDA 001
MVI C,00
ADD B
JNC AHEAD
INR C
[lab1] STA 002
MOV A,C
STA 003
HLT
PROGRAM-9- TO ADD TWO 8-BIT DATA PRESENT IN THE MEMORY
LXI H,000
MVI C,OO
MOV A,M
INX H
ADD M
JNC LAB1
INR C
[LAB1] INX H
MOV M,A
INX H
MOV M,C
HLT
LHLD 000
XCHG
LHLD 002
XRA A
DAD D
JNC LAB1
INR A
[LAB1] SHLD 004
STA 006
HLT
LDA 002
MOV B,A
LDA 000
SUB B
STA 004
LDA 003
MOV B,A
LDA 001
SBB
STA 005
HLT
PROGRAM-12-TO ADD TWO 2-DIGIT BCD DATA:-
LDA 000
MOV B,A
LDA 001
MIV C,00
ADD D
DAA
JNC LAB1
INR C
[LAB1] STA 002
MOV A,C
STA 003
HLT
LDA 000
MOV B,A
LDA 002
MVI C,00
ADD B
DAA
STA 004
LDA 001
MOV B,A
LDA 003
ADC B
DAA
STA 005
JNC GO
INR C
[GO] MOV A,C
STA 006
HLT
PROGRAM-14-TO MULTIPLY TWO NUMBERS OF 8-BIT DATA:-
LXI H,000
MVI C,00
XRA A
MOV B,M
INX H
MOV D,M
[REPT] ADD D
JNC GO
INR C
[GO] DCR B
JNZ REPT
INX H
MOV M,A
INX H
MOV M,C
HLT
PROGRAM-15-TO MULTIPLY TWO NUMBERS OF 16-BIT DATA:-
LHLD 000
SPHL
LHLD 002
XCHG
LXI H,000
LXI B,000
[NEXT] DAD SP
JNC AHED
INX B
[AHED] DCX D
MOV A,E
ORA D
JNZ NEXT
SHLD 004
MOV L,C
MOV H,B
SHLD 006
HLT
PROGRAM-16-TO DIVIDE TWO NUMBERS OF 8-BIT DATA
LDA 001
MOV B,A
LDA 000
MVI C,00
[AGO] CMP B
JC STORE
SUB B
INR C
JMP AGO
[STO] STA 003
MOV A,C
STA 002
HLT
LXI H,000
MOV B,M
MVI C,00
XRA A
[REPT] INX H
ADD M
JNC AH1
INR C
[AH1] DCR B
JNZ REPT
STA 100
MOV A,C
STA 101
HLT
PROGRAM-18-TO SEARCH SMALLEST DATA IN THE ARRAY:-
LXI H,000
MOV B,M
INX H
MOV A,M
DCR B
[LOOP] INX H
CMP M
JC AHED
MOV A,M
[AHD] DCR B
JNZ LOOP
STA 100
HLT
LXI H,000
MOV B,M
INX H
MOV A,M
DCR B
[LOOP] INX H
CMP M
JNC AHED
MOV A,M
[AHED] DCR B
JNZ LOOP
STA 100
HLT
LDA 000
MOV B,A
DCR B
[LOP2] LXI H,100
MOV C,M
DCR C
[LOP1] INX H
MOV A,M
INX H
CMP M
JC AHD1
MOV D,M
MOV M,A
DCX H
MOV M,D
JMP AHED
[AHD1] DCX H
[AHED] DCR C
JNZ LOP1
DCR B
JNZ LOP2
HLT
PROGRAM-21-TO SORT AN ARRAY OF DATA IN DESCENDING ORDER
LDA 000
MOV B,A
DCR B
[LOP2] LXI H,100
MOV C,M
DCR C
[LOP1] INX H
MOV A,M
INX H
CMP M
JNC AHD1
MOV D,M
MOV M,A
DCX H
MOV M,D
JMP AHED
[AHD1] DCX H
[AHED] DCR C
JNZ LOP1
DCR B
JNZ LOP2
HLT
PROGRAM-22-TO FIND THE SQUARE ROOT OF AN 8-BIT BINARY NUMBER
LDA 000
MOV B,A
MVI C,02
CALL DIV
[REPT] MOV E,D
MOV A,M
MOV C,D
CALL DIV
MOV A,D
ADD E
MVI C,02
CALL DIV
MOV A,E
CMP D
JNZ REPT
STA 001
HLT
[DIV] MOV D,00
[NEXT] SUB C
INR D
CMP C
JNC NEXT
RET
LDA 000
MOV E,A
ANI F0
RLC
RLC
RLC
RLC
MOV B,A
XRA A
MVI C,0A
[REPT] ADD B
DCR C
JNZ REPT
MOV B,A
MOV A,E
ANI 0F
ADD B
STA 100
HLT
PROGRAM-24-TO CONVERT 8-BIT BINARY NUMBER TO BCD
MVI E,00
MOV D,E
LDA 000
[HUND] CPI 64
JC TEN
SUI 64
INR E
JMP HUND
[TEN] CPI 0A
JC UNIT
SUI 0A
INR D
JMP TEN
[UNIT] MOV C,A
MOV A,D
RLC
RLC
RLC
RLC
ADD C
STA 250
MOV A,E
STA 251
HLT
PROGRAM-25-TO CONVERT 8-BIT BINARY TO ASCII
LDA 000
MOV B,A
ANI 0F
CALL CODE
STA 001
MOV A,B
ANI F0
RLC
RLC
RLC
RLC
CALL CODE
STA 002
HLT
[CODE] CPI 0A
JC SKIP
ADI 07
[SKIP] ADI 30
RET
PROGRAM-26-TO CONVERT ASCII CODE' TO BINARY VALUE
LXI H,000
MOV D,M
LXI B,100
[LOOP] INX H
MOV A,M
CALL BIN
STAX B
INX B
DCR D
JNZ LOOP
HLT
[BIN] SUI 30
CPI 0A
RC
SUI 07
RET
ALL THE BEST!!!!!!
No comments:
Post a Comment