MC Lab Programs
MC Lab Programs
o add the byte in the RAM at 34h and 35h, store the result in
to destination (40h) using Internal-RAM. the register R5 (LSB) and R6 (MSB), using Indirect Addressing Mode.
Q3: Program: Write an ALP To exchange the source block starting with address ORG 0000H
20h, containing N bytes of data with destination block starting with address 40h.
MOV R0, #30H
ORG 0000H MOV R1, #31H
MOV R0, #20H MOV A, @R0
MOV R1, #40H MOV B, @R1
MOV R3, #05H MUL AB
BACK: MOV R0, #32H
MOV A, @R0 MOV R1, #33H
XCH A, @R1 MOV @R0, A
MOV @R0, A MOV @R1, B
INC R0 HERE:
INC R1 SJMP HERE
DJNZ R3, BACK END
HERE: Q8: Write an ALP to perform division operation on 8-bit number by 8-bit number.
SJMP HERE
END ORG 0000H
MOV R0, #30H
Q4:Program: Write an ALP to exchange the source block starting with address
MOV R1, #31H
10h, containing N bytes of data with destination block starting at location 00h.
MOV A, @R0
ORG 0000H MOV B, @R1
MOV R0, #10H DIV AB
MOV R1, #00H MOV 32H, A
MOV R2, #06H MOV 33H, B
MOV DPH, #00H HERE:
BACK: SJMP HERE
MOV DPL, R1 END
MOVX A, @DPTR
XCH A, @R0
MOVX @DPTR, A
INC R0
INC R1
DJNZ R2, BACK
HERE:
SJMP HERE
END
Q9: Write an ALP to separate positive and negative in a given array.
Q11: Write an ALP to arrange the numbers in Ascending & Descending order.
ORG 0000H
MOV R0, #30H ORG 0000H
MOV R3, #05H MOV R0,#30H
MOV R4, #40H MOV R1,#05H
MOV R5, #50H SORT:
LOOP: MOV B,R3
MOV A, @R0 MOV R2,B
JNB ACC.7, POSITIVE PASS:
NEGATIVE: MOV R1,#04H
//MOV R6, A MOV R0,#30H
MOV B, R5 COMPARE:
MOV R1, B MOV A,@R0
MOV @R1, A MOV B,A
INC R5 INC R0
SJMP NEXT MOV A,@R0
POSITIVE: CJNE A,B,CHECK
//MOV R6, A SJMP SKIP
MOV B, R4 CHECK:
MOV R1, B JNC SKIP ;JNC=Ascending AND JC=Descending
MOV @R1, A MOV @R0, B
INC R4 DEC R0
NEXT: MOV @R0, A
INC R0 INC R0
DJNZ R3, LOOP SKIP:
DJNZ R1,COMPARE
HERE: DJNZ R2, PASS
SJMP HERE HERE:
END SJMP HERE
Q10: Write an ALP to separate even or odd elements in a given array.
END
Q12: Write an ALP to find Largest & Smallest number from a given array starting
ORG 0000H
from 20h & store it in Internal Memory location 40h.
MOV R0, #30H
MOV R3, #05H ORG 0000H
MOV R4, #40H MOV R0,#20H
MOV R5, #50H MOV R2,#05H
LOOP: MOV A,@R0
MOV A, @R0 MOV R1,A
JNB ACC.0, EVEN MOV R3,A
ODD: DEC R2
//MOV R6, A LOOP:
MOV B, R5 INC R0
MOV R1, B MOV A,@R0
MOV @R1, A MOV 30H,R1
INC R5
SJMP NEXT CJNE A,30H,COMPARE_MAX
EVEN: SJMP COMPARE_MIN
//MOV R6, A COMPARE_MAX:
MOV B, R4 JC COMPARE_MIN
MOV R1, B MOV R1,A
MOV @R1, A COMPARE_MIN:
INC R4 MOV 35H,R3
NEXT: CJNE A,35H,CHECK_MIN
INC R0 MOV R3,A
DJNZ R3, LOOP SJMP NEXT
HERE: CHECK_MIN:
SJMP HERE JNC NEXT
END MOV R3,A
NEXT:
DJNZ R2,LOOP
MOV 40H,R1
MOV 41H,R3
END
Q13:Write an ALP for Decimal UP-Counter. Q15: Write an ALP for Hexadecimal UP-Counter.