0% found this document useful (0 votes)
237 views

Microprocessor Assignment

The document contains details of a student's microprocessor lab assignment, including their name, roll number, and section. It describes experiments performed using 8085 assembly language to load and store values, swap memory locations, perform 8-bit addition with and without carry, and 16-bit addition with carry. Algorithms and assembly code are provided for each experiment.

Uploaded by

Kaustav Mallick
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
237 views

Microprocessor Assignment

The document contains details of a student's microprocessor lab assignment, including their name, roll number, and section. It describes experiments performed using 8085 assembly language to load and store values, swap memory locations, perform 8-bit addition with and without carry, and 16-bit addition with carry. Algorithms and assembly code are provided for each experiment.

Uploaded by

Kaustav Mallick
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

NAME: KAUSTAV MALLICK

ROLL NUMBER: 001710701066

SECTION: G3(UG3)

SUBJECT: MICROPROCESSOR LAB

ELECTRONICS AND TELECOMMUNICATIONS ENGINEERING

Lab Proceeded Under:


Assignment 1: 22/08/19

1. Load the Accumulator with an 8-bit data. (using MVI, LDA)


Store it in a specified register. (using MOV)
Store it in a specified address. (using STA)

LDA: - Load accumulator. (this instruction copies the data from a given 16-bit
address to the accumulator)

Algorithm:
• Reset
• Assign Memory value
• Assign Load Accumulator Hex Code to the destined memory.
• Halt the program
• Execute the program.

Address Mnemonics Hex Code Comments


8150 LDA 8500 3A, (00,85) Load the accumulator with 8-bit data
8153 HLT 76 Stop the program Execution

CONCLUSION: Accumulator returns a garbage value.

MVI: - move immediate date to a register or memory location.


MVI A to use the accumulator register.

Algorithm:
• Reset
• Assign Memory value
• Assign Hex Code for the move immediate data to the accumulator.
• Assign the value to the accumulator in the next bit.
• Halt the program
• Execute the program.

Address Mnemonics Hex Code Comments


8150 MVI A,10 3E, 10 Load the accumulator with 8-bit data
8152 HLT 76 Stop the program Execution
MOV: - This instruction is used to copy the data from one register to another.

Algorithm:
• Reset
• Assign Memory value
• Assign Hex Code for the move immediate data to the accumulator.
• Assign the value to the accumulator in the next bit.
• Copy the value of 8-bit data in Accumulator to B register using MOV.
• Halt the program.
• Execute the program.

Address Mnemonics Hex Code Comments


8150 MVI A,10 3E, 10 Load the accumulator with 8-bit data
8152 MOV B, A 47 Copy the value of 8 bit data into register B from A
8153 HLT 76 Stop the program Execution

STA: - the content of accumulator are copied into the memory location.

Algorithm:
• Reset
• Assign Memory value
• Assign Hex Code for the move immediate data to the accumulator.
• Assign the value to the accumulator in the next bit.
• Use STA to store the content of the accumulator in some memory location.
• Halt the program
• Execute the program.

Address Mnemonics Hex Code Comments


8150 MVI A,10 3E, 10 Load the accumulator with 8-bit data
8152 STA 8500 32 (00,85) Store the value of accumulator at the location
8155 HLT 76 Stop the program Execution
2. SWAP the contents of two memory locations using 8085
programming.

Algorithm:
• Reset
• Assign memory Value
• Assign two values at memory location 8500H and 8501H respectively
• Reset
• Assign some other memory value.
• Load accumulator with the first location of the stored data above.
• Copy accumulator data to register B
• Load accumulator with the next stored data.
• Store the value of the accumulator at the first location.
• Copy the value of Register B into the accumulator.
• Store the value of accumulator into the other location.
• Halt the program.
• Execute.

Address Mnemonics Hex Code Comments


8150 LDA 8500 3A, (00,85) Load the accumulator with 8-bit data
8153 MOV B, A 47 Copy value of accumulator in register B
8154 LDA 8501 3A (01,85) Load accumulator with 8-bit data
8157 STA 8500 32 (00,85) Store the value of accumulator at location
8160 MOV A, B 78 Copy value of register B into accumulator
8161 STA 8501 32 (01,85) Store the value of accumulator at location
8164 HLT 76 Stop the program Execution
3. Perform an 8-Bit Addition (with carry) using 8085.

