gnupic: Thread: gpasm - how to get address of variable ?


[<<] [<] Page 1 of 1 [>] [>>]
Subject: gpasm - how to get address of variable ?
From: "Vaclav Peroutka" ####@####.####
Date: 7 Sep 2012 07:52:40 -0000
Message-Id: <2E.J}Dp.4cJ3Vft1G{C.1GIQV5@seznam.cz>

Hello,

I want to use FSR/INDF in assembler. I have defined

    CBLOCK    0x20
        var1:    1
        var_array:    1
    ENDC

In the code, I want to use
   movlw address_of_var_array
   movwf FSR

and then to write to var_array through INDF.

How can I do that ? I did not find any expression in gputils manual.

Thank you in advance,
Vaclav
Subject: Re: gpasm - how to get address of variable ?
From: Borut ####@####.####
Date: 7 Sep 2012 08:15:17 -0000
Message-Id: <5049AD12.9080204@gmail.com>

Hi Vaclav,

I don't think you can get the address of CBLOCK variable.
The alternative is to use EQUs instead of CBLOCK:

var1            EQU        0x20
var_array    EQU        0x21

                     movlw    var_array
                     movwf    FSR

Borut

On 07. 09. 2012 09:52, Vaclav Peroutka wrote:
> Hello,
>
> I want to use FSR/INDF in assembler. I have defined
>
>      CBLOCK    0x20
>          var1:    1
>          var_array:    1
>      ENDC
>
> In the code, I want to use
>     movlw address_of_var_array
>     movwf FSR
>
> and then to write to var_array through INDF.
>
> How can I do that ? I did not find any expression in gputils manual.
>
> Thank you in advance,
> Vaclav

Subject: Re: gpasm - how to get address of variable ?
From: Joe Pfeiffer ####@####.####
Date: 7 Sep 2012 15:38:52 -0000
Message-Id: <20554.5386.898649.263574@pfeifferfamily.net>

To elaborate just a bit more on my previous response:  cblock can be
thought of as a way to automatically define equ's.  That's not the
best way to think of it in most cases, but in this case it helps to
show why what I said before works.

Borut Ražem writes:
>Hi Vaclav,
>
>I don't think you can get the address of CBLOCK variable.
>The alternative is to use EQUs instead of CBLOCK:
>
>var1            EQU        0x20
>var_array    EQU        0x21
>
>                     movlw    var_array
>                     movwf    FSR
>
>Borut
>
>On 07. 09. 2012 09:52, Vaclav Peroutka wrote:
>> Hello,
>>
>> I want to use FSR/INDF in assembler. I have defined
>>
>>      CBLOCK    0x20
>>          var1:    1
>>          var_array:    1
>>      ENDC
>>
>> In the code, I want to use
>>     movlw address_of_var_array
>>     movwf FSR
>>
>> and then to write to var_array through INDF.
>>
>> How can I do that ? I did not find any expression in gputils manual.
>>
>> Thank you in advance,
>> Vaclav
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: ####@####.####
>For additional commands, e-mail: ####@####.####
>

-- 
Joseph J. Pfeiffer, Jr., Ph.D.                 http://pfeifferfamily.net/
1440 Tierra del Sol Dr                         575.525.2764 (H)
Las Cruces, NM 88007                           575.496.3501 (C)
Subject: Re: gpasm - how to get address of variable ?
From: Gál ####@####.####
Date: 7 Sep 2012 20:07:29 -0000
Message-Id: <CAFKtu37cRr3GoOVOmJYnkfdiSJ5rxzCAdV+wBXHfG7jH=4R+wA@mail.gmail.com>

I would like  to say about bankisel in addition. You should use it, if
the variable ( register ) takes places, then the previous used
variables or array.

So the almost perfect solution:

  bankisel   var_array
  movlw      var_array
  movwf      FSR

and you can move data trough INDF register.
Subject: Re: gpasm - how to get address of variable ?
From: Joe Pfeiffer ####@####.####
Date: 7 Sep 2012 21:59:37 -0000
Message-Id: <20554.28229.475556.681871@pfeifferfamily.net>

Gál Zsolt writes:
>I would like  to say about bankisel in addition. You should use it, if
>the variable ( register ) takes places, then the previous used
>variables or array.
>
>So the almost perfect solution:
>
>  bankisel   var_array
>  movlw      var_array
>  movwf      FSR
>
>and you can move data trough INDF register.

Good point -- though I believe the IRP bit doesn't need to be set
using bankisel until the actual use of the INDF register (it affects
how the indirect addressing is done, not how the address is
represented as it is moved into W and then FSR).
-- 
Joseph J. Pfeiffer, Jr., Ph.D.                 http://pfeifferfamily.net/
1440 Tierra del Sol Dr                         575.525.2764 (H)
Las Cruces, NM 88007                           575.496.3501 (C)
Subject: Re: gpasm - how to get address of variable ?
From: Borut ####@####.####
Date: 8 Sep 2012 06:57:24 -0000
Message-Id: <504AEC50.2080109@gmail.com>

I was totally wrong: the cblock "variables" actually hold the address. I 
was wrongly thinking about cblocks as C structures...

Obviously I have no idea how the assembler works :-[

My apologies,
Borut

On 07. 09. 2012 10:15, Borut Ražem wrote:
> Hi Vaclav,
>
> I don't think you can get the address of CBLOCK variable.
> The alternative is to use EQUs instead of CBLOCK:
>
> var1            EQU        0x20
> var_array    EQU        0x21
>
>                     movlw    var_array
>                     movwf    FSR
>
> Borut
>
> On 07. 09. 2012 09:52, Vaclav Peroutka wrote:
>> Hello,
>>
>> I want to use FSR/INDF in assembler. I have defined
>>
>>      CBLOCK    0x20
>>          var1:    1
>>          var_array:    1
>>      ENDC
>>
>> In the code, I want to use
>>     movlw address_of_var_array
>>     movwf FSR
>>
>> and then to write to var_array through INDF.
>>
>> How can I do that ? I did not find any expression in gputils manual.
>>
>> Thank you in advance,
>> Vaclav
>

Subject: Re: gpasm - how to get address of variable ?
From: Gál ####@####.####
Date: 8 Sep 2012 15:51:23 -0000
Message-Id: <CAFKtu37XCKDCW-mjEsG4gTTLJjMSOdvjAMikyD=p9nr0gfGLKA@mail.gmail.com>

Is that right? Good joke...

2012/9/8 Borut Ražem ####@####.####
> I was totally wrong: the cblock "variables" actually hold the address. I was
> wrongly thinking about cblocks as C structures...
>
> Obviously I have no idea how the assembler works :-[
>
> My apologies,
> Borut
>
>
> On 07. 09. 2012 10:15, Borut Ražem wrote:
>>
>> Hi Vaclav,
>>
>> I don't think you can get the address of CBLOCK variable.
>> The alternative is to use EQUs instead of CBLOCK:
>>
>> var1            EQU        0x20
>> var_array    EQU        0x21
>>
>>                     movlw    var_array
>>                     movwf    FSR
>>
>> Borut
>>
>> On 07. 09. 2012 09:52, Vaclav Peroutka wrote:
>>>
>>> Hello,
>>>
>>> I want to use FSR/INDF in assembler. I have defined
>>>
>>>      CBLOCK    0x20
>>>          var1:    1
>>>          var_array:    1
>>>      ENDC
>>>
>>> In the code, I want to use
>>>     movlw address_of_var_array
>>>     movwf FSR
>>>
>>> and then to write to var_array through INDF.
>>>
>>> How can I do that ? I did not find any expression in gputils manual.
>>>
>>> Thank you in advance,
>>> Vaclav
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ####@####.####
> For additional commands, e-mail: ####@####.####
>



-- 
~~~~~~~~~~~~~~~~
http://galzsolt.zzl.org
Subject: Re: gpasm - how to get address of variable ?
From: Tamas Rudnai ####@####.####
Date: 8 Sep 2012 17:03:09 -0000
Message-Id: <CAJLb5+TtXAR0_CtdCtcCwqo3QGbEyw2KH9L-WpMQ1ruz+dX7bg@mail.gmail.com>

CBLOCK-s are *not* variables but (C)onstant (BLOCK)s ...

So you define constants that happen to be easily used as memory addresses
-- but you can use this for other things than this if you wish.

If you want to have real variable definitions and memory management, you
need to use relocative mode and linker scripts as opposed to absolute mode.

Tamas


On 7 September 2012 23:57, Borut Ražem ####@####.#### wrote:

> I was totally wrong: the cblock "variables" actually hold the address. I
> was wrongly thinking about cblocks as C structures...
>
> Obviously I have no idea how the assembler works :-[
>
> My apologies,
> Borut
>
>
> On 07. 09. 2012 10:15, Borut Ražem wrote:
>
>> Hi Vaclav,
>>
>> I don't think you can get the address of CBLOCK variable.
>> The alternative is to use EQUs instead of CBLOCK:
>>
>> var1            EQU        0x20
>> var_array    EQU        0x21
>>
>>                     movlw    var_array
>>                     movwf    FSR
>>
>> Borut
>>
>> On 07. 09. 2012 09:52, Vaclav Peroutka wrote:
>>
>>> Hello,
>>>
>>> I want to use FSR/INDF in assembler. I have defined
>>>
>>>      CBLOCK    0x20
>>>          var1:    1
>>>          var_array:    1
>>>      ENDC
>>>
>>> In the code, I want to use
>>>     movlw address_of_var_array
>>>     movwf FSR
>>>
>>> and then to write to var_array through INDF.
>>>
>>> How can I do that ? I did not find any expression in gputils manual.
>>>
>>> Thank you in advance,
>>> Vaclav
>>>
>>
>>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: ####@####.####
> For additional commands, e-mail: ####@####.####
>
>


-- 
int main() { char *a,*s,*q; printf(s="int main() { char *a,*s,*q;
printf(s=%s%s%s, q=%s%s%s%s,s,q,q,a=%s%s%s%s,q,q,q,a,a,q); }",
q="\"",s,q,q,a="\\",q,q,q,a,a,q); }
Subject: Re: gpasm - how to get address of variable ?
From: Joe Pfeiffer ####@####.####
Date: 8 Sep 2012 17:04:57 -0000
Message-Id: <20555.31412.478275.849821@pfeifferfamily.net>

Assembly languages generally don't have a real concept of "variables" --
they have lower-level concepts like symbols with values, which we use
as variables.  A cblock is the way to get the assembler to
automatically assign values to symbols in a way that makes them useful
to us as variables -- they're really aren't structs.

Which reminds me that your use of

   var_array:  1

is a little bit odd.  From the name, it sounds like you want that
symbol to be useful as an array.  If that's the case, you should
allocate as much space to it as you need for your array.  If you want
a five element array, you'd say

   var_array:  5

Borut Ražem writes:
>I was totally wrong: the cblock "variables" actually hold the address. I 
>was wrongly thinking about cblocks as C structures...
>
>Obviously I have no idea how the assembler works :-[
>
>My apologies,
>Borut
>
>On 07. 09. 2012 10:15, Borut Ražem wrote:
>> Hi Vaclav,
>>
>> I don't think you can get the address of CBLOCK variable.
>> The alternative is to use EQUs instead of CBLOCK:
>>
>> var1            EQU        0x20
>> var_array    EQU        0x21
>>
>>                     movlw    var_array
>>                     movwf    FSR
>>
>> Borut
>>
>> On 07. 09. 2012 09:52, Vaclav Peroutka wrote:
>>> Hello,
>>>
>>> I want to use FSR/INDF in assembler. I have defined
>>>
>>>      CBLOCK    0x20
>>>          var1:    1
>>>          var_array:    1
>>>      ENDC
>>>
>>> In the code, I want to use
>>>     movlw address_of_var_array
>>>     movwf FSR
>>>
>>> and then to write to var_array through INDF.
>>>
>>> How can I do that ? I did not find any expression in gputils manual.
>>>
>>> Thank you in advance,
>>> Vaclav
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: ####@####.####
>For additional commands, e-mail: ####@####.####
>

-- 
Joseph J. Pfeiffer, Jr., Ph.D.                 http://pfeifferfamily.net/
1440 Tierra del Sol Dr                         575.525.2764 (H)
Las Cruces, NM 88007                           575.496.3501 (C)
[<<] [<] Page 1 of 1 [>] [>>]


Powered by ezmlm-browse 0.20.