Sunteți pe pagina 1din 10

8085 Microprocessor Processor

Problem 1

Calculate the sum of series of numbers. The length of the series is in memory location 3200H and the series begins from memory location 3201H.

a. Consider the sum to be 8 bit number. So, ignore carries. Store the sum at memory location 3300H.

b. Consider the sum to be 16 bit number. Store the sum at memory locations 3300H and 3301H.

a. Sample problem

3200H = 04H 3201H = 1AH 3202H = 45H 3203H = 3BH 3204H = 22H

Source program:

 

LDA 3200H MOV C, A SUB A

: Initialize counter : sum = 0

LXI

H, 320lH

: Initialize pointer

BACK:

ADD M

: SUM = SUM + data

INX

H

: increment pointer

DCR C

: Decrement counter

JNZ BACK

: if counter 0 repeat

STA 3300H

: Store sum

EF

: Terminate program execution

b. Sample problem

3200H = 04H 320lH = 9AH 3202H = 52H 3203H = 89H 3204H = 3EH

Results

3300H = Lower byte 3301H = Higher byte

Source program:

LDA 3200H MOV C, A LXI H, 3201H SUB A MOV B, A BACK: ADD M JNC SKIP INR B SKIP: INX H DCR C JNZ BACK STA 3300H

: Initialize counter : Initialize pointer :Sum low = 0 : Sum high = 0 : Sum = sum + data

: Add carry to MSB of SUM : Increment pointer : Decrement counter : Check if counter 0 repeat : Store lower byte

1

MOV A, B

STA

3301H

: Store higher byte

EF

:Terminate program execution

Problem 2

Multiply two 8-bit numbers stored in memory locations 3200H and 3201H by repetitive addition and store the result in memory locations 3300H and 3301H.

Sample problem:

3200H = 03H 3201H = B2H

Result = B2H + B2H + B2H = 216H

3300H = 16H 3301H = 02H

Source program

LDA 3200H

MOV E, A

MVI

D, 00

: Get the first number in DE register pair

LDA

3201H

MOV C, A

: Initialize counter

LX I H, 0000 H

: Result = 0

BACK: DAD

D

: Result = result + first number

DCR

C

: Decrement count

JNZ

BACK

: If count

0 repeat

SHLD 3300H

: Store result

EF

: Terminate program execution

2

count JNZ BACK : If count 0 repeat SHLD 3300H : Store result EF : Terminate

Problem 3

Divide 16 bit number stored in memory locations 3200H and 3201H by the 8 bit number stored at memory location 3202H. Store the quotient in memory locations 3300H and 3301H and remainder in memory locations 3302H and 3303H.

Sample problem

3200H = 60H 3201H = A0H 3202H = 12H

Result = A060H/12H = 08E8H Quotient and 10H remainder

3300H = E8H 3301H = 08H 3302H= 10H 3303H= 00H

Source program

LHLD 3200H

LDA

MOV C, A

LXI D, 0000H

3202H

BACK: MOV A, L SUB C

MOV L, A

SKIP

DCR H SKIP: INX D MOV A, H CPI, 00 JNZ BACK MOV A, L CMP C JNC BACK SHLD 3302H XCHG SHLD 3300H EF

JNC

: Get the dividend : Get the divisor

: Quotient = 0

: Subtract divisor

: Save partial result

: if CY

: Subtract borrow of previous subtraction

1 jump

: Increment quotient

: Check if dividend < divisor : if no repeat

: Store the remainder

: Store the quotient : Terminate program execution

Problem 4

Find the number of negative elements (most significant bit 1) in a block of data. The length of the block is in memory location 3200H and the block itself begins in memory location 3201H. Store the number of negative elements in memory location 3300H

Sample problem

3200H = 04H 3201H = 56H 3202H = A9H 3203H = 73H 3204H = 82H

3

Result = 02 since 3202H and 3204H contain numbers with a MSB of 1.

Source program

LDA 3200H

MOV C, A

: Initialize count

MVI

B, 00

: Negative number = 0

LXI

H, 3201H

: Initialize pointer

BACK: MOV A, M

: Get the number

ANI

80H

: Check for MSB

JZ SKIP

: If MSB = 1

INR B

SKIP: INX H

DCR C

JNZ

MOV A, B

BACK

: Increment negative number count : Increment pointer

: Decrement count

: If count

0 repeat

STA

3300H

: Store the result

EF

: Terminate program execution

: Store the result EF : Terminate program execution Problem 5 Find the largest number in

Problem 5

Find the largest number in a block of data. The length of the block is in memory location 3200H and the block itself starts from memory location 3201H. Store the maximum number in memory location 3300H. Assume that the numbers in the block are all 8 bit unsigned binary numbers.

Sample problem

3200H = 04 3201H = 34H 3202H = A9H 3203H = 78H 3204H =56H

Result = 3202H = A9H

Source program

LDA 3200H

MOV C, A

: Initialize counter

XRA

A

: Maximum = Minimum possible value = 0

LXI

H, 3201H

: Initialize pointer

BACK: CMP M

: Is number> maximum

JNC SKIP

