You are on page 1of 5

EE312: EMBEDDED SYSTEM

LAB ASSIGNMENT-12
~By Arhita Kundu (210102021)

Q1. Develop an 8085 assembly code to find the first 'n' prime numbers and save them in memory
starting from address 2000H.

1. Load the H register with the address 2000H.


2. Move the immediate value 01H to the B register.
3. Load the accumulator with the content at memory address 4000.
4. Start a loop to find and store prime numbers:
- Store the accumulator value at memory address 4000H.
- Call a subroutine named `IS_PRIME`.
- Jump to `NOT_PRIME` if the carry flag is set.
- Move the content of register B to register A.
- Move the content of register A to the memory location pointed by the HL register.
- Increment the HL register.
- Load the accumulator with the content at memory address 4000H.
- Decrement the accumulator and jump to `FIND_PRIMES` if not zero.
5. Label for the case when the number is not prime.
- Increment the B register.
6. Halt the program.
7. Subroutine `IS_PRIME`:
- Copy the content of register B to registers D and E.
- Start a loop (L2) with the content of register D.
- Inner loop (L1) to compare and subtract B from D until zero.
- If not zero, jump to `LABEL`.
- Compare the accumulator with zero and jump to `SKIP`.
- Increment register C.
- Skip to `SKIP`.
- Move the content of register E to register A.
- Decrement register D.
- If not zero, jump to L2.
- Move the content of register C to register A and return from the subroutine.
Q2. Create an 8085 assembly code to execute division operations on 8-bit integer numbers. The outcome
should be stored in 16-bit fixed-point representation with 8 bits for the integer part and 8 bits for the
decimal part.

1. Load the accumulator with the content at memory address 4000H.


2. Move the accumulator content to register C.
3. Load the accumulator with the content at memory address 4001H.
4. Call a subroutine named `DIV_LOOP`.
5. Store the remainder at memory address 4004H.
6. Move the content of register D to the accumulator.
7. Store the quotient at memory address 4002H.
8. Load the remainder from memory address 4004H into the accumulator.
9. Move the content of register D to register H.
10. Move immediate value 64H to register E.
11. Move immediate value 00H to register A.
12. Start a loop labeled as `ADD`:
- Add the content of register E to the accumulator.
- Decrement register H, and if not zero, jump to `ADD`.
13. Call a subroutine named `DIV_LOOP`.
14. Store the remainder at memory address 4005H.
15. Move the content of register D to the accumulator.
16. Store the quotient at memory address 4003H.
17. Halt the program.
18. Subroutine `DIV_LOOP`:
- Move the content of register A to register L (Dividend).
- Move immediate value 00H to register D (Set Quotient to 0).
- Start a loop labeled as `SUB`:
- Move the content of register L to the accumulator.
- Subtract the content of register C.
- Move the result back to register L.
- Increment register D (Increment quotient).
- Compare with the content of register C.
- If no carry (JNC), jump to `SUB`.
- Return from the subroutine (`RET`).

Q3. Implement an assembly code to perform a 1-D convolution operation. The input array consists of 10
elements and is located in memory addresses beginning at 2000H. The two-element kernel is stored at
3000H and 3001H. The resulting array should be stored in memory starting at addresses 4000H.


1. Load HL register with the address 2000H.

2. Load the accumulator with the content at memory address 3000H.

3. Move the accumulator content to register B.

4. Load the accumulator with the content at memory address 3001H.

5. Move the accumulator content to register C.

6. Move immediate value 0AH to register E.

7. Add the content of register C to the accumulator.

8. Start a loop labeled as `LOOP`:

- Load the content at the memory address pointed by HL into the accumulator.

- Copy the content of register B to register D.

- Add the content of register A to the accumulator.

- Decrement register D, and if not zero, jump to `MULTIPLY_BY_B`.

- Move immediate value 40 to register H.

- Increment register H.

- Load the content at the memory address pointed by HL into the accumulator.

- Start a multiplication loop labeled as `MULTIPLY_BY_B`:

- Copy the content of register B to register D.

- Add the content of register A to the accumulator.

- Decrement register D, and if not zero, jump to `MULTIPLY_BY_B`.

- Move immediate value 40 to register H.

- Decrement register H.

- Decrement register E, and if not zero, jump to `LOOP`.

9. Add twice the content of register B to the accumulator.

10. Halt the program.

11. The code snippet after `#ORG 2000H` appears to be data storage with the following values: 01, 02, 09, 04, 07, 06,

08, 03, 02.

You might also like