Algorithm:
• Reset
• Assign Memory
• Initialize the carry as 0
• Load the first 8-bit data into the accumulator
• Copy the contents of accumulator into the register B
• Load the second 8-bit data into the accumulator
• Add the 2 - 8-bit data and check for carry
• Jump on if no carry
• Increment carry if there is
• Store the added request in accumulator
• Move the carry value to accumulator
• Store the carry value in accumulator
• Halt
• Execute

Address Mnemonics Hex Code Comments


8150 MVI C ,00 0E,00 Initialize the carry as zero
8152 LDA 8500 3A, (00,85) Load the accumulator with 8-bit data
8155 MOV B, A 47 Copy value of accumulator in register B
8156 LDA 8501 3A (01,85) Load accumulator with 8-bit data
8159 ADD B 80 Add the two values
815A JNC D2, (5E,81) Jump on if no carry
815D INR C 0C If carry is there increment it by one
815E STA 8502 32 (02,85) Store the value of accumulator at location
8161 MOV A, C 79 Copy value of register C into accumulator
8161 STA 8503 32 (03,85) Store the value of accumulator at location
8164 HLT 76 Stop the program Execution
Input Address Value
8500 04
8501 02

Output Address Value


8502 06
8503 00

Input Address Value


8500 FF
8501 FF

Output Address Value


8502 FE
8503 01

Calculation : 1111 1111


1111 1111
---------------
1111 1110
=========
F E
Assignment 2:
4. Write 8085 ALP to perform 8 bit subtraction with borrow.
-Algorithm –
• Load 00 in a register C (for borrow)
• Load two 8-bit number from memory into registers
• Move one number to accumulator
• Subtract the second number with accumulator
• If borrow is not equal to 1, go to step 7
• Increment register for borrow by 1
• Store accumulator content in memory
• Move content of register into accumulator
• Store content of accumulator in other memory location
• Stop

MEMORY MNEMONICS OPERANDS COMMENT

2000 MVI C, 00 [C] <- 00

2002 LHLD 2500 [H-L] <- [2500]

2005 MOV A, H [A] <- [H]

2006 SUB L [A] <- [A] – [L]

2007 JNC 200B Jump If no borrow

200A INR C [C] <- [C] + 1

200B STA 2502 [A] -> [2502], Result

200E MOV A, C [A] <- [C]

2010 STA 2503 [A] -> [2503], Borrow

2013 HLT Stop


Input

Case 1: Case 2:

Address Data Address Data

8000 78 8000 23

8001 5D 8001 CF

Output

Case 1: Case 2:

Address Data Address Data

8050 1B 8050 54

8051 00 8051 01

5. Write 8085 ALP to perform 16 bit addition with carry.


- Algorithm –
1. Load both the lower and the higher bits of first number at once
2. Copy the first number to another register pair
3. Load both the lower and the higher bits of second number at once
4. Add both the register pairs and store the result in a memory location
Program –
MEMORY ADDRESS MNEMONICS COMMENTS

2000 LHLD 2050 A ← 2050

2003 XCHG D←H&E←L


MEMORY ADDRESS MNEMONICS COMMENTS

2004 LHLD 2052 A ← 2052

2007 DAD D H ← H+D & L ← L+E

2008 SHLD 3050 A → 3050

200B HLT Stops execution

Explanation –
1. LHLD 2050 loads the value at 2050 in L register and that in 2051 in H register
(first number)
2. XCHG copies the content of H to D register and L to S register
3. LHLD 2052 loads the value at 2052 in L register and that in 2053 in H register
(second number)
4. DAD D adds the value of H with D and L with E and stores the result in H and L
5. SHLD 3050 stores the result at memory location 3050
6. HLT stops execution

6. Write a 8085 ALP for 16 bit subtraction with borrow.


-Algorithm –
1. Get the LSB in L register and MSB in H register of 16 Bit number.
2. Exchange the content of HL register with DE register.
3. Again Get the LSB in L register and MSB in H register of 16 Bit number.
4. Subtract the content of L register from the content of E register.
5. Subtract the content of H register from the content of D register and borrow
from previous step.
6. Store the result in memory location.

Program –
MEMORY

ADDRESS MNEMONICS COMMENTS

LHLD

2000 2050 Load H-L pair with address 2050


MEMORY

ADDRESS MNEMONICS COMMENTS

