0% found this document useful (0 votes)
15 views13 pages

Microcontroller Assign PDF

The document contains a series of assembly language programs for the 8051 microcontroller, demonstrating tasks such as LED blinking, sorting arrays in both ascending and descending order, finding the largest and smallest numbers in an array, and reversing a string. Each program includes comments explaining the code structure and functionality. The assignment is submitted by Ruhullah to Dr. Adil Sarwar as part of a course on Microcontroller Systems & Applications.

Uploaded by

bhatiqbal0147
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views13 pages

Microcontroller Assign PDF

The document contains a series of assembly language programs for the 8051 microcontroller, demonstrating tasks such as LED blinking, sorting arrays in both ascending and descending order, finding the largest and smallest numbers in an array, and reversing a string. Each program includes comments explaining the code structure and functionality. The assignment is submitted by Ruhullah to Dr. Adil Sarwar as part of a course on Microcontroller Systems & Applications.

Uploaded by

bhatiqbal0147
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

ASSIGNMENT #1

8051 ASSEMBLY LANGUAGE PROGRAMMING

NAME: RUHULLAH

FACULTY NUMBER: 22EEB513

ENROLL. NUMBER: GN2604

SERIAL NUMBER: 55

SUBJECT : MICROCONTROLLER SYSTEMS & APPLICATION

SUBMITTED TO : DR. ADIL SARWAR


1.Program for LED Blinking using Software Delay o Interface an LED to P1.0
and write a program to blink it with a 500ms delay.

ORG 0000H ; Start of program

MAIN:

MOV P1, #00H ; Clear P1 (Turn off all LEDs)

ACALL DELAY ; Call delay subroutine

SETB P1.0 ; Turn on LED at P1.0

ACALL DELAY ; Call delay subroutine

CLR P1.0 ; Turn off LED at P1.0

SJMP MAIN ; Repeat the process

DELAY:

MOV R0, #200 ; Load R0 with 200 (outer loop count)

DELAY_LOOP1:

MOV R1, #250 ; Load R1 with 250 (inner loop count)

DELAY_LOOP2:

DJNZ R1, DELAY_LOOP2 ; Decrement R1 and loop until R1 = 0

DJNZ R0, DELAY_LOOP1 ; Decrement R0 and loop until R0 = 0

RET ; Return from subroutine

END
2. Program to Sort an Array in Ascending Order o Store a set of
numbers in an array and sort them in ascending order using the Bubble
Sort algorithm.

ORG 0000H ; Start of program

MAIN:

MOV R0, #40H ; Starting address of the array

MOV R1, #09H ; Number of elements in the array - 1

OUTER_LOOP:

MOV A, R1 ; Load R1 into A

MOV R2, A ; Copy A to R2 (inner loop counter)

MOV R3, #00H ; Clear R3 (swap flag)

INNER_LOOP:

MOV A, @R0 ; Load current element into A

INC R0 ; Move to the next element

MOV B, @R0 ; Load next element into B

CJNE A, B, COMPARE ; Compare A and B

COMPARE:

JC NO_SWAP ; If A < B, no swap needed

MOV @R0, A ; Swap A and B

DEC R0

MOV @R0, B

INC R0

MOV R3, #01H ; Set swap flag

NO_SWAP:

DJNZ R2, INNER_LOOP ; Decrement R2 and loop until R2 = 0

CJNE R3, #00H, OUTER_LOOP ; If swap flag is set, repeat outer loop

SJMP $ ; Stop the program

END
3. Program to Sort an Array in Descending Order o Modify the previous
program to sort the array in descending order.

ORG 0000H ; Start of program

MAIN:

MOV R0, #40H ; Starting address of the array

MOV R1, #09H ; Number of elements in the array - 1

OUTER_LOOP:

MOV A, R1 ; Load R1 into A

MOV R2, A ; Copy A to R2 (inner loop counter)

MOV R3, #00H ; Clear R3 (swap flag)

INNER_LOOP:

MOV A, @R0 ; Load current element into A

INC R0 ; Move to the next element

MOV B, @R0 ; Load next element into B

CJNE A, B, COMPARE ; Compare A and B

COMPARE:

JNC NO_SWAP ; If A > B, no swap needed

MOV @R0, A ; Swap A and B

DEC R0

MOV @R0, B

INC R0

MOV R3, #01H ; Set swap flag

NO_SWAP:

DJNZ R2, INNER_LOOP ; Decrement R2 and loop until R2 = 0

CJNE R3, #00H, OUTER_LOOP ; If swap flag is set, repeat outer loop

SJMP $ ; Stop the program

END
4. Program to Find the Largest Number in an Array o Store 10 numbers
in an array and find the maximum value among them.

ORG 0000H ; Start of program

MAIN:

MOV R0, #40H ; Starting address of the array

MOV R1, #0AH ; Number of elements in the array

MOV A, @R0 ; Load first element into A

DEC R1 ; Decrement R1

FIND_MAX:

INC R0 ; Move to the next element

MOV B, @R0 ; Load next element into B

CJNE A, B, COMPARE ; Compare A and B

COMPARE:

JNC NO_UPDATE ; If A > B, no update needed

MOV A, B ; Update A with the larger value

NO_UPDATE:

DJNZ R1, FIND_MAX ; Decrement R1 and loop until R1 = 0

SJMP $ ; Stop the program

END
5. Program to Find the Smallest Number in an Array o Store 10
numbers in an array and find the minimum value among them.

ORG 0000H ; Start of program

MAIN:

MOV R0, #40H ; Starting address of the array

MOV R1, #0AH ; Number of elements in the array

MOV A, @R0 ; Load first element into A

DEC R1 ; Decrement R1

FIND_MIN:

INC R0 ; Move to the next element

MOV B, @R0 ; Load next element into B

CJNE A, B, COMPARE ; Compare A and B

COMPARE:

JC NO_UPDATE ; If A < B, no update needed

MOV A, B ; Update A with the smaller value

NO_UPDATE:

DJNZ R1, FIND_MIN ; Decrement R1 and loop until R1 = 0

SJMP $ ; Stop the program

END
6. Program to Reverse a String o Store a string in memory and write a
program to reverse it.

ORG 0000H ; Start of program

MAIN:

MOV R0, #40H ; Starting address of the string

MOV R1, #50H ; Starting address of the reversed string

MOV R2, #00H ; Clear R2 (length counter)

FIND_LENGTH:

MOV A, @R0 ; Load current character into A

JZ REVERSE ; If A = 0 (null terminator), exit loop

INC R0 ; Move to the next character

INC R2 ; Increment length counter

SJMP FIND_LENGTH ; Repeat until end of string

REVERSE:

DEC R0 ; Move R0 to the last character of the string

MOV A, @R0 ; Load current character into A

MOV @R1, A ; Store character in reversed string location

INC R1 ; Move to the next location in reversed string

DJNZ R2, REVERSE ; Decrement R2 and loop until R2 = 0

SJMP $ ; Stop the program

END

You might also like