Sei sulla pagina 1di 66

MICRO PROCESSOR AND

MICRO CONTROLLER
REPORT

Submitted by:
Niraj Kachariya: 151020011011
Priyank Joshi: 151020011016

Submitted To:
Jatin Upadhyay

`
(3) Write an assembly language program to load Accumulator with
data byte 82H and store that data in register B.
Assume that initially all the registers are reset.

Flowchart:

Start

Load Accumulator
with 82H

Move that data to


register B

Stop

Code:

Memory
Mnemonics Hex code Remark
Location
C000 MVI A,82 H 3E Load accumulator with 82 H
C001 82
C002 MOV B,A 47 Store the data of Accumulator in register B
C003 RST 1 CF Halt the program

Registers Status:
Before the execution
A = 00H
B =00H
Flag CY =0

`
After the execution
A = 82H
B = 82H
Flag CY =0

(4) Write an ALP to load A0H in the Accumulator, decrement the


accumulator and store that data to the memory location F120H.
Flowchart:

Start

Load Accumulator
with A0 H

Decrement the
Accumulator

Store the data of


Accumulator to memory
location F120 H

Stop

`
Code:

Memory
Mnemonics Hex code Remark
Location
C000 MVI A,A0 H 3E Load accumulator with A0 H
C001 A0
C002 DCR A 3D Decrement the register A.
Store the data of accumulator to the F120 memory
C004 STA F120H 32
location
C005 20
C006 F1
C007 RST 1 CF Halt the program

Registers Status:
Before the execution
A = 82 H
B = 82 H
Flag CY =0

After the execution


A = A0 H
B = 82 H
Flag CY =0
Memory location F120 H: 9F H

(5) Write an ALP to store the data of the Accumulator to the


memory location that is indicating by another register pair.

Registers Status:
Before the execution
A = A0 H
B = 82 H
Flag CY =0
Memory location F120 H: 9F H

`
After the execution
A = A0 H
B = F1 H
C = 20 H
Flag CY =0
Memory location F120 H: A0 H

Flowchart:

Start

Load register B
with data F1 H

Load register C
with data 20 H

Store the data of the Accumulator to


the memory location F120 H specified
by the register pair BC.

Stop

`
Code:

Memory Hex
Mnemonics Remark
Location code
C000 MVI A,A0 3E Load accumulator with A0 H
C001 A0
C002 LXI B ,F120 01 Load register pair B with F120 H
C003 20
C004 F1
Move the data of Accumulator to the memory location specified
C005 STAX B 02
by the BC register pair.
C008 RST 1 CF Halt

(6) Write an ALP to load register B with data byte that is stored at
the memory location, where memory location is stored in the HL
pair register.

Flowchart:

Start

Load immediate the register


pair HL with the data

Move the data of the Accumulator to the memory


specified by the address location of HL register pair.

Load register B
with the data byte

Stop
`
Code:

Memory
Mnemonics Hex code Remark
Location
C000 MVI A,A0 3E Load register A with A0
C001 A0
C002 LXI H,E000 21 Load register pair H at location E000
C003 00
C004 E0
C005 MOV M,A 77 Move data of accumulator to memory location of HL
Copy the data to register B specified by the memory
C006 MOV B,M 46
address location of HL register pair
C007 RST 1 CF Halt

Registers Status:
Before the execution
A = A0 H
B = F1 H
C = 20 H
H = 00 H
L = 00H
Flag CY =0

After the execution


A = A0 H
B = A0 H
C = 20 H
H = E0 H
L = 00H
Flag CY =0
Memory location E000 H: A0 H

`
(7) Write an assembly language program to compliment any
number without using CMA instructions.

Flowchart:

Start

Load Accumulator
with FF H

Load Reg. B with


10 H

Subtract register B with


Register A and store that data
in Accumulator

Stop

Code:

Memory
Mnemonics Hex code Remark
Location
C000 MVI A,FF H 3E, FF Load accumulator with FF H
C002 MVI B,10 H 06, 10 Load reg. b with FF H
Substract value of Ragister B with Ragister A and
C004 SUB B 90
store data in Accumulator
C006 RST 1 CF Halt

`
Registers Status:
Before the execution
A = A0 H
B = A0 H
Flag CY =0

After the execution


A = FFH
B = 10 H
Flag CY =0

VALUE IN ACCUMULATOR : EF

(8) Write an assembly language program to exchange the data of


two registers without using the XCHG instructions.
Flowchart:

Start

LOAD data in register A,B,C


with 01,02,03 respectively

Move data of
register B to A

Move data of
register B to C

