0% found this document useful (0 votes)
104 views5 pages

8085 Assembly Programs for Arithmetic Operations

The document contains several statements describing programs to perform arithmetic operations and data conversions on numbers stored in memory locations. Sample problems and source code are provided for adding numbers stored in BCD format, multiplying two 8-bit numbers using repetitive addition, shifting a 16-bit number left by one bit, converting numeric values to ASCII characters, and adding two decimal numbers stored in BCD format. Flowcharts are also shown illustrating the program logic.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Topics covered

  • decrementing counters,
  • initialization,
  • HLT instruction,
  • incrementing pointers,
  • program structure,
  • increment operation,
  • 8085 microprocessor,
  • program logic,
  • decimal adjustment,
  • instruction set
0% found this document useful (0 votes)
104 views5 pages

8085 Assembly Programs for Arithmetic Operations

The document contains several statements describing programs to perform arithmetic operations and data conversions on numbers stored in memory locations. Sample problems and source code are provided for adding numbers stored in BCD format, multiplying two 8-bit numbers using repetitive addition, shifting a 16-bit number left by one bit, converting numeric values to ASCII characters, and adding two decimal numbers stored in BCD format. Flowcharts are also shown illustrating the program logic.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Topics covered

  • decrementing counters,
  • initialization,
  • HLT instruction,
  • incrementing pointers,
  • program structure,
  • increment operation,
  • 8085 microprocessor,
  • program logic,
  • decimal adjustment,
  • instruction set

Statement: Calculate the sum of series of numbers.

The length of the series is in memory


location 4200H and the series begins from memory location 4201H.

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

4300H.

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

Sample problem 1:

4200H  = 04H

4201H  = 10H

4202H  = 45H

4203H  = 33H

4204H  = 22H

Result = 10 +41 + 30 + 12 =  H

4300H  =  H

Flowchart for Source program1

Source program 1:
LDA 4200H

MOV C, A : Initialize counter

SUB A : sum = 0

LXI H, 420lH : Initialize pointer

BACK: ADD M : SUM = SUM + data

INX H : increment pointer

DCR C : Decrement counter

JNZ BACK : if counter  0 repeat

STA 4300H : Store sum

HLT : Terminate program execution


Sample problem 2:

4200H =  04H

420lH  = 9AH
4202H = 52H

4203H = 89H

4204H = 3EH

Result = 9AH + 52H + 89H + 3EH = H

4300H = B3H Lower byte

4301H = 0lH Higher byte

Source program 2
LDA 4200H

MOV C, A : Initialize counter

LXI H, 4201H : Initialize pointer

SUB A :Sum low = 0

MOV B, A : Sum high = 0

BACK: ADD M : Sum = sum + data

JNC SKIP

INR B : Add carry to MSB of SUM

SKIP: INX H : Increment pointer

DCR C : Decrement counter

JNZ BACK : Check if counter 0 repeat

STA 4300H : Store lower byte

MOV A, B

STA 4301H : Store higher byte

HLT :Terminate program execution

Statement: Multiply two 8-bit numbers stored in memory locations 2200H and 2201H by
repetitive addition and store the result in memory locations 2300H and 2301H.

Sample problem 1:

(2200H) = 03H

(2201H) = B2H
Result = B2H + B2H + B2H = 216H

               = 216H

(2300H) = 16H

(2301H) = 02H

Flowchart for program

Source program :
 LDA 2200H
 MOV E, A
 MVI D, 00 : Get the first number in DE
register pair
 LDA 2201H
 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 2300H : Store result
 HLT : Terminate program execution

Statement: Program to shift a 16-bit data 1 bit left. Assume data is in the HL register

Source Program

Add each element of array with the elements of another array

Statement: Two decimal numbers six digits each, are stored in BCD package form. Each

number occupies a sequence of byte in the memory. The starting address of first number is

6000H Write an assembly language program that adds these two numbers and stores the sum in

the same format starting from memory location 6200H.


Source program : Flowchart for program

 LXI H, 6000H : Initialize pointer l to first number


 LXI D, 6l00H : Initialize pointer2 to second number
 LXI B, 6200H : Initialize pointer3 to result
 STC
 CMC : Carry = 0
 BACK: LDAX D  : Get the digit
 ADD M  : Add two digits
 DAA : Adjust for decimal
 STAX.B : Store the result
 INX H : Increment pointer 1
 INX D  : Increment pointer2
 INX B : Increment result pointer
 MOV A, L
 CPI 06H : Check for last digit
 JNZ BACK  : If not last digit repeat
 HLT : Terminate program execution 

Statement: Write an assembly language program to convert the contents of the five memory
locations starting from 2000H into an ASCII character. Place the result in another five memory
locations starting from 2200H.

Sample Problem

       (2000H) = 1

       (2001H) = 2

       (2002H) = 9

       (2003H) = A

       (2004H) = B

       Result:(2200H) = 31

               (2201H) = 32

               (2202H) = 39

               (2203H) = 41

               (2204H) = 42

Source program:

       LXI SP, 27FFH        : Initialize stack pointer


       LXI H, 2000H        : Source memory pointer

       LXI D, 2200H        : Destination memory pointer

       MVI C, O5H                : Initialize the counter