MOV A, M

SKIP: INX H

: Yes, replace maximum

DCR

C

JNZ

BACK

STA

3300H

: Store maximum number

EF

: Terminate program execution

4

maximum DCR C JNZ BACK STA 3300H : Store maximum number EF : Terminate program execution

Problem 6

Write a program to count number of l's in the contents of D register and store the count in the B register.

Source program:

MVI

MVI

MOV A, D

B, 00H

C, 08H

BACK: RAR

JNC SKIP

INR B

SKIP: DCR C

JNZ

EF

BACK

5

count in the B register. Source program: MVI MVI MOV A, D B, 00H C, 08H

Problem 7

Write a program to sort given 10 numbers from memory location 3200H in the ascending order.

Source program:

 

MVI

B, 09

: Initialize counter

START:

LXI H, 3200H

: Initialize memory pointer

MVI

C, 09H

: Initialize counter 2

BACK:

MOV A, M

: Get the number

INX

H

: Increment memory pointer

CMP M JC SKIP JZ SKIP MOV D, M MOV M, A

: Compare number with next number : If less, don't interchange : If equal, don't interchange

DCX

H

MOV M, D

 

INX

H

: Interchange two numbers

SKIP:

DCR C

: Decrement counter 2

JNZ

BACK

: If not zero, repeat

DCR B

: Decrement counter 1

JNZ

START

EF

: Terminate program execution

6

BACK : If not zero, repeat DCR B : Decrement counter 1 JNZ START EF :

Problem 8

Calculate the sum of series of even numbers from the list of numbers. The length of the list is in memory location 3200H and the series itself begins from memory location 3201H. Assume the sum to be 8 bit number so you can ignore carries and store the sum at memory location 3210H.

Sample problem:

3200H= 4H

3201H= 20H

3202H= l5H

3203H= l3H

3204H= 22H

Result 3210H= 20 + 22 = 42H

Source program:

LDA 3200H

MOV C, A

MVI B, 00H

LXI H, 3201H BACK: MOV A, M

: Initialize counter

: sum = 0

: Initialize pointer

: Get the

number

ANI

0lH

: Mask Bit l to Bit7

JNZ

SKIP

: Don't add if number is ODD

MOV A, B ADD MOV B, A

M

: Get the sum : SUM= SUM+ data : Store result in B register

SKIP: INX H DCR

C

BACK

: increment pointer : Decrement counter

JNZ

: if counter 0 repeat

STA

3210H

: store sum

EF

: Terminate program execution

7

counter JNZ : if counter 0 repeat STA 3210H : store sum EF : Terminate program

Problem 9 Find the square of the given numbers from memory location 3100H and store the result from memory location

3500H.

Source Program:

LXI

H, 3200H

: Initialize lookup table pointer

LXI

D, 3100H

: Initialize source memory pointer

LXI

B, 3500H

: Initialize destination memory pointer

BACK: LDAX D

: Get the number

MOV L, A MOV A, M STAX B

: A point to the square : Get the square : Store the result at destination memory location

INX

D

: Increment source memory pointer

INX

B

: Increment destination memory pointer

MOV A, C

CPI

05H

: Check for last number

JNZ

BACK

: If not repeat

EF

: Terminate program execution

A, C CPI 05H : Check for last number JNZ BACK : If not repeat EF

8

Problem 10 Search the given byte in the list of 5 numbers stored in the consecutive memory locations and store the address of memory location in the memory locations 3200H and 3201H. Assume byte is in the C register and starting address of the list is 3500H. If byte is not found store 00 at 2200H and 2201H.

Source program:

LX I H, 3500H

MVI B, 05H

BACK: MOV A, M

CMP C

JZ LAST

INX H

DCR B

: Initialize memory pointer : Initialize counter : Get the number : Compare with the given byte : Go last if match occurs

: Increment memory pointer

: Decrement counter

JNZ

B

: I f not zero, repeat

LXI

H, 0000H

SHLD 3200H

JMP END

LAST: SHLD 3200H

END: EF

: Store 00 at 3200H and 3201H

: Store memory address

: Stop

LXI H, 0000H SHLD 3200H JMP END LAST: SHLD 3200H END: EF : Store 00 at

9

Problem 11 Add 2 arrays having ten 8-bit numbers each and generate a third array of result. It is necessary to add the first element of array 1 with the first element of array-2 and so on. The starting addresses of array l, array2 and array3 are 3200H, 3300H and 3400H, respectively.

Source Program:

LXI

LXI

LXI

H, 3200H

B, 3300H

D, 3400H

BACK: LDAX B ADD M STAX D

: Initialize memory pointer 1 : Initialize memory pointer 2 : Initialize result pointer : Get the number from array 2 : Add it with number in array 1 : Store the addition in array 3

INX

H

: Increment pointer 1

INX

B

: Increment pointer2

INX

D

: Increment result pointer

MOV A, L

CPI

0AH

: Check pointer 1 for last number

JNZ

BACK

: If not, repeat

EF

: Stop

pointer MOV A, L CPI 0AH : Check pointer 1 for last number JNZ BACK :

10