`
Stop
Code:

Memory Location Mnemonics Hex code Remark


C000 MVI A,01 4F Load register A with 01
C002 MVI B,02 50 Load register B with 02
C004 MVI C,03 Load register C with 03
Move data of register C to
C006 MOV A,C 7A
accumulator A
C007 MOV C,B 41 Move data of register B to C
C008 RST 1 CF

Registers Status:
Before the execution
A = 01H
B = 02H
C = 03 H
Flag CY =0

After the execution


A = 03 H
B = 02 H
C = 02H
Flag CY =0

(9) Write an assembly language program to load 16 bit data to the


HL and 16 bit data immediately to the DE register pair, exchange
the data of HL and DE using the XCHG instruction and store HL
pair register data to E004 H and store data of DE pair register data
to location E006 H.

`
Flowchart:

Start

Load HL register pair


immediate with data

Load BC register pair


data immediate
immediate

Exchange the data of HL


and DE register pair

Store H and L registers


data direct to the
memory location E004

Store D and E registers


data direct to the
memory location E006

Stop

Code:

Memory
Mnemonics Hex code Remark
Location
C000 LXI H,1122 21 Load register pair HL immediate
C003 LXI D,2233 11 Load register pair DE immediate

`
C006 XCHG EB Exchange the data of HL and DE register pair
Store the data of HL register pair to the
C009 SHLD E004H 22
memory location pointed by E004H
Again exchange the data of register pair HL
C00A XCHG EB
and DE
Store the data of HL register pair to the
C00F SHLD E006H 22
memory location pointed by E006H
C012 RST 1 CF Halt

Registers Status:
Before the execution
H = 00
L = 00
D = 00
E = 00
Flag = 0

After the execution


H = 11H
L = 22H
D = 22H
E = 33H
Memory location E004 H: 2233 H
Memory location E006 H: 1122 H

(10) Write an assembly language program to copy the data of


C250H to E310H using the HL register pair and LHLD/LXI
instruction set.
Flowchart: Assume that the data A5H is stored at the memory location C250H.

`
Start

Load HL register pair direct


using LHLD instruction

Store HL register pair data direct to


the memory location specified

Stop
Code:

Memory
Mnemonics Hex code Remark
Location
Copy the data contents of the memory location to the
C000 LHLD C250H 2A
HL register pair
Store the data contents of the HL register pair to the
C003 SHLD E310H 22
memory location specified
C005 RST 1 CF

Registers Status:
Before the execution
H = 11H
L = 22H
Flag = 0

After the execution


H = A5 H
B = 00 H
Flag CY =0
Memory location C250 H: A5 H

`
Memory location E310 H: A5 H

(11) Write an assembly language program to load Accumulator with


9AH. After that rotate the accumulator left and right.

Flowchart:

Start

Load Accumulator
with 9A H

Rotate the accumulator left with the


help of instruction code.

Rotate the accumulator right with


the help of instruction code.

Stop

Code:

Memory
Mnemonics Hex code Remark
Location
C000 MVI A,9A H 3E 01 Load accumulator with 9A H
C002 RLC 07 Rotate the accumulator data left
C004 RRC 0F Rotate the accumulator right
C006 RST 1 CF

`
Registers Status:
Before the execution
A = 9A H
Flag CY =0

After the execution


When Accumulator rotated left:
A = 35 H
Flag CY =1
When Accumulator rotated right:
A = 5A H
Flag CY= 0

Final Result:
A = 5A H
Flag CY = 0

(12) Write an assembly language program to set carry flag and load
the accumulator with data A8H. After that rotate the accumulator
left and right through carry.
Assume initially that the carry flag is set to 1 OR we can set the carry flag register by the
instruction code “CMC”.

Flowchart:
Start

Complement the carry

Load Accumulator
with A8 H

`
Rotate the accumulator
left through carry

Rotate the accumulator


right through carry

Stop

Code:

Memory Location Mnemonics Hex code Remark


C000 MVI A,A8 H 3E 01 Load accumulator with 01 H
C002 RAL 17 Rotate the accumulator through carry left
Rotate the accumulator through carry
C004 RAR 1F
right
C008 RST 1 CF

Registers Status:
Before the execution
A = 5A H
Flag CY = 1

After the execution


When Accumulator is rotated left through carry
A = 51
Flag CY = 1

When accumulator is rotated right through carry


`
A = A8 H
Flag CY = 1

(13) Write an assembly language program to load two values x and


y. If x>y then store 01 H data at D000H memory location and if x<y
then store 10 H value at D000H memory location.
Flowchart:

Start

Load two values x and y in


register A and B

Compare x and y using


compare instructions

NO YES

Jump on instruction Jump on instruction


if x>y (JNC) if x<y (JC)

Store 01 H to D000 H Store 10 H to D000 H


memory location memory location

Stop Stop

`
Code:

Memory
Mnemonics Hex code Remark
Location
C000 MVI A,11 H 3E Load accumulator with 11 H
C002 MVI B,22 H 06 Load reg. b with 22 H
Compare the data of accumulator with the data of
C004 CMP B B8
register B
C005 JC CA00 DA Jump on carry, the conditional statement
C007 JNC CB00 D2 Jump on no carry, the conditional statement
CA00 MVI D,01 H 16 A<B then store 01 H in the register D
CA02 MOV A,D 7A Move the data of register D to Accumulator
Copy the data of accumulator to memory location
CA03 STA D000H 32
specified
CA06 RST 1 CF
CB00 MVI D,10 H 16 A>B then load 10 H in register D
CB02 MOV A,D 7A Move the data of register D to accumulator
Copy the contents of the accumulator to the memory
CB03 STA D000H 32
location specified
CB06 RST 1 CF

Registers Status:
Before the execution
A = A5 H
B = 03 H
D = 22 H
Flag CY =0

After the execution


A = 10 H
B = 22 H
D = 10 H
Flag CY = 1
Memory location D000: 10 H

`
(14) Write an assembly language programme for addition operation
for two 8 bit numbers stored in memory location D101 H and D102
h. Store the result at D103 H.
Flowchart :

Start

Load Accumulator
DATA

STORE DATA IN
MEMORY
LOCATION

ADD B IN
ACCUMULATOR

MOVE ACCUMULATOR DATA INTO B&C


RAGISTER PAIR

STORE DATA IN
MEMORY
LOCATION

Stop

`
CODE :
Memory
Mnemonics Hex code Remark
Location
C000 MVI A,01 H 3E,01 Load accumulator with 01 H
C002 STA D101H 32,01,D1 Store Accumulator data in location D101H
C005 MVI A,02H 3E,02 Load accumulator with 02 H
C007 STA D102H 32,D1,02 Store Accumulator data in location D102H
C00A LDA D101 3A,01,D1 Copy data from location to accumulator
C00D MOV B,A 47 Move content of A into B
C00E LDA D102 3A,02,D1 Copy data from location to accumulator
C011 MOV C,A 4F Move content of A into C
C012 ADD B 80 ADD B in accumulator
C013 STA D103 32,03,D1 Store accumulator data in location D103
C016 RST 1 CF STOP

Result:
D101H = 01H
D102H = 02H
D103H = 03H
(16)Write an assembly language programme to subtract two 8 bit
numbers.
Flowchart :

Start

Load Register A
and B

Substract B

STOP

`
CODE :
Memory
Mnemonics Hex code Remark
Location
C000 MVI A,02 H 3E, 02 Load accumulator with 02 H
C002 MVI B,01 H 06, 01 Load reg. b with 01 H
Substract value of Ragister B with Ragister A and store
C004 SUB B 90
data in Accumulator
C005 RST 1 CF Halt

Result :
Accumulator : 01H
(17) Write an assembly language programme for 1’s and 2’s
compliment of any 8 bit number using CMA instruction.
Flowchart:

Start

Load Register A

Use Instruction
CMA

INR A

`
Code :
Memory Location Mnemonics Hex code Remark
C000 MVI A,02 H 3E, 02 Load accumulator with 02 H
C002 CMA 2F 1’S Compliment Of A
C003 INR A 3C Incriment in A
C006 RST 1 CF Halt

Result :
1’s Compliment : FD H
2’s Compliment : FE H
(18) Write an ALP for logical operation of any data. (Logical
operations: AND ,OR, XOR, NOT)
Flow chart :

Start

Load Register A &


B

Logical
Operations

Stop

`
Code :
Memory
Mnemonics Hex code Remark
Location
C000 MVI A,11 H 3E, 11 Load accumulator with 11 H
C002 MVI B,10 H 06, 10 Load reg. b with 10 H

C004 ANA,ANI,XRA,XRI,ORA,ORI Logical Operations

C006 RST 1 CF Halt

Result :
ANA Operation : A=10H
ANI Operation : ANI 01 ;A=01H
ORI Operation : ORI 10 ; A=11H
ORA Operation : A=11H
XRA Operation : A=01H
XRI Operation : XRI 10;A=01H
19. Write an ALP to mask off most significant four bits.

Start

Load accumulator
with 55H

And operation of 0F H
with Accumulator

Stop

`
Code:
Memory Location Mnemonics Remark

C000 MVI A,55 H Load accumulator with 55H

C002 ANI OF H And operation of 0F H with


Accumulator

Register status
A=55 H

After the execution


A=05 H

20. Write an ALP to transfer the block of data to another memory


location. For ex. Sixteen bytes of data are stored in memory location
XX10 H to XX1F H. Transfer the entire block of data to new
memory location starting at XX30 H.

Start

Load L with data 10H

Load DD10 H to pair


B, C

Load DD30 H to pair


D, E

Move 00 H to A

`
Load data of B, C pair
to A

Store the data of A to


D, E pair

Increase the B, C pair

Increase the D, E pair

Decrement L

Jump on non zero

Stop

Code
Memory Location Mnemonics Remark

C000 MVI L,10 H Load L with data 10 H

C002 LXI B, DD10 H Load DD10 H to pair B, C

C005 LXI D, DD30 H Load DD30 H to pair D, E

C008 MVI A,00 H Move 00 H to

C00A LDAX B Load data of B, C pair to A

C00B STAX D Store the data of A to D, E pair

C00C INX B Increase the B, C pair

`
C00D INX D Increase the D, E pair

C00E DCR L Decrement L

C00F JNZ C00A Jump on non zero

Registers status
L=10 H
C=10 H
B= DD H
E=30 H
D=DD H
After the execution
Data of DD10 H= Data of DD30 H
Data of DD11 H= Data of DD31 H
Like….
Data of DD1F=Data of DD3F

21 Write an ALP to multiply two 8 bit data stored in different


memory location. Store the result in E001 H memory location.

Move 8 bit number to


register E

Move 8 bit number to


register B

`
Load counter with the
number of register B

Load A with 00 H

Add E

DCR C

JNZ

Stop

Code
Memory Location Mnemonics Remarks
C000 MVI E, 55 H Move 8 bit number to register E

C002 MVI B, 03 H Move 8 bit number to register B

C004 MOV C, B Load counter with the number


of register B

C005 MVI A, 00 H Load A with 00 H

C007 ADD E Adding number of register E


with number of A

C008 STA E001 H Store data of A to E001 H

C00B DCR C Decrementing c

`
C00C JNZ C007 Jump on non zero

Registers status
E= 55 H
B= 03 H
C=03 H
A=00 H
After the execution
E=55 H
B= 03 H
C=00 H
A= FF H
AC =1
22 Write an ALP to multiply 16 bit number with 8 bit multiplier.
Store the result at D000 H memory location.

Start

Load H-L pair with


any address

Load multiplier in
register C

Load A with 00 H

`
Add M

Decrement C

Jump on Non Zero

Stop

Memory Location Mnemonics Remarks


C000 LXI H, 000F H Load H-L pair with
Add. 000F
C003 MVI C, 02H Load register c with
02 H
C005 MVI A, 00H Load accumulator
with 00 H
C007 ADD M Adding M
C008 STA D000 Store data of answer
to location D000 H
C00B DCR C Decrementing C
C007 JNZ C006 Jump on non zero

`
Registers status
H= 00 H
L= 0F H
C=02 H
A= 00 H
After the execution
H= 00 H
L= 0F H
C=00 H
At Location EEEE= 001D H
C=0

23. Write an ALP for division of two 8 bit numbers stored in


different memory location. Store the quotient at E000 H and
reminder at E001 H memory location

Start

Load register C
with 00 H

Load register B with the number


from which we have to divide

`
Load A with the Number that we have to
divide

Compare B with A

If carry is present If carry is not present

Subtract B

Increment C

Store the data of A at


E001

Store the data of C at


E000

Stop
Code
Memory location Mnemonics Remarks
C000 MVI C, 00H Load C with 00 H
C002 LDA D000 H Load A with the data
of D000

`
C005 MOV B,A Move data of A to B
C006 LDA D001H Load A with the data
of D001
C009 CMP B Compare B with A
C00A JC C012 If carry jump in L2
C00D SUB B Subtract B
C00E INR C Increment A
C00F JMP C009 Jump on L1
C012 STA E001 H Save data of A to
E001 H
C015 MOV A,C Move data of C to A
C016 STA E000 H Store data of A to
E000 H

Registers status
If data at D000 is 0B H
And Data at D001 is 18 H
B=0B H
A= 18 H
C= 00 H
After the execution
A =02 H (2)
C=02 H (2)

`
26. Write an ALP to find the number of odd and even numbers from
the given 10 8-bit numbers.

Start

Load H-L pair with any


address

Load 00 H in register C

Load B with 00 H

Load D with 0A H

( 10)

Decrement C

Move the data of M to


A

Rotate the data of


A through Carry
If carry is not there

If carry is there

`
Increment B Increment C

Increment pair H-L

Decrement D

Jump on Non zero

Stop
Code
Memory Location Mnemonics Remark
C000 LXI H,FF00 Load H-L pair with
data of address FF00
C003 MVI D,0A H Load D with 0A H
C005 MVI C,00 H Load C with 00 H
C007 MVI B, 00 H Load B with 00 H
C009 MOV A,M Move data of M to A
C00A RRC Rotate right through
carry
C00B JC C012 Jump on carry
C00E INR B Increment B
C00F JMP C013 Jump on
C012 INR C Increment c
C013 INX H Increment H-Lpair

`
C014 DCR D Decrement D
C015 JNZ C009 Jump on Non Zero

Register Status
B=00 H
C=00H
D=0A H
After Execution
If there are 5 even and five odd numbers in memory location FF00 H to
FFFF H
B=05 H
C=05 H
D=00 H

27. Write an ALP to find the biggest number in array of five 8 bit
data.

Start

Load H-L pair with


any address

Load C with 05 H

`
Load A with 00 H

Decrement C

Move data of M to A

Increase the data Of H-L


pair

Compare M

If carry is there

Move data of M to A

Decrement C

Jump on non zero

Store the data to any


location

Stop

`
Code
Memory Mnemonics Remarks
Location
C000 LXI H, Load data of D000 in H-L pair
D000H
C003 MVI C,05 Load C with 05 H
H
C005 MVI A, 00 Load A
H
with 00 H
C007 MVI B,00 Load B with 00 H
H
C009 MOV A,M Move data of M to A
C00A DCR C Decrement c
C00B INX H Increment pair H-L
C00C CMP M Compare M
C00D JC C010 Jump on Carry
C010 MOV A,M Move data of memory to A
C011 JMP C014 Jump
C014 DCR C Decrement c
C015 JNZ C00A Jump on non zero
C018 STA FFFF Store to FFFF

Register Status

`
C=05 H
A=00H
B=00H

After execution
C=00H
At location FFFF biggest number among the location D000 to D005 is
saved

24. Data bytes are stored in memory locations from XX50 H


to XX5F H. To insert an additional five bytes of data, it is
necessary to shift the data string by five memory locations.
Write an assembly language programme to store the data
string from XX55 H to XX64 H and add new additional five
element 8 bit array at XX50 H.

Start

Initialize register pair H,


L with location D05F H

Initialize register pair D,


E with location D064 H

Load counter with 0F H

Move the data of


`
memory to Accumulator
If zero flag is 1

Initialize register pair H,


L with location E000 H

Initialize register pair D,


E with location D050 H

Load counter with 05 H

Move the data of


memory to Accumulator

Store the data of


Accumulator to pair D, C

Increment pair D, C and


H, L

Decrement counter

If zero flag is 1

Stop

`
Code
Memory Location Mnemonics Remark
C000 LXI H, D05F H Initialize register pair H, L
with location D05F H

C003 LXI D, D064 Initialize register pair D, E


with location D064 H

C006 MVI B,0F H Load counter with 0F H

C008 MOV A,M Move the data of


memory to Accumulator

C009 STAX D Store the data of


Accumulator to pair D, C

C00A DCX D Decrement pair D, C and


H, L

C00B DCX H Decrement pair D, C and


H, L

C00C DCR B Decrement counter

`
C00D JNZ C008 Jump on C008

C010 LXI H, E000 H Initialize register pair H, L


with location E000 H

C013 LXI D, D050 H Initialize register pair D, E


with location D050 H

C016 MVI B, 05 H Load counter with 05 H

C018 MOV A,M Move the data of


memory to Accumulator

C019 STAX D Store the data of


Accumulator to pair D, C

C01A INX H Increment pair D, C and


H, L

C01B INX D Increment pair D, C and


H, L

C01C DCR D Decrement counter

C01D JNZ C018 Jump on C018

`
Before the Execution

D050= 11H
D05F= 22 H
E000= 00 H

After the execution


D050= 00H
D055= 11 H
D064= 22 H

`
25. You are given a set of 100 resistors with 10 k values and
asked to test them for 10 percent tolerance. Reject all the
resisters that are outside the tolerance and give the final
number of resistors you found within the tolerance.

Start

Initialize M with data


of D000

Load counter with


value 0A H

Copy the value 0A h in


Register D

Copy the data of


memory to register A

Compare D

Value of zero
flag Increment B (zero flag
is 1)

Increment pair H, L (zero


flag is 0)

Decrement Counter

If zero

Stop
`
Code
Memory Location Mnemonics Remarks
Initialize M with data of D000
C000 LXI H, D000 H
Copy the value 0A h in Register
C003 MVI D, 0A H D

Load counter with value 0A H


C005 MVI C, 0A H
Copy the data of memory to
C007 MOV A,M register A

Compare D
C008 CMP D
Jump on F001
C009 JZ F001
Increment pair
C00C INX H
Decrement counter
C00D DCR C
Jump on non zero to C008
C00E JNZ C008
Increment register B
F001 INR B
Jump on C008
F002 JMP C008

Before Execution
C=0A H
B= 00 H
After Execution
C= 00 H
B = 04 H

`
28. Write an ALP to find the smallest number in array of five 8 bit
data.

Start

Load H-L pair with


any address

