Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Memcopy

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
sielcon

Bascom Member



Joined: 16 Mar 2006
Posts: 82
Location: Argentina

argentina.gif
PostPosted: Tue Mar 26, 2019 3:08 pm    Post subject: Memcopy Reply with quote

Hi all. I'm doing a routine to remove data (word) from a table and I want to use Memcopy. I did the following example and it does not work for me, I think that memcopy can copy forward as backwards. Any ideas.
Thank you very much and best regards.

Code:

$regfile = "m2560def.dat"
$crystal = 20000000
$hwstack = 100
$swstack = 100
$framesize = 100
Dim Buf As String * 5 , Aux_word As Word , Aux1 As Byte , Str1(5) As String * 1

Dim Tabla_rx_tx_addr(20) As Word
Dim Origen As Word , Destino As Word , Bytes As Word , Cantidad As Word

   Aux1 = 1
   For Aux_word = 1 To 20
      Tabla_rx_tx_addr(aux_word) = Aux1
      Print Tabla_rx_tx_addr(aux_word)
      Incr Aux1
   Next Aux_word

   For Aux_word = 1 To 20
      If Tabla_rx_tx_addr(aux_word) = 8 Then
        Goto Borrar1
      End If
   Next Aux_word
Borrar1:
   Print Varptr(tabla_rx_tx_addr(20))
   Destino = Varptr(tabla_rx_tx_addr(aux_word))
   Origen = Varptr(tabla_rx_tx_addr(aux_word + 1))
   Cantidad = 20 - Aux_word
   Print Cantidad
   Cantidad = Cantidad * 2
   Print Cantidad
   Print Destino
   Print Origen

   Bytes = Memcopy(origen , Destino , Cantidad)
   Print Bytes
   For Aux_word = 1 To 20
      Print Tabla_rx_tx_addr(aux_word)
   Next Aux_word

 




(BASCOM-AVR version : 2.0.8.1 )
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 1136

poland.gif
PostPosted: Tue Mar 26, 2019 8:12 pm    Post subject: Reply with quote

Maybe like that Very Happy
Code:
$regfile = "m2560def.dat"
$crystal = 20000000
$hwstack = 100
$swstack = 100
$framesize = 100
$sim

Config Submode = New

Dim N As Byte , Helpb As Byte
Dim Spoint As Byte , Bytes As Byte

Dim Table(20) As Word

Sub Remove()
 Spoint = N + 1
 If Spoint <= 20 Then
    Bytes = 20 - N
    Shift Bytes , Left , 1                                  'multiply bytes by 2 for WORDs
    Print "Start at " ; Spoint ; " " ; Bytes ; " bytes"
    Helpb = Memcopy(table(spoint) , Table(n) , Bytes)
 Else
  'handle end of the Table(20)
 End If
End Sub

'fill table
For N = 1 To 20
 Table(n) = N
Next

'check for "8"
For N = 1 To 20
 If Table(n) = 8 Then Call Remove()
Next

Print "Result ";
For N = 1 To 20
 Print Table(n) ; "-";
Next
Print

End

 

Back to top
View user's profile Visit poster's website
sielcon

Bascom Member



Joined: 16 Mar 2006
Posts: 82
Location: Argentina

argentina.gif
PostPosted: Wed Mar 27, 2019 3:51 am    Post subject: Reply with quote

Thank you very much EDC, it works perfectly.
But you can tell me what I did wrong with my code, I used Memcopy on other occasions and I have not had any problems.
Best regards.
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 1136

poland.gif
PostPosted: Wed Mar 27, 2019 7:37 am    Post subject: Reply with quote

Code:
Bytes = Memcopy(origen , Destino , Cantidad)

This code not work like you suppose. Variables Origen and Destino contain address of the other variable but this no mather and Memcopy takes their addresses (adresses of the Origen and Destino).
Back to top
View user's profile Visit poster's website
sielcon

Bascom Member



Joined: 16 Mar 2006
Posts: 82
Location: Argentina

argentina.gif
PostPosted: Wed Mar 27, 2019 1:13 pm    Post subject: Reply with quote

Thank you.
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum