Home

Inserting string in a given array of characters

Statement: Write an 8085 assembly language program to insert a string of four characters from the tenth location in the given array of 50 characters.

Solution:

Step 1: Move bytes from location 10 till the end of array by four bytes downwards.

Step 2: Insert four bytes at locations 10, 11, 12 and 13.

Source program :

  • LXI H, 2l31H : Initialize pointer at the last location of array.
  • LXI D, 2l35H : Initialize another pointer to point the last location of array after insertion.
  • AGAIN: MOV A, M : Get the character
  • STAX D : Store at the new location
  • DCX D : Decrement destination pointer
  • DCX H : Decrement source pointer
  • MOV A, L : [check whether desired
  • CPI 05H  bytes are shifted or not]
  • JNZ AGAIN : if not repeat the process
  • INX H : adjust the memory pointer
  • LXI D, 2200H : Initialize the memory pointer to point the string to be inserted
  • REPE: LDAX D : Get the character
  • MOV M, A : Store it in the array
  • INX D : Increment source pointer
  • INX H  : Increment destination pointer
  • MOV A, E : [Check whether the 4 bytes
  • CPI 04     are inserted]
  • JNZ REPE  : if not repeat the process
  • HLT : stop

Related Programs for Beginners: (Click down)

Calculate the sum of series of numbers

Find the square of given number

Divide a 16 bit number by a 8-bit number

Unpack a BCD number