EXCHANGE H-L PAIR WITH D-E

2003 XCHG PAIR

LHLD

2004 2052 Load H-L pair with address 2052

2007 MVI C, 00 C<-00H

2009 MOV A, E A<-E

200A SUB L A<-A-L

200B STA 2054 2054<-A

200E MOV A, D A<-D

200F SBB H SUBTRACT WITH BORROW

2010 STA 2055 2055<-A

2013 HLT TERMINATES THE PROGRAM


Assignment 3:

7. Write 8085 Assembly language program to find the largest and smallest number in
the given array: 02H, 01H, FFH, 04H, 40H, 20H, 50H.

Input Address Data

2050 02

2051 01

2052 FF

2053 04

2054 40

2055 20

2056 50

In CMP instruction:
If Accumulator > Register then carry and zero flags are reset
If Accumulator = Register then zero flag is set
If Accumulator < Register then carry flag is set

Algorithm –
1. Maximum number is stored in B register and minimum in C register
2. Load counter in D register
3. Load starting element in Accumulator, B and C register
4. Compare Accumulator and B register
5. If carry flag is not set then transfer contents of Accumulator to B. Else, compare
Accumulator with C register, if carry flag is set transfer contents of Accumulator
to C
6. Decrement D register
7. If D>0 take next element in Accumulator and go to point 4
8. If D=0, store B and C register in memory
9. End of program
Program-
ADDRESS LABEL INSTRUCTION COMMENT

LXI H,

2000H 2050H Load starting address of list

2003H MOV B, M Store maximum

2004H MOV C, M Store minimum

2005H MVI D, 07H Counter for 10 elements

2007H LOOP MOV A, M Retrieve list element in Accumulator

2008H CMP B Compare element with maximum number

2009H JC MIN Jump to MIN if not maximum

200CH MOV B, A Transfer contents of A to B as A > B

200DH MIN CMP C Compare element with minimum number

200EH JNC SKIP Jump to SKIP if not minimum

Transfer contents of A to C if A <

2011H MOV C, A minimum

2012H SKIP INX H Increment memory

2013H DCR D Decrement counter

2014H JNZ LOOP Jump to LOOP if D > 0

LXI H,

2017H 2060H Load address to store maximum


ADDRESS LABEL INSTRUCTION COMMENT

201AH MOV M, B Move maximum to 2060H

201BH INX H Increment memory

201CH MOV M, C Move minimum to 2061H

201DH HLT Halt

Explanation –
1. One by one all elements are compared with B and C register.
2. Element is compared with maximum, if it greater than maximum then it is stored
in B register. Else, it is compared with minimum and if it is less than minimum
then it stored in C register.
3. Loop executes 10 number of times.
4. At the end of 10 iterations, maximum and minimum are stored at 2060H and
2061H respectively.

8. Write 8085 Assembly language program to transfer N number


of data located from [8050H] to [805AH] TO [8070H] to
[807AH].

-- Program

Address Hex Codes Label Mnemonic Comment

21
8000 Setup HL pair as a pointer for source
50 START: LXI H, 8050H
memory.
80

11
70 Set up DE pair as a pointer for destination
8003 LXI D, 8070H
memory
80

8006 06 MVI B, 0AH Set up B to count 16 bytes


10

8008 7E LOOP: MOV A, M Get data byte from source.

8009 12 STAX D Store data byte as destination

800A 23 INX H Point HL to next source location

800B 13 INX D Point DE to next destination

800C 05 DCR B Decrement count

C2
08 If counter is not 0, go back to transfer next
800D JNZ LOOP
byte.
80

8010 76 HLT Stop

9. Write 8085 Assembly language program to exchange N number of data located


from [9000H] to [900AH] with those at [A000H] to [A00AH] respectively.

-- Program

Address HEX Codes Labels Mnemonics Comments

21

F000 10 LXI H, 8000H Point 8000Hto get byte count

80

F003 4E MOV C,M Load Count from memory

21

F004 10 LXI H,9000H Point first block address

80

F007 11, 10, 90 LXI D,A000H Point second block address


Address HEX Codes Labels Mnemonics Comments

F00A 46 LOOP MOV B, M Take element from first block to B

F00B 1A LDAX D Take element from second block to Acc

F00C 77 MOV M, A Store Acc content to second block

F00D 78 MOV A, B Load B to A

F00E 12 STAX D Store into second block

F00F 23 INX H Point to next address of first block

F010 13 INX D Point to next address of second block

F011 0D DCR C Decrease the count variable

When block is not completed, jump to


F012 C2, 0A, F0 JNZ LOOP
LOOP

F015 76 HLT Terminate the program


Assignment 4:

10. Write 8085 Assembly language program to


multiply two 8-bit numbers and store the 16-bit result
in the memory.

Algorithm –
1. We are taking adding the number 43 seven(7) times in this example.
2. As the multiplication of two 8 bit numbers can be maximum of 16 bits so
we need register pair to store the result.
Program –
MEMORY ADDRESS MNEMONICS COMMENT

2000 LHLD 2050 H←2051, L←2050

2003 XCHG H↔D, L↔E

2004 MOV C, D C←D

2005 MVI D 00 D←00

2007 LXI H 0000 H←00, L←00

200A DAD D HL←HL+DE

200B DCR C C←C-1

200C JNZ 200A If Zero Flag=0, goto 200A


MEMORY ADDRESS MNEMONICS COMMENT

200F SHLD 3050 H→3051, L→3050

2012 HLT

11. Write 8085 Assembly language program to sort a given


array of numbers in ASCENDING ORDER.

Assumption – Size of list is stored at 2040H and list of numbers from 2041H
onwards.
Algorithm –
1. Load size of list in C register and set D register to be 0
2. Decrement C as for n elements n-1 comparisons occur
3. Load the starting element of the list in Accumulator
4. Compare Accumulator and next element
5. If accumulator is less than next element jump to step 8
6. Swap the two elements
7. Set D register to 1
8. Decrement C
9. If C>0 take next element in Accumulator and go to point 4
10. If D=0, this means in the iteration, no exchange takes place consequently we
know that it won’t take place in further iterations so the loop in exited and
program is stopped
11. Jump to step 1 for further iterations
Program –
ADDRESS LABEL INSTRUCTION COMMENT

2000H START LXI H, 2040H Load size of array


ADDRESS LABEL INSTRUCTION COMMENT

2003H MVI D, 00H Clear D register to set up a flag

Set C register with number of

2005H MOV C, M elements in list

2006H DCR C Decrement C

2007H INX H Increment memory to access list

Retrieve list element in

2008H CHECK MOV A, M Accumulator

Increment memory to access next

2009H INX H element

Compare Accumulator with next

200AH CMP M element

JC If accumulator is less then jump to

200BH NEXTBYTE NEXTBYTE

200EH MOV B, M Swap the two elements

200FH MOV M, A

2010H DCX H

2011H MOV M, B

2012H INX H
ADDRESS LABEL INSTRUCTION COMMENT

If exchange occurs save 01 in D

2013H MVI D, 01H register

2015H NEXTBYTE DCR C Decrement C for next iteration

2016H JNZ CHECK Jump to CHECK if C>0

Transfer contents of D to

2019H MOV A, D Accumulator

Compare accumulator contents

201AH CPI 01H with 01H

201CH JZ START Jump to START if D=01H

201FH HLT HALT

12. Write 8085 Assembly language program to sort a given


array of numbers in ASCENDING ORDER.

Program
Address Hexcodes Labels Mnemonics Comments

8000 21, 40, 80 START LXI H, 8040H Pointer to the IN-BUFFER

8003 16, 00 MVI D, 00H The D register is used as a flag register

8005 4E MOV C, M Initialize reg. C with data count

8006 0D DCR C Set Reg. C for comparison count


Address Hexcodes Labels Mnemonics Comments

8007 23 INX H Pointing to the next location

8008 7E CHECK MOV A, M Get the number

8009 23 INX H Go to next location

Compare the contents of the current memory


800A BE CMP M
location with the contents of the accumulator

800B D2, 14, 80 JNC NEXTBYT If (A) >= second byte, do not exchange

800E 46 MOV B, M Get second byte for exchange

800F 77 MOV M, A Store first byte in second location

8010 2B DCX H Point to first location

8011 70 MOV M, B Store second byte in first location

8012 23 INX H Get ready for next comparison

8013 16, 01 MVI D, 01H Load 1 in D as a remainder for exchange

8015 0D NEXTBYT DCR C Decrement comparison count

8016 C2, 08, 80 JNZ CHECK If comparison count not 0, go back

8019 7A MOV A, D Get flag bit in A

801A 0F RRC Place flag bit D0in carry

801B DA, 00, 80 JC START If flag is 1, exchange occurred


Address Hexcodes Labels Mnemonics Comments

801E 76 HLT Terminate the program

Assignment 5:
13. Find the first 7 terms of the Fibonacci series using 8085.
--Algorithm –
1. Initialize register H with 30 and register L with 50, so that indirect memory M
points to memory location 3050.
2. Initialize register B with 00, register C with 05 and register D with 01.
3. Move the content of B in M.
4. Increment M by 1 so that M points to next memory location.
5. Move the content of D in M.
6. Move the content of B in accumulator A.
7. Add the content of D in A.
8. Move the content of D in B.
9. Move the content of A in D.
10. Increment M by 1 so that M points to next memory location.
11. Move the content of A in M.
12. Decrements C by 1.
13. Jump to memory location 200C if ZF = 0 otherwise Halt the program.
Program –
MEMORY ADDRESS MNEMONICS COMMENT

2000 LXI H, 3050 H <- 30, L <- 50

2003 MVI C, 05 C <- 08

2005 MVI B, 00 B <- 00

2007 MVI D, 01 D <- 01

2009 MOV M, B M <- B

200A INX H M <- M + 01


200B MOV M, D M <- D

200C MOV A, B A <- B

200C ADD D A <- A + D

200E MOV B, D B <- D

200F MOV D, A D <- A

2010 INX H M <- M + 01

2011 MOV M, A M <- A

2012 DCR C C <- C – 01

2013 JNZ 200C Jump if ZF = 0

2016 HLT END

14. Assuming that the first term and common difference


are given, find the first 5 terms of an AP series, and
calculate the sum.
The first term (01) is stored in memory location 9000H as input. Common difference (02) is
provided. Program stores the consecutive terms is memory locations starting at 9001H. The
sum of the AP series is stored in 9005H.

Input

Address Data

9000H 01

Program

Address HEX Codes Labels Mnemonics Comments

Store address 9000H in


8000 21, 00, 90 LXI H, 9000H
register pair HL.
8003 06, 02 MVI B, 02H Assign 02 to B.

8005 0E, 04 MVI C, 04H Assign 04 to C.

8007 7E LOOP1 MOV A, M Move content of M in A.

Add content of B and A.


8008 80 ADD B
Store result in A.

8009 23 INX H Increment M by 1.

800A 77 MOV M, A Move content of A in M.

800B 0D DCR C Decrement C by 1.

Jump to memory location


800C C2, 07, 80 JNZ LOOP1
8007 if ZF=0.

800F 16, 04 MVI D, 04 H Assign 04 to D.

8010 2B LOOP2 DCX H Decrement M by 1.

Add content of M and A.


8011 86 ADD M
Store result in A.

8012 15 DCR D Decrement D by 1.

Jump to memory location


8015 C2, 10, 80 JNZ LOOP2
8010 if ZF=0.
Store content of A in
8016 32, 05, 90 STA 9005H
memory location 9005.

8017 76 HLT Terminate the program.

Output

Address Data

9000 01

9001 03

9002 05

9003 07

9004 09

9005 19
15. Find the factorial of a given number using 8085.
Algorithm –
1. Load the data into register B
2. To start multiplication set D to 01H
3. Jump to step 7
4. Decrements B to multiply previous number
5. Jump to step 3 till value of B>0
6. Take memory pointer to next location and store result
7. Load E with contents of B and clear accumulator
8. Repeatedly add contents of D to accumulator E times
9. Store accumulator content to D
10. Go to step 4
ADDRESS LABEL MNEMONIC COMMENT

2000H Data Data Byte

2001H Result Result of factorial

2002H LXI H, 2000H Load data from memory

2005H MOV B, M Load data to B register

2006H MVI D, 01H Set D register with 1

2008H FACTORIAL CALL MULTIPLY Subroutine call for multiplication

200BH DCR B Decrement B


ADDRESS LABEL MNEMONIC COMMENT

200CH JNZ FACTORIAL Call factorial till B becomes 0

200FH INX H Increment memory

2010H MOV M, D Store result in memory

2011H HLT Halt

2100H MULTIPLY MOV E, B Transfer contents of B to C

2101H MVI A, 00H Clear accumulator to store result