BACK: MOV A, M                : Get the number

       CALL ASCII                : Call subroutine ASCII

       STAX D                : Store result

       INX H                        : Increment source memory pointer

       INX D                        : Increment destination memory pointer

       DCR C                : Decrement count by 1        

       CJNZ                        : if not zero, repeat

       HLT                        : Stop program execution subroutine ASCII

ASCII: CPI, OAH                : Check if number is OAR

       JNC NEXT                : If yes go to next otherwise continue

       ADI 30H

       JMP LAST

NEXT: ADI 37H

LAST: RET                        : Return to main program

Common questions

Powered by AI

In assembly language, control flow for different arithmetic operations can be managed using conditional branches and subroutines. Programs can dynamically decide operations based on input or flags (e.g., using CMP instructions followed by conditional jumps like JZ, JNZ to direct flow). Subroutines for each arithmetic operation can be created, with the accumulator or specific registers indicating the desired operation, and CALL instructions to execute based on program state. Flexibility can be enhanced by parameterizing inputs and using stack manipulations to dynamically allocate resources, but requires meticulous planning to manage state and execution flow without conventional high-level language constructs.

Flowcharts serve an important role in visually representing the logical flow of a program, helping to abstract complex code into understandable segments. They outline processes such as initialization, iterative execution (looping), conditional checks (e.g., using DEC and JNZ for loops), and termination instruction sequences (HLT). By providing a clear graphical representation, they assist in understanding the sequence of operations, especially data movement and arithmetic operations involved in summation, making logic errors easier to identify and correct.

The program for multiplying two numbers uses repetitive addition; it initializes one operand in the DE register pair and the other as a counter. The DAD instruction accumulates the sum in a loop controlled by the JNZ instruction. Improvements could include using faster multipliers such as table-based lookup or using algorithms that employ binary shifts and additions. Parallel additions or utilizing hardware multiplication on compatible systems could also speed up the operation .

The assembly language handles array operations by aligning pointers to the start of each array using LXI instructions and iteratively processing each element using indexed addressing (e.g., LDAX and STAX instructions). Challenges in aligning arrays of different lengths involve managing boundary conditions and ensuring excess elements in the longer array don't cause unwanted operations or overwrites. It requires conditional logic to pause or stop processing upon reaching the length of the shorter array, often managed with software flags or counters and conditional jumps.

When adding two BCD numbers, the program manages the carry using set and clear carry instructions with CMC and STC at the beginning to ensure the initial carry state is zero . It uses the ADD M instruction to perform the addition. Importantly, the DAA (Decimal Adjust for Addition) instruction adjusts the result to ensure it remains a valid BCD by adding 6 to each nibble if necessary, which is essential after each arithmetic operation involving BCD to correct any non-decimal results and manages the carry accordingly .

The left-shift operation for 16-bit data in the HL register involves bit manipulation to double the stored value. The process uses the RAL (rotate accumulator left through carry) instruction, effectively shifting both the higher and lower bytes. First, RAL shifts the L register, then an additional RAL is used on the H register to ensure the carry from L shifts into H, concatenating the bits correctly across both registers . This method maintains the integrity of both registers and deals with overflow by using the carry mechanism.

The conversion of memory data to ASCII characters is handled through an assembly program that loops over the data in memory, converts each value, and stores the ASCII equivalent. The program uses LXI SP to initialize the stack pointer and LXI H to set the source memory pointer, then moves the data to the accumulator using MOV A, M. It calls the ASCII conversion subroutine, which checks if the number is less than 0A with CPI 0A and either adds 30H to convert to ASCII if true, or adds 37H otherwise. This result is then stored at the destination address using STAX D .

The multiplication program employs repetitive addition wherein it initializes registers for each operand and uses a loop to add one operand to the running total the number of times specified by the other operand. It uses LDA to load the first operand, MOV to set up a counter for the loop, and DAD with a loop controlled by JNZ to implement addition . This approach, though straightforward, has limitations such as inefficiency for large numbers due to repeated loops and increased execution time. It does not handle carries over 16-bit boundaries nor negative numbers or inputs beyond the 8-bit size efficiently.

In the program's first mode, which considers an 8-bit sum, carries are ignored, resulting in only the lower byte being stored at memory location 4300H. The program initializes with LDA 4200H to load the count and uses ADD M to progressively add values from subsequent memory locations. The sum is stored using STA 4300H, effectively disregarding overflow . For a 16-bit sum, the program adopts a similar approach but incorporates carry management. After each addition using ADD M, it checks for a carry with JNC SKIP, incrementing a higher byte if necessary, and both the lower and higher bytes are stored at locations 4300H and 4301H respectively .

Storing numbers in Binary Coded Decimal (BCD) format has distinct implications. BCD stores each decimal digit separately, which simplifies interfacing with decimal-based systems like displays. However, it increases storage requirements and complicates arithmetic operations, as conventional binary operations don't apply directly. Programs need additional instructions like DAA to adjust after arithmetic. While BCD improves human readability and direct manipulation of decimal data, it incurs penalties in processing efficiency and storage compared to compact binary or hexadecimal formats .

You might also like