Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

89c51 array

Status
Not open for further replies.

tpramanhyd

New Member
can any one suggest me how to create an array for 89c51? i want to create an array in the internal ram and move the contents of this array to a different location of internal ram. I am writing code in assembly language and want to continue with the same.
 
Last edited:
Unfortuneately internal RAM is an imprecise term in the 8051 architecture.
There is the directly accessible data space from 0x00 to 0x7F. This space contains the four register banks (0x00 to 0x1F) and the 128 addressable bits(0x20 to 0x2F). Then there is the indirectly accessible data space from 0x80 to 0xFF. Lastly there is data memory from 0x0000 to 0xFFFF. Most 8051 variants implement only a portion of this space.

The complication in the routine you want to write is knowing the boundaries of the two arrays. With three possible source addresses, three possible destinations that's nine different routines. This of course assumes that the arrays do not cross boundries or overlap each other.

Most assemblesr have a pseudo-operation like DB (Define Byte) for an array with intial values, or DS (Define Storage) for an array with no initial values.

Where would you like to start?
 
thank you

my array size for simulation process i have reduced it to 3 bytes i am free to use any location so i would start from 0080h and use db & ds which solved my issue thanks
 
I'm glad to have been helpful.
An assembly language routine to move an array pointed at by R0 to an array pointed at by R1 for the number of bytes in R2 would look like
Code:
array_move:
    mov  A,@R0
    mov  @R1,A
    inc  R0
    inc  R1
    djnz R2,array_move
The calling sequence would look like
Code:
    mov   R0,#array1
    mov   R1,#array2
    mov   R2,#sizeof(array1)
    lcall array_move

Good Luck
 
Last edited:
You forgot the declaration parts
For internal RAM
Code:
Variables    segment data
or for external RAM
Code:
Variables    segment xdata

Then the variables themselves
Code:
RSEG Variables
Array1:  ds 3
Array2:  ds 3

;)
 
The routine I wrote only works for variables in internal RAM since that was what the original poster wanted. I assumed he could do the declarations from his previous post since he said he understood the use of db and ds pseudo operations, but thanks for the additional suggestions.

The routine for xdata to xdata is just a bit more complicated and less obvious. It also assumes there is only a single data pointer.
Code:
xarray_move:
    mov   A,@DPTR
    inc   DPTR
    xch   R0,DPH
    xch   R1,DPL
    mov   @DPTR,A
    inc   DPTR
    xch   R0,DPH
    xch   R1,DPL
    djnz  R2,xarray_move
The calling sequence might look like
Code:
    mov   DPTR,#destination_array
    mov   R0,DPH
    mov   R1,DPL
    mov   DPTR,#source_array
    mov   R2,sizeof(source_array)
    lcall xarray_move
with appropriate declarations
 
Status
Not open for further replies.

Latest threads

Back
Top