Embedded System Journal
Embedded System Journal
1
Aim: Write a program to perform Addition of two 8 bits numbers.
Theory: The program's objective is to perform the addition of two 8-bit numbers using the
DYNA-8051 Trainer Kit. The given algorithm outlines the steps involved in achieving this task.
It initializes registers, fetches numbers from memory, performs additions, checks for carry,
increments registers as needed, and stores the final result in memory. The program stops after
completing the addition process.
Algorithm:
1) Initialize RI with 00
2) Initialize DPTR with C100
3) Move content pointed by location in DPTR to Reg A
4) Move content of A to R2
5) Increment DPTR
6) Move content pointed by location in DPTR to Reg A
7) Add content of A and R2
8) Move contents of A to R2
9) Increment DPTR
10) Check for carry, if no carry go to step no. 12
11) If cary increment R
12) Move content of RI to A
13)Move content of A to location posted by DPTR 3
14) Move R2 to A
15) Incremem DPTR
16) Move content of A to location pointed by DPTR
17) Stop.
Result:
C001
C003
C004
C009 ADD A, R2
C00D
C00E INC R1
C011 MOV A, R2
C014 RET
Practical No. 2
Aim: Write a program to perform Addition of two 16 bits numbers.
Theory: The program aims to add two 16-bit numbers using the DYNA-8051 Trainer Kit. It
follows a step-by-step algorithm to accomplish this task. The program initializes registers,
fetches numbers from memory, performs additions, checks for carry, increments registers or
memory pointers accordingly, and finally stores the result in memory. The program terminates
once the addition process is complete.
Result:
D000 D000
D001 D001
D002 D002
D003 D003
C000 CLR C
C002
C004
C005
C011 MOV A, R1
C012 ADD A, R3
C014 MOV A, R2
C015 ADDC A, R4
C016 MOV R6, A
C017 JNC HERE
C018
C019 INC R7
C01A HERE : INC DPTR
C01B MOV A, R7
C01C MOV X @ DPTR, A
C01D INC DPTR
C01E MOV A, R6
C01F MOVX @ DPTR, A
C020 INC DPTR
C021 MOV A, R6
C022 MOVX @ DPTR, A
C023 RET
Practical No. 3
Aim: Write a program to perform nibble separation of a 8 bit number.
Requirement: DYNA-8051 Trainer Kit
Theory: The program aims to perform nibble separation of an 8-bit number. It initializes
registers, retrieves the 8-bit number from memory, performs bitwise operations to extract the
high and low nibbles, and stores them in separate registers. The program then terminates.
Algorithm:
1) Load the 8-bit number in accumulator.
2) Move contents of accumulator to R2.
3) AND contents of accumulator with OFOH.
4) Swap the contents of accumulator.
5) Move contents of accumulator to Ro
6) Move contents of R₂ to accumulator
7) AND contents of accumulator with OFH.
8) Move contents of accumulator to R
9) Stop.
Result:
R1
Accumulator 92H
R2 92H
Code:
C001
C003
C005
C006 SWAP A
C008
C009 MOV A, R2
C00A
C00C
C00E
C00F MOV A, R2
C010
C012
C013 RET
Practical No. 4
Aim: Write a program to perform nibble separation of a 16 bit number.
Requirement: DYNA-8051 Trainer Kit
Theory: The program aims to perform nibble separation of a 16-bit number. It follows a step-
by-step algorithm to accomplish this task. The program initializes registers, retrieves the 16-bit
number from external memory, performs bitwise operations to extract the high and low nibbles
of each byte, and stores them in separate registers. The program then terminates.
Algorithm:
1) Initialize register R7 with 00H.
2) Load the value DO00H into the DPTR register.
3) Read the value at the memory location pointed by DPTR and store it in the accumulator.
4) Move the value from the accumulator to register R1.
5) Increment DPTR to point to the next memory location.
6) Read the value at the updated memory location pointed by DPTR and store it in the
accumulator.
7) Move the value from the accumulator to register R2.
8) Read the value at the next memory location pointed by DPTR using MOVX instruction
and store it in the accumulator.
9) Move the value from the accumulator to register R3.
10) Increment DPTR to point to the next memory location.
11) Read the value at the updated memory location pointed by DPTR using MOVX
instruction and store it in the accumulator.
12) Move the value from the accumulator to register R4.
13) Add the values in registers R1 and R3 using the ADD instruction and store the result in
the accumulator.
14) Move the value from the accumulator to register R5.
15) Add the values in registers R2 and R4, along with the carry flag, using the ADC
instruction and store the result in the accumulator.
16) Move the value from the accumulator to register R6.
17) Check if there was no carry generated during the addition operation using the JNC
instruction.
18) If there was no carry, increment register R7.
19) Move the value from register R7 to the accumulator.
20) Increment DPTR to point to the next memory location.
21) Move the value from the accumulator to the memory location pointed by DPTR.
22) Increment DPTR to point to the next memory location.
23) Move the value from register R5 to the accumulator.
24) Move the value from the accumulator to the memory location pointed by DPTR.
25) Check if there was no carry generated during the addition operation using the JNC
instruction.
26) If there was no carry, move the value from register R6 to the accumulator.
27) Move the value from the accumulator to the memory location pointed by DPTR.
28) Return from the subroutine
Result:
R7 00H R7 01H
DPTR D000H DPTR D002H
Accumulator Accumulator
R0
R0
R1 D000H
R1
R2 D001H
R2 R3 D002H
R3 R4 D003H
R4 R5
R5 R6
R6
Code:
C002
C003
C004
C007
C00B
C00E
C00F
C013
C014
C015 ADD A, R3
C016
C017 MOV R5, A
C018
C019 MOV A, R2
C01A
C01B ADC A, R4
C01C
C01D MOV R6, A
C01E
C01F JNC Next
C020
C021
C022 NEXT INC R7
C023 MOV A, R7
C024
C025 INC DPTR
C026 MOVX @DPTR, A
C027 INC DPTR
C028 MOV A, R5
C029
C02A MOVX @DPTR, A
C02B JNC Next2
C02C
C02D
C02E Next2 MOV A, R6
C02F
C030 MOVX @DPTR, A
C031 RET
Practical No. 5
Aim: Write a program to sort numbers in descending order
Requirement: DYNA-8051 Kit
Algorithm:
1) Initialize the number of elements counter
2) Initialize the number of comparison counter
3) Compare the elements. If first element > second element, go to step 8 else go to step 4
4) Swap the elements
5) Decrement the comparison counter
6) Is count=0? If yes, go to step 8 else go to step 4
7) Insert the number in proper position
8) Increment the elements counter
9) Is count=N? Is yes, go to step 11 else go to step 2
10) Store the result
11) Stop.
Theory: The program's objective is to arrange a set of numbers in descending order using the
DYNA-8051 Kit. It begins by initializing the counters for the number of elements and
comparisons. It then compares the elements and swaps them if necessary to ensure the largest
element is in the proper position. The comparison counter is decremented, and the process
repeats until all elements have been compared and arranged. Finally, the sorted result is stored,
and the program terminates
Result:
Before Execution After Execution
C002
C003
C004
C007
C00B
C00E
C00F
C013
C014
C015 ADD A, R3
C016
C017 MOV R5, A
C018
C019 MOV A, R2
C01A
C01B ADC A, R4
C01C
C01D MOV R6, A
C01E
C01F JNC Next
C020
C021
C022 NEXT INC R7
C023 MOV A, R7
C024
C025 INC DPTR
C026 MOVX @DPTR, A
C027 INC DPTR
C028 MOV A, R5
C029
C02A MOVX @DPTR, A
C02B JNC Next2
C02C
C02D
C02E Next2 MOV A, R6
C02F
C030 MOVX @DPTR, A
C031 RET
Practical No. 6
Aim: Write a program to sort numbers in ascending order
Requirement: DYNA-8051 Kit
Algorithm:
1) Initialize the number of elements counter
2) Initialize the number of comparison counter
3) Compare the elements. If first element < second element, go to step 8 else go to step 4
4) Swap the elements
5) Decrement the comparison counter
6) Is count=0? If yes, go to step 8 else go to step 4
7) Insert the number in proper position
8) Increment the elements counter
9) Is count=N? Is yes, go to step 11 else go to step 2
10) Store the result
11) Stop.
Theory: The program's objective is to sort numbers in ascending order using the DYNA-8051
Kit. It follows a specific algorithm that involves comparing pairs of elements, swapping them if
necessary, and inserting the numbers in their proper positions. The algorithm uses counters to
keep track of the number of elements and comparisons. The program terminates once the sorting
process is completed.
Result:
Before Execution After Execution
MOV A, @DPTR
DEC DPL
MOVX @ DPTR, A
MOV A, R0
INT DPTR
MOVX @ DPTR, A
Here DJNZ R6, Jump
MOV A, R5
MOV R6, A
DJNZ R7, up
RET
MOV DPTR, # D000 H
MOVX A, @ DPTR
DEC A
MOV R5, A
MOV R6, A
MOV R7, A
C008 Up MOV DPTR, # D000 H
C00B Jump MOVX A, @ DPTR
MOV R0, A
INC DPTR
MOV A, @DPTR
CLR C
SUBB A, R0
JNC HERE
MOVX @DPTR, A
DEC DPL (82H)
MOVX @DPTR, A
MOV A, R0
INC DPTR
MOVX @DPTR, A
C01A HERE DJNZ R6, JUMP
MOV A, R6
MOV R6, A
DJNZ R7,UP
RET
Practical No. 7
Aim: Write a program for serial addition
Requirement: DYNA-8051 Kit
Algorithm:
1) Initialize counter at D000H
2) Initialize DPTR with D000H
3) Move the content at location of DPTR to Accumulator
4) Move content of Acc to R1
5) Initialize DPTR with D001H
6) Initialize Acc to 0
7) Move content of Acc to R2
8) Move content of Acc to RO
9) Move content of DPTR to Acc
10) Add contents of Acc and RO
11) Check for carry
12) If carry, increment R2
13) Increment DPTR
14) Decrement and jump if R1 not zero to Step 8
15) Move content of Ace to R7
16) Move content of R2 to Ace
17) Move content of Acc to location pointed by DPTR
18) Increment DPTR
19) Move R7 to Acc
20) Move content of Acc to location pointed by DPTR
21) Stop
Theory: The program aims to perform serial addition using the DYNA-8051 Kit.
It follows a specific algorithm to add numbers in a sequential manner. The
algorithm involves initializing registers and memory addresses, retrieving and
manipulating data, performing additions with carry checks, and storing the results
in memory. The program terminates once the addition process is completed.
Result:
Before Execution After Execution
D000 Count __
D000
Code:
MOV A, R2
MOV X @DPTR, A
INT DPTR
MOV A, R7
MOVX @ DPTR, A
RET