Load C with 05 H

Load A with 00 H

Load B with 00 H

Decrement C

Move data of M to A

Increase the data Of H-L


pair

Compare M

If carry is not
there

Move data of M to A

`
Decrement C

Jump on non zero

Store the data to any


location

STOP

Code
Memory Location Mnemonics Remarks
C000 LXI H, D000H Load data of D000 in
H-L pair
C003 MVI C,0A H Load C with 0A H
C005 MVI A, 00 H Load A with 00 H
C007 MVI B,00 H Load B with 00 H
C009 MOV A,M Move data of M to A
C00A DCR C Decrement c
C00B INX H Increment pair H-L
C00C CMP M Compare M
C00D JNC C010 Jump on Not Carry
C010 MOV A,M Move data of memory

`
to A
C011
C014 DCR C Decrement c
C015 JNZ C00B Jump on non zero
C018 STA FFFF Store to FFFF

Register Status
C=0A H
A=00H
B=00H

After execution
C=00H
At location FFFF smallest number among the location D000 to D005 is
saved

`
29. Write an ALP to arrange the array of five 8 bit numbers in ascending order.

Start

Initialize register pair H, L


with location D000

Move the data from M


to C and then to D

Get the first value in accumulator


and compare with next value

According to comparison store the


smallest value

Repeat till the array is sorted in


ascending order

STOP

Code
MEMORY MNEMONIC Remark
C000 LXI H,D000H Load the array size to
the HL pair
C003 MOV C,M Copy the array size to
C register
C004 DCR C Decrement C by 1
C005 MOV D,C Copy content of C to
D register

`
C006 LXI H,D001H Load the first data to
the HL pair
C009 MOV A,M Copy the data to the
accumulator
C00A INX H Increment memory by
1
C00B CMP M Compare accumulator
and memory content
C00C JC C014 Jump on carry to the
label C014
C00F MOV B,M Copy memory
content to B register
C010 MOV M,A Copy accumulator
content to memory
C011 DCX H Decrement memory
by 1
C012 MOV M,B Copy B register’s
content to memory
C013 INX H Increment memory by
1
C014 DCR D Decrement D by 1
C015 JNZ C009 Jump on non-zero to
the label C009
C018 DCR C Decrement C by 1
C019 JNZ C005 Jump on non-zero to
the label C005
C01C HLT Program ends

Registers Status: -
Before the execution: -
D000 = 00 D001 = 06 D002 = 0A D003 = 03 D004 = 01 D005 = 04
After the execution: -
D000 = 00 D001 = 01 D002 = 03 D003 = 04 D004 = 06 D005 = 0A

`
30. Write an ALP to arrange the array of five 8 bit numbers in ascending order.

Start

Initialize register pair H, L


with location D000

Move the data from M to


C and then to D

Get the first value in accumulator


and compare with next value

According to comparison store


the smallest value

Repeat till the array is sorted in


ascending order

STOP

Code
MEMORY MNEMONIC Remark
C000 LXI H,D000H Load the array size to the HL pair
C003 MOV C,M Copy the array size to C register
C004 DCR C Decrement C by 1
C005 MOV D,C Copy content of C to D register
C006 LXI H,D001H Load the first data to the HL pair

`
C009 MOV A,M Copy the data to the accumulator
C00A INX H Increment memory by 1
C00B CMP M Compare accumulator and memory content
C00C JNC C014 Jump on carry to the label C014
C00F MOV B,M Copy memory content to B register
C010 MOV M,A Copy accumulator content to memory
C011 DCX H Decrement memory by 1
C012 MOV M,B Copy B register’s content to memory
C013 INX H Increment memory by 1
C014 DCR D Decrement D by 1
C015 JNZ C009 Jump on non-zero to the label C009
C018 DCR C Decrement C by 1
C019 JNZ C005 Jump on non-zero to the label C005
C01C HLT Program ends

Registers Status: -
Before the execution: -
D000 = 00 D001 = 0A D002 = 04 D003 =02 D004 = 01 D005 =06
After the execution: -
D000 =0A D001 =06 D002 =04 D003 = 02 D004 = 01 D005 = 00
31. Write an ALP for a2+b2 operation, where a and b are stored at D000
and D001 memory location respectively.

Flowchart:
Start

Load Register B
with 02 And
Store data inn
location D000
`
Load Register D
with 02 and store
data into location
D001

Load Accumulator
With 00H

Move from
register B to C

LOOP1:ADD B

Decrement Register C

Conditional jump to loop1

Move from register D to E

LOOP 2:ADD D

Decrement Register E

Conditional jump to loop2

Stop

`
Code:

Memory
Mnemonics Hex code Remark
Location
C000 MVI B,02H 06,02 Load register B with 8 bit data
C002 MOV A,B 78 Move from register b to a
C003 STA D000H 32,00,DO Store accumulator data in memory location DOOO
C006 MVI D,01H 16,01 Load register D with 8 bit data
C008 MOV A,D 7A Move from register D to a
Store accumulator data in memory location
C009 STA D001 32,01,DO
D001H
C00C MVI A,00H 3E,00 Load register A with 8 bit data
C00E MOV C,B 48 Move from register B to C
C00F L1:ADD B 80 ADD Register B
C010 DCR C 0D Decrement Register C
C011 JNZ L1 C2 Conditional jump to loop1
C014 MVI D,02H 0F Load register D with 8 bit data
C016 MOV E,D 5A Move from register D to E
C017 L2:ADD D 82 ADD Register D
C018 DCR E 1D Decrement Register E
C019 JNZ L2 C2,17,00 Conditional jump to loop2
C01C HLT 76 Halt

Result :

a = Register B = 02H=D000H
b = Register D = 02H=D001H
a^2+b^2 = 04H In accumulator

32. Write an ALP to find factorial of any number that is stored at D034
memory location.
Code :

Memory
Mnemonics Hex code Remark
Location
MVI B,04H
C000 0604 Load register B with 8 bit data
C002 MOV C,B 48 Move from register b to C
C003 DCR B 05 Decrement B
C004 LOOP 1 :MOV D,B 50 Move from register B to D
C005 MVI A,00H 3E,00 Load register A with 8 bit data

`
C007 Loop 2 :ADD C 81 ADD Register C
C008 DCR D 15 Decrement register d
JNZ Loop 2
C009 C2,07,00 Conditional loop
C00C MOV C,A 4F MOVE REGISTER A TO C
DCR B
C00D 05 Decrement Register B
JNZ L1
C00E C2 Conditional jump to loop1
C011 STA D034H 32,34,D0 Store accumulator data in location
C014 HLT 76 Halt

Start

Load Register B
with 04

Move Register
FROM B to C

DCR Register B

LOOP 1:Move
and data in d000
from register B to
D

Load Accumulator
With 00H

`
LOOP 2 : ADD C

DCR D

Conditional jump to
loop2

Move from register A


to C

DCR B

Conditional jump to
loop1

Store accumulator
data in location D034

Stop

Result :

Factorial of 04 is 24 satisfied

`
33. Write an ALP to generate Fibonacci number up to 13.
Memory
Mnemonics Hex code Remark
Location
C000 MVI A,01H 3E,01 Load register A with 8 bit data
C002 MVI C,0D 0E,0D Load register C with 8 bit data
C003 LXI H,D000 21,00,D0 Store data into register
C004 LXI D,D001 11,01,D0 Store data into register
C005 L1 :STAX D 12 Store data from accumulator
C007 LDAX D 1A Store data to accumulator
C008 ADD M 86 Add M
C009 INX D 13 Increment register pair
C00C INX H 23 Increment register pair
C00D DCR C 0D Decrement register pair
C00E JNZ L1 C2 Conditional jump
C011 RST 1 76 Halt

Start

Load Register A with 01

Load Register C with 0D

Store data into register

LOOP 1: Store data


from accumulator

Store data to accumulator

ADD M

` Increment & Decrement Register


CONDITONAL LOOP

STOP

34. Write an ALP for 8155: Configure port A, B and C as


input mode without timer operation. Disable interrupts A
and B. Read the inputs from kit to and store that data to the
register for corresponding port i.e input from port A, B and
C should be stored in register A, B, and C respectively

Control Word
0 0 0 0 0 0 0 0

00 H

`
Code
Memory Location Mnemonics
C000 MVI A,00 H
C002 OUT 30
C004 IN 33
C006 MOV C,A
C007 IN 32
C009 MOV B,A
C00A IN 31

35. Write an ALP for 8155: Configure port A, B and C as


output mode without timer operation. Disable interrupts A
and B. Show your data to the corresponding port LED’s

Control Word
0 0 0 0 1 1 1 1

OF H

`
Code
Memory location Mnemonics
C000 MVI A, FF H
C002 OUT 30
C004 MVI A, FE H
C006 OUT 31
C008 MVI A, FD H
COOA OUT 32
C00C MVI A, 0A H
C00E OUT 33

36. Write an ALP for 8155: Configure port A as input mode


and port b as output port. Take the input from port A and
reflect your input to the respective port LES’s.*

Control Word
0 0 0 0 0 0 1 0

02 H

`
Memory Location Mnemonics
C000 MVI A, 02 H
C002 OUT 30
C004 IN 31
C006 OUT 32

37. Design a square wave generator with a pulse width of


100μs by using 8155 timer. Set up the timer in mode 1, on
board clock frequency is 3MHz.Rember while generating
signal at TIMER OUT port, connect TIMER_IN to
CPU_CLK

Clock Period = = 330 ns

Timer Count = = 606 = 025E H

Timer Mode = 01 hence, MSB


0 1 0 0 0 0 1 0
42 H

Timer LSB = 5E H
Control Word
1 1 x x x x x x

C0 H
`
Code

Memory Location Mnemonics


C000 MVI A, 5E H
C002 OUT 34
C004 MVI A, 42
C006 OUT 35
C008 MVI A, C0
C00A OUT 30

`
38) Write an ALP for 8255:8255 is configured in mode 0, i.e. simple input-
output mode. Ports A, B, C are in mode 0. Show register data on the
corresponding LED’s. **

Control Word : 80h

1 0 0 0 0 0 0 0

Memory Location Mnemonics


C000 MVI A,80H
C002 OUT 33H
C004 MVI A,FE H
C006 OUT 30
C008 MVI A,FE H
C00A OUT 31
C00C RST 1

39) 8255 is configured in mode 0 i.e. Simple input – output mode. Where port
A, B, C are as input mode. Read the data from all 3 ports and store in
different register. **

Control Word : 9Bh

1 0 0 1 1 0 1 1

Memory Location Mnemonics


C000 MVI A,9BH
C002 OUT 33H
C004 IN 31H
C006 MOV B,A
C007 IN 32H
C009 MOV C,A
C00A IN 30H
C00C HLT

`
40. Write an ALP for Logic control interface: Your LCI board is working on
the 8255 control word register. Blink the All LED’s to the corresponding port
A and B alternatively

Control Word : 80h

1 0 0 0 0 0 0 0

Memory Location Mnemonics


C000 MVI A,9BH
C002 OUT 33H
C004 MVI C,FF
C006 BACK : MVI A,FF
C008 OUT 30
C00A MVI A,00
C00C OUT 31
C00E CALL D000
C011 MVI A,00
C013 OUT 30
C015 MVI A,FF
C017 OUT 31
C019 CALL D000
C01C DCR C
C01D JNZ BACK
C020 RST 1

DELAY :
Memory Location Mnemonics
C000 MVI H,0A
C002 L1 : MVI D,64H
C004 L2 :MVI E,DE
C006 L3 : DCR E
C007 JNZ L2
C00A DCR D

`
C00B JNZ L1
C00E DCR H
C00F JNZ L1
C012 HLT

44. Write an ALP to make sensible Traffic Light Controller. Make


appropriate delay routine between to state of transition

Data To turn LED ON Purpose

70 H Left green and Red Stop

B0 H Left green and Yellow Slow

C0 H All green Go

87 H All green and Yellow Slow

PORT Address

1 20 H - 2F H
2 28 H – 2F H
3 30 H – 37 H
4 38 H – 3F H

Memory Location Mnemonics


C000 MVI A,C0H
C002 OUT 20H
C004 MVI A,70
C006 OUT 28
C008 CALL D000 (4)
C00B MVI A,87
C00D OUT 20
C00F MVI A,B0
C011 OUT 28

`
C013 CALL D000 (4)
C016 MVI A,70
C018 OUT 20
C01A MVI A,C0
C01C OUT 28
C01E CALL D000(4)
C021 MVI A,C0H
C023 OUT 28H
C025 MVI A,70
C027 OUT 30
C029 CALL D000 (4)
C02C MVI A,87
C02E OUT 28
C030 MVI A,B0
C031 OUT 30
C032 CALL D000 (4)
C034 MVI A,70
C037 OUT 28
C039 MVI A,C0
C03B OUT 30
C03F CALL D000(4)
C042 MVI A,C0H
C044 OUT 30H
C046 MVI A,70
C048 OUT 38
C04A CALL D000 (4)
C04D MVI A,87
C04F OUT 30
C051 MVI A,B0
C053 OUT 38
C055 CALL D000 (4)
C058 MVI A,70
C05A OUT 30
C05C MVI A,C0
C05E OUT 38
C060 CALL D000(4)
C063 MVI A,C0H
C065 OUT 38H
C067 MVI A,70
C069 OUT 20

`
C06B CALL D000 (4)
C06E MVI A,87
C070 OUT 38
C072 MVI A,B0
C074 OUT 20
C076 CALL D000 (4)
C079 MVI A,70
C07B OUT 38
C07D MVI A,C0
C07F OUT 20
C081 CALL D000(4)
C084 HLT

DELAY :
Memory Location Mnemonics
C000 MVI H,0A
C002 L1 : MVI D,64H
C004 L2 :MVI E,DE
C006 L3 : DCR E
C007 JNZ L2
C00A DCR D
C00B JNZ L1
C00E DCR H
C00F JNZ L1
C012 HLT

Potrebbero piacerti anche