2103H MULTIPLYLOOP ADD D Add contents of D to A

2104H DCR E Decrement E

2105H JNZ MULTIPLYLOOP Repeated addition

2108H MOV D, A Transfer contents of A to D

2109H RET Return from subroutine


Assignment 6:
16. Implement 4 programs to convert

1. BCD to HEX
2. HEX to BCD
3. HEX to ASCII
4. ASCII to HEX

1]. Program

HEX
Address Labels Mnemonics Comments
Codes

8000 31, FF, 80 LXI SP,80FFH Initialize stack pointer

8003 21, 00, 90 LXI H, 9000H Pointer to the IN-BUFFER

8006 01, 01, 90 LXI B, 9001H Pointer to the OUT-BUFFER

8009 7E MOV A, M Move the contents of 802BH to A

Subroutine to convert a BCD number to


800A CD, 0F, 80 CALL BCDBIN
HEX

Store Acc to memory location pointed


800D 02 STAX B
by BC

800E 76 HLT Terminate the program

800F C5 BCDBIN PUSH B Saving B

8010 47 MOV B, A Copy A to B

8011 E6, 0F ANI 0FH Mask of the most significant four bits
HEX
Address Labels Mnemonics Comments
Codes

8013 4F MOV C, A Copy A to C

8014 78 MOV A, B Copy B to A

8015 E6, F0 ANI F0H Mask of the least significant four bits

8017 0F RRC Rotate accumulator right 4 times

8018 0F RRC

8019 0F RRC

801A 0F RRC

801B 57 MOV D, A Load the count value to the Reg. D

801C AF XRA A Clear the contents of the accumulator

801D 1E, 0A MVI E, 0AH Initialize Reg. E with 0AH

801F 83 SUM ADD E Add the contents of Reg. E to A

Decrement the count by 1 until 0 is


8020 15 DCR D
reached

8021 C2, 1F, 80 JNZ SUM

8024 81 ADD C Add the contents of Reg. C to A

8025 C1 POP B Restoring B

8026 C9 RET Returning control to the calling program


2]. Program
Address HEX Codes Labels Mnemonics Comments

F000 21, 00, 80 LXI H,8000H Initialize memory pointer

F003 16, 00 MVI D,00H Clear D- reg for Most significant Byte

F005 AF XRA A Clear Accumulator

F006 4E MOV C, M Get HEX data

F007 C6, 01 LOOP ADI 01H Count the number one by one

F009 27 DAA Adjust for BCD count

F00A D2, 0E, F0 JNC SKIP Jump to SKIP

F00D 14 INR D Increase D

F00E 0D SKIP DCR C Decrease C register

F00F C2, 07, F0 JNZ LOOP Jump to LOOP

F012 6F MOV L, A Load the Least Significant Byte

F013 62 MOV H, D Load the Most Significant Byte

F014 22, 50, 80 SHLD 8050H Store the BCD

F017 76 HLT Terminate the program


3]. Algorithm:

1. Load the given data in accumulator and move to B register


2. Mask the most significant 4 bits(upper nibble) of the Hexa decimal number in
accumulator.
3. Call subroutine to get ASCII of least significant 4 bits.
4. Store it in memory
5. Move B register to accumulator and mask the least significant 4 bits(lower nibble).
6. Rotate the upper and lower nibble position.
7. Call subroutine to get ASCII of upper nibble
8. Store it in memory
9. Terminate the program.
Code:
MEMORY ADDRESS MNEMONICS COMMENTS

2000 LDA 2050H Load the hex data

2003 MOV B, A move content of accumulator to B

2004 ANI OFH mask upper nibble

2006 CALL SUB1 get ascii code for upper nibble

2009 STA 2051H

2012 MOV A, B move content of B to accumulator

2013 ANI F0H mask lower nibble

2015 RLC

2016 RLC

2017 RLC

2018 RLC
MEMORY ADDRESS MNEMONICS COMMENTS

2019 CALL SUB1 get ascii code for lower nibble

2022 STA 2052H

2025 HLT

SUB1 CPI 0AH

JC SKIP

ADI 07H

SKIP ADI 30H

RET

4].

