You are on page 1of 9

EE312: EMBEDDED SYSTEM

LAB ASSIGNMENT-13
~By Arhita Kundu(210102021)

1. Consider the decimal number 14.25 stored in BCD format. Addresses A and (A + 1) respectively store 14 and
25 in BCD. Convert 14.25 to fixed-point representation and store that in addresses B and (B+1). Here, B
stores the integer part (8bits) and (B + 1) stores the fraction part (8bits).
1. Load and Exchange (LHLD 2000, XCHG):

- Load the contents of memory location 2000 into the HL register pair.

- Exchange the contents of the HL register pair with the DE register pair.

2. Initialize H with 30H (MVI H,30H):

- Load immediate value 30H into the H register.

3. Process Integer Part:

- Extract the lower 4 bits of the E register (MOV A,E, ANI 0F).

- Move the result to register B (MOV B,A).

- Extract the higher 4 bits of the E register, rotate right through carry (RRC), and store in register C.

- Repeat the rotation to get the second nibble.

- Add B and C to obtain the hexadecimal value of the integer part.

- Store the result in the memory location pointed by HL (MOV M,A).

4. Process Decimal Part:

- Increment HL to point to the next memory location.

- Similar steps as in the integer part for the D register.

5. Set B and C (MVI B,80, MVI C,00):

- Load immediate values into B and C registers.

6. Initialize Loop Counter (MVI E,08):

- Load immediate value 08 into the E register (loop counter).

7. Start of Loop (LOOP):

- Decrement the loop counter (DCR E).

- If the result is negative, jump to the STORE label.

8. Rotate and Check for Carry (RLC):

- Rotate the accumulator left through carry.

- Compare with 64, and if less, jump to CONTINUE.

9. Subtract 64 (SUI 64):

- Subtract 64 from the accumulator.

- Move the result to E.


10. Update B and C (MOV E,A, MOV A,B, ADD C):

- Move E to A.

- Add C to A and store the result in C.

- Move B to A.

11. Check Zero (JZ STOR_IN_MEM):

- If the accumulator is zero, jump to the STOR_IN_MEM label.

12. Continue Rotation (CONTINUE):

- Move E to A.

- Move B to A, rotate right through carry, and jump back to the LOOP label.

13. Store in Memory (STORE_IN_MEM):

- Store the content of C in the memory location pointed by HL.

14. Halt (HLT):

- Halt the program.

In summary, the code processes a BCD number, converts its integer and decimal parts separately to
hexadecimal, and stores the result in memory. The loop iterates through each digit of the BCD number. The
final hexadecimal result is stored in consecutive memory locations.
2. Read data1 from memory location 2000H. After a delay of around 100ms, data2 from location 2001H. After a
delay of 100ms store the sum of data1 and data2 at 2002H. Explain your approach and delay estimation.

1. Initialize HL and Load D (LXI H,2000, MOV D,M):

- Load immediate value 2000 into the HL register pair.

- Move the content of memory location 2000 to the D register.

2. Call Delay1 and Increment HL (CALL DELAY1, INX H):

- Call a subroutine named DELAY1.

- Increment the HL register pair to point to the next memory location.

3. Load A and Call Delay1 (MOV A,M, CALL DELAY1):

- Move the content of the memory location pointed by HL to the A register.

- Call the DELAY1 subroutine.

4. Increment HL, Add D, and Store in Memory (INX H, ADD D, MOV M,A):

- Increment the HL register pair.

- Add the content of the D register to the accumulator (A).

- Store the result in the memory location pointed by HL.


5. Loop for 100ms (75,188 time cycles) with Delay (DELAY2, MVI B,10H, DELAY1, MVI C,10H, NOP, DCR C, JNZ
DELAY1, DCR B, JNZ DELAY2):

- Set B to 10H (16 in decimal).

- Set C to 10H.

- Execute a delay loop using a nested loop structure.

6. Data and Origin Declarations (# ORG 2000, # DB A, # ORG 2001, # DB 5):

- Declare data at memory location 2000 with value A.

- Declare data at memory location 2001 with value 5.

7. Reset Program Counter to Start Address (# ORG 0000):

- Set the program counter to the start address (0000).

Note: The code involves memory manipulations, subroutine calls, and delay loops. The actual functionality
depends on the specifics of the DELAY1 subroutine and the purpose of the data manipulation.

3. Write a program for 8085 to copy 5 numbers stored from address 2000H to 3000H if the number of ones in
the number is greater than four else copy FF.
1. Initialization (START):

- Set register B to 05H.

- Begin a loop labeled COPY_LOOP to process a sequence of numbers.

2. Processing Loop (COPY_LOOP):

- Load the content of memory into register C.

- Call the subroutine COUNT_ONES to count the number of set bits in the content of C.

- Depending on the count:

- If the count is less than 4, subtract it from a preset value and store the result in memory.

- If the count is 4 or more, set the value to FFH.

- Move to the next element in the sequence.

3. Counting Set Bits (COUNT_ONES):

- Initialize register A to 00.

- Use a loop labeled COUNT_LOOP to count the number of set bits in register C.

- If a set bit is found, increment register D.

- Continue the loop until 8 bits are processed.

- Return the count stored in register D.

4. Data Sequence and Origin Declarations:

- The original data sequence is provided at memory location 2000.

- The data sequence consists of numbers: 01, 03, 60, 71, 50.

4. Someone has damaged a program written at 4050H for 8085 microprocessor. The damage is done by
changing the bit D7 and bit D5 of each byte. The size of the program is 100 bytes. Now write a program for
8085 to correct this damaged program.
1. Set the origin address to memory location 4050H.

2. Initialization:

- Initialize loop counter B to 00H.

- Set the first term of the arithmetic progression (AP) to 01H.

- Set the common difference of the AP to 05H.

3. Arithmetic Progression Generation Loop (AP_LOOP):

- Load the current value of the AP term (C) into register A.

- Store the value of A in the memory location pointed to by HL.

- Increment the HL register pair to point to the next memory location.

- Add the common difference (D) to the current AP term (C).

- Update the AP term (C) with the result.

- Increment the loop counter (B).

- Compare the loop counter with 64H (100 numbers - 1).

- If not equal, jump back to AP_LOOP.

4. Re-initialize Loop Counter (MVI B,64H)

5. Modification Loop (LOOP):

- Load the current value from memory into register A.


- XOR A with 50H.

- Store the result back in the memory location pointed to by HL.

- Increment the HL register pair to point to the next memory location.

- Decrement the loop counter (B).

- If the loop counter is not zero, jump back to LOOP.

6. Halt the program (HLT).

5. Write a code to store the first 15 Fibonacci numbers at address 2000H.

1. Initialization (START):

- Initialize loop counter B to 0FH (15 in decimal).

- Set the content of the memory location pointed to by HL to 00H.

- Increment the HL register pair to point to the next memory location.


- Set the first term of the Fibonacci sequence (C) to 01H.

- Decrement the loop counter (B).

2. Fibonacci Generation Loop (FIBONACCI_LOOP):

- Load the current value from memory into register A.

- Add the first term of the Fibonacci sequence (C) to A.

- Store the result in the memory location pointed to by HL.

- Increment the HL register pair to point to the next memory location.

- Load the first term of the Fibonacci sequence (C) into register A.

- Store the value in the memory location pointed to by HL.

- Increment the HL register pair to point to the next memory location.

- Load the loop counter (B) into register A.

- Decrement the loop counter.

- If the loop counter is not zero, jump back to FIBONACCI_LOOP.

3. Halt the Program (HLT).

You might also like