Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

How to pass the table name to the SUB?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
mrak

Bascom Member



Joined: 14 Dec 2005
Posts: 24

poland.gif
PostPosted: Fri Oct 17, 2014 7:03 am    Post subject: How to pass the table name to the SUB? Reply with quote

Dear all,

I would like to pass the name of the data table to the sub SUB in order to use it insight as an argument of the LOOKUP function.


Have tried to use the bylabel attribute as illustrated below:

Code:


call Procedure_name(data_table)

[...]

sub Procedure_name(bylabel my_label as word)

[...]
    xx=lookup(yy,my_label))
[...]

End Sub


Data_table:
Data 1, 2, 3, ...

 


But this approach is not accepted by the compiler.

Very appreciate an exemplary working code or your suggestion how to do this in the right way.

Thanks,
makarak

[/b]

(BASCOM-AVR version : 2.0.7.7 )
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 733

poland.gif
PostPosted: Fri Oct 17, 2014 9:34 am    Post subject: Reply with quote

Test this in simulator Smile
Code:
$sim
$regfile = "m8def.dat"
$crystal = 16000000
$hwstack = 64
$swstack = 64
$framesize = 64

Dim Address As Word
Dim N As Byte
Dim Items(5) As Byte

Declare Sub Show_array(byval Address As Word , Byval Linia As Byte)

Cls

Address = Loadlabel(label_1)
Call Show_array(address , 1)
Address = Loadlabel(label_2)
Call Show_array(address , 2)

'** pro forma
Do
nop
Loop
End
'** End **

Sub Show_array(byval Address As Word , Byval Linia As Byte)
  Locate Linia , 1

  Loadadr Address , X
   !LD    R8,X+
   !LD    R9,X

    For N = 1 To 5
     Read Items(n)
     Lcd Items(n) ; " "
    Next

End Sub


Label_1:
Data 1 , 2 , 3 , 4 , 5

Label_2:
Data 5 , 4 , 3 , 2 , 1


Have a nice day
Back to top
View user's profile Visit poster's website
mrak

Bascom Member



Joined: 14 Dec 2005
Posts: 24

poland.gif
PostPosted: Mon Nov 03, 2014 9:32 pm    Post subject: Reply with quote

EDC,

thank you for your great suggestion plus the exemplary code enclosed
.

In the next step, after accessing the right table using a pair of the R8/R9 registers. I would like to jump over to an OFFSET position in the table. I have used the following code to achieve that:

Code:



Dim Bh As Byte , Bl As Byte                                 'auxiliary global variable used at offset calculation
Dim Font As Word
Dim Dw As Word                                              'address in the table


[.........]


Sub Put_char(byval Font As Word , Byval Page As Byte , Byval Column As Byte , Byval Znak As String )


[.........]

'locate the pointer address
   Loadadr Font , X
   !LD    R8,X+
   !LD    R9,X
   !sts {bl},r8
   !sts {bh},r9
   Ww = Makeint(bl , Bh)

   ww = ww + offset         'calculate the pointer address with offset

   'load the new pointer to the R8/R9 pair
   Bl = Low(offset)
   Bh = High(offset)
   !lds r8,{bl}
   !lds r9,{bh}


[.........]

end sub

 



The above code works fine in line with expectations once the 'bl' and 'bh' are defined as a GLOBAL variables!

As soon as I try to define them as the LOCAL variables the compiler issues the following error: "No more space for BIT [BL]", "No more space for BIT [BH]"

Likely I misuse assembler command to store the R8/R9 register values to the local BH/BL variables hence the error.


Very appreciate your suggestion how to copy R8/R9 value into the local variable and (after adding the offset) copy back to these registers.


Please, note I hardly know assembler so any exemplary code will be more than welcome.

local BH/BL --> R8/R9 (what assembler code?)
R8/R9 --> local R8/R9 (what assembler code?)


Thank you in advance for any advice.
Back to top
View user's profile
laborratte

Bascom Expert



Joined: 27 Jul 2005
Posts: 279
Location: Berlin

germany.gif
PostPosted: Mon Nov 03, 2014 11:07 pm    Post subject: Reply with quote

Don't make your life harder than it should be. Locals are stored on the soft stack and so they have to accessed indirect via Y-register. See help "BASCOM Language Fundamentals > Mixing ASM and BASIC > Locals".
Just reserve global two bytes of RAM and be happy.
Back to top
View user's profile
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 733

poland.gif
PostPosted: Mon Nov 03, 2014 11:12 pm    Post subject: Reply with quote

I don`t know where the problem. Offset can be set in many ways. Try Both codes try in symulator.
Code:
$sim
$regfile = "m8def.dat"
$crystal = 16000000
$hwstack = 64
$swstack = 64
$framesize = 64

Dim Address As Word
Dim N As Byte
Dim Items(5) As Byte
Dim Offset As Word

Offset = 2                                                  'TRY OTHER VALUES

Declare Sub Show_array(byval Address As Word , Byval Linia As Byte)

Cls

Address = Loadlabel(label_1)
Call Show_array(address , 1)

Macro Restore_address
   Loadadr Address , X                                      'restore address
   !LD    R8,X+
   !LD    R9,X
End Macro

'** pro forma
Do
nop
Loop
End
'** End **

Sub Show_array(byval Address As Word , Byval Linia As Byte)

  Locate Linia , 1

  Address = Address + Offset

     Restore_address                                        'macro is used

    For N = 1 To 5
     Read Items(n)
     Lcd Items(n) ; " "
    Next

End Sub


Label_1:
Data 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9
 


Then second
Code:
$sim
$regfile = "m8def.dat"
$crystal = 16000000
$hwstack = 64
$swstack = 64
$framesize = 64

Dim Address As Word
Dim N As Word
Dim Items(5) As Byte

Declare Sub Show_array(byval Address As Word , Byval Linia As Byte , Byval Offset As Word)

Cls

Address = Loadlabel(label_1)
Call Show_array(address , 1 , 1)

Macro Restore_address
   Loadadr Address , X                                      'restore address
   !LD    R8,X+
   !LD    R9,X
End Macro

'** pro forma
Do
nop
Loop
End
'** End **

Sub Show_array(byval Address As Word , Byval Linia As Byte , Byval Offset As Word )

     Locate Linia , 1

     Restore_address                                        'macro is used


    For N = 2 To 6
     Read Items(n)
     Lcd Items(n) ; " "
    Next

    Address = Address + Offset

    Linia = Linia + Offset
    Locate Linia , 1

    Restore_address


    For N = 2 To 6
     Read Items(n)
     Lcd Items(n) ; " "
    Next

End Sub


Label_1:
Data 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9


If You want polish then click GG3100706
Back to top
View user's profile Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive 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