Algorithm –
1. Input the content of 2050 in accumulator.
2. Subtract 30H from accumulator.
3. Compare the content of accumulator with 0AH.
4. If content of accumulator is less than 0A then goto step 6 else goto step 5.
5. Subtract 07H from accumulator.
6. Store content of accumulator to memory location 3050.
7. Terminate the program.
Program –
ADDRESS MNEMONICS COMMENTS

2000 LDA 2050 A<-[2050]

2003 SUI 30H A<-A-30

2005 CPI 0AH

2007 JC 200D Check for carry


ADDRESS MNEMONICS COMMENTS

200B SUI 07H A<-A-07H

200D STA 3050 [3050]<-A

2010 HLT Stop execution

Assignment 7:
17. Display a number using LEDs to show the output.
Solution:
Control Word:

D7 D6 D5 D4 D3 D2 D1 D0
1 0 0 0 0 0 0 0 =80H

Program

Address HEX Codes Mnemonics Comments

A000 3E Load the control word,


MVI A, 80H
A001 80 80H into the accumulator

A002 D3
OUT F3H Set port A in the output mode
A003 F3

A004 3E
Load the number to be displayed,
MVI A, 05H
05H into the accumulator
A005 05

A006 D3
OUT F0H Display the number at port A
A007 F0

A008 C3 JMP A006H Unconditional Jump


Address HEX Codes Mnemonics Comments

A009 06

A01A A0

Output:

Four LEDs are connected with the output pins of the chip through a jumper. The first and the third LEDs

were ON while the other LEDs were OFF, i.e. the LEDs displayed the number O5H i.e. 0101. This is

basically, an Infinite loop. That is why the LEDs keep on displaying 05H until the microprocessor is reset.

If we would connect 4 more LEDs for the four most significant bits, these LEDs will remain OFF(this is not
done in the lab exp).

18. Turn a LED ON and OFF periodically.


CONTROL WORD:
D7 D6 D5 D4 D3 D2 D1 D0
1 0 0 0 0 0 0 0 = 80H

Address HEX Codes Mnemonics Comments

A000 3E
MVI A, 80H Load 80H in the accumulator.
A001 80

A002 D3
OUT F3H Set port A in the output mode
A003 F3

A004 3E
MVI A, FFH Load FFH in Accumulator
A005 FF

A006 D3 OUT F0H Show the no at port A


Address HEX Codes Mnemonics Comments

A007 F0

A008 CD CALL DELAY Call delay subroutine

A009 00

A00A B0

AO0B 3E MVI A, 00H Load accumulator with 00H

A00C 00

A00D D3 OUT F0H Show the number at port A

A00E F0

A00F CD CALL DELAY Call delay subroutine

A010 00

A011 B0

A012 C3 JMP

A013 04 Jump Unconditionally

A014 A0

B000 00 MVI B, 92H Load B with 02H for delay counter

B001 02

B002 CD CALL 04DE Call Delay Subroutine

B003 DE

B004 04
Address HEX Codes Mnemonics Comments

B005 05 DCR B Decrease (B)

B006 C2 JNZ Jump to address B002

B007 02

B008 B0

B009 C9 RET Return to main program

Output:

Four LEDs are connected with the output pins of the chip through a Jumper. The LED is turned ON and
OFF periodically. This is basically an Infinite loop. That’s why this cycle repeats until the microprocessor is
reset.

UP Counter:

Address Instruction Opcode Operand

A000 LXI SP, FF00H 31 00, FF

A003 MVI A, 00H 3E 00

A005 PUSH PSW F5

A006 STA FFF9H 32 F9, FF

A009 CALL UPDDT CD D3, 06

A00C MVI B, 02H 06 02

A00E CALL 04BE CD BE, 04

A011 DCR B 05

A012 JNZ A00E C2 OE, 40


A015 POP PSW F1

A016 INR A 3C

A017 JMP A005 C3 05, A0

A018 RST 1

Down Counter:

Address Instruction Opcode Operand


A000 LXI SP, F100H 31 00, F1
A003 MVI A, 99 3E 99
A005 PUSH PSW F5
A006 STA FFF9H 32 F9, FF
A009 CALL UPDDT CD D3, 06
A00C MVI B, 02H 06 02
A00E CALL 04BE CD BE, 04
A011 DCR B 05
A012 JNZ A00E C2 OE, 40
A015 POP PSW F1
A016 ADI 99 C6 99
A018 DAA 27
A018 JMP A005 C3 05, A0
A01A RST 1 CF

You might also like