354 39 Solutions Instructor Manual 4 Assembly Language Programming 8085 Chapter 4

December 12, 2017 | Author: Saravanan Jayabalan | Category: Binary Coded Decimal, Microcontroller, Digital Electronics, Electronics, Computer Science
Share Embed Donate


Short Description

Microcontoller ppt...

Description

Microprocessors and Microcontrollers

Kumar, Saravanan & Jeevananthan

Chapter 4  Assembly language programming of 8085  Solutions to Review Questions: 1. Write a program to arrange n numbers in ascending order. Refer to example 31 in chapter 4 2. Write a program to unpack a 2-digit BCD number stored at memory location 1C00H. Label

Mnemonics

Comments

LDA 1C00H

; Load the BCD number in the accumulator.

MOV B, A

; Move it to register B.

ANI 0FH

; Mask the most significant four bits.

STA 1C01H

; Save the unpacked unit digit to 1C01H.

MOV A, B

; Load the BCD number in the accumulator.

ANI F0H

; Mask the least significant four bits.

RRC RRC RRC ; Shift the tens digit of the BCD number to the ones RRC place by shifting right four times. STA 1C02H

; Save the unpacked tens digit (BCD2) to 1C02H.

HLT

; Terminate program execution.

3. Explain the technique and write a program to convert a BCD number into its equivalent decimal form. The decimal form here means the binary equivalent of the BCD number. Refer to example 44 in chapter 4. 4. Explain the technique and write a program to convert a BCD number to seven-segment code.

 

© Oxford University Press 2011

4‐ 1

Microprocessors and Microcontrollers

Kumar, Saravanan & Jeevananthan

Following table gives the display data to be connected to the seven segment display for various decimal numbers. BCD D7 D6 D5 D4 D3 D2 D1 D0 Data for display (hex) number dp g f e d c b a 0

0

0

1

1

1

1

1

1

3F

1

0

0

1

1

0

0

0

0

30

2

0

1

0

1

1

0

1

1

5B

3

0

1

0

0

1

1

1

1

4F

4

0

1

1

0

0

1

1

0

66

5

0

1

1

0

1

1

0

1

6D

6

0

1

1

1

1

1

0

1

7D

7

0

0

0

0

0

1

1

1

07

8

0

1

1

1

1

1

1

1

7F

9

0

1

1

0

1

1

1

1

6F

The above table can be stored in the form of look up table in memory starting from location 9000H and can be accessed to get the corresponding display code. The decimal number is stored in BCD format at the location 8100H and the corresponding display code is stored in the memory location 8500H. Label

Mnemonics

Comments

LXI H, 9000H

; Initialize the look-up table pointer.

LDA 8100H

; Get a BCD number from memory

MOV L, A

; Move the number to register L.

MOV A, M

; Load the display data from look up table in the accumulator.

STA 8500H

; Store the result in the destination memory location.

HLT

; Terminate program execution.

5. Write a program to find the seven-segment codes for the lower and higher nibbles of the given 8–bit binary number using look-up table technique and store the result in memory.

 

© Oxford University Press 2011

4‐ 2

Microprocessors and Microcontrollers

Kumar, Saravanan & Jeevananthan

Combine the programs for the review questions 2 and 4 and rewrite the program suitably. 6. Write a program to calculate the factorial of a number between zero and eight. Refer to example 54 in chapter 4. 7. Write a program to find the number of negative, zero and positive numbers. Refer to example 37 in chapter 4. 8. Write a program to perform the following arithmetic operation: (ab + ac), where a, b, and c are 8-bit binary numbers. Explain with an algorithm and flowchart. The following program assumes that the binary numbers a, b, c are stored in the memory locations 9000h, 9001H and 9002H. The result is assumed to be 16 bits wide and is stored in the memory locations 9003 and 9004H. The program uses the multiplication by repeated addition. Label

Mnemonics

Comments

LDA 9000H

; Load the first number a in the accumulator.

MOV E, A

; Move the first number to register E.

MVI D, 00H

; Load register D with 00H so that the DE register pair now contains the first number.

LOOP:

 

LDA 9001H

; Load the second number b in the accumulator.

MOV C, A

; Initialize the second number as a counter in register C.

LXI H, 0000H

; Initialize Result = 0.

DAD D

; Result = Result + first number.

DCR C

; Decrement the counter.

JNZ LOOP

; If the counter is not equal to zero, repeat the addition process.

SHLD 9010H

; Store the result ab in 9010H and 9011H.

LDA 9000H

; Load the first number a in the accumulator.

MOV E, A

; Move the first number to register E.

MVI D, 00H

; Load register D with 00H so that the DE register pair now

© Oxford University Press 2011

4‐ 3

Microprocessors and Microcontrollers

Kumar, Saravanan & Jeevananthan

contains the first number.

LOOP:

LDA 9002H

; Load the third number c in the accumulator.

MOV C, A

; Initialize the this number as a counter in register C.

LXI H, 0000H

; Initialize Result = 0.

DAD D

; Result = Result + first number.

DCR C

; Decrement the counter.

JNZ LOOP

; If the counter is not equal to zero, repeat the addition process.

XCHG

; Store the result ac in HL to DE register pair.

LHLD 9100H

; Load the partial result ab to HL register pair

DAD D

; Add the partial result ac in DE register with ab in HL pair

SHLD 9103H

; Store the result (ab+ac) in 9103 and 9104H.

HLT

; Terminate program execution.

9. Write a program to add two 16-bit numbers from memory locations 4100H and 4102H using 16-bit move and arithmetic instructions and save the result starting at 4104H.

Mnemonics

Comments

LHLD 4100H ; Load the first 16-bit number in the HL register pair. XCHG

; Save the first 16-bit number in the DE register pair.

LHLD 4102H ; Load the second 16-bit number in the HL register pair.

 

DAD D

; Add the two 16-bit numbers

SHLD 4104H

; Store the 16-bit result in memory locations 4104H and 4105H.

HLT

; Terminate program execution.

© Oxford University Press 2011

4‐ 4

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF