To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.nqcOpen lugnet.robotics.rcx.nqc in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / NQC / 1366
1365  |  1367
Subject: 
Re: maximum number of variables in RCX2 ?
Newsgroups: 
lugnet.robotics.rcx.nqc
Date: 
Thu, 21 Feb 2002 00:41:48 GMT
Viewed: 
3431 times
  
In article <GrtLHx.E8E@lugnet.com>, "John Guerquin"
<jguerquin@sympatico.ca> wrote:

When using the RCX2 target, the NQC manual (Section 2.2.4) states that 32
global variables, and 16 local variables (per task) are allowed.  Does
this
mean that the whole program can only have 48 variables total when using
only
one task, ie. "main" , and several functions?

The reason I ask this question, is that my understanding of local
variables
is that space is allocated only when the function has been called.  Once
the
function is complete, the memory that was used to store those local
variables is returned back to the ‘memory pool’.

Lego's usage of the terms'local' and 'global' is a little different than
what most people expect.  In the RCX, global storage is available across
all tasks while local storage is avaialble per task.  This is different
from the more traditional terminology where global variables are
available throughout the program and local variables are only valid
within some smaller scope (typically a function call).

When talking about NQC I often differentiate between variables (which
are the things the programmer asks for in NQC) and storage (which are
the slots of memory used within the RCX).

The compiler's job is to assign storage locations for all of the
variables you want to use.  There are a few constraints...

* global variables must go in global storage

* local variables in a sub that is called from more than one task must
go in local storage

* global storage is usually more precious, so local storage is preferred
whenever the compiler can use it safely (temp results are always good
candidates for local storage)

Note that functions don't really exist at runtime...there are no stack
frames, no recursion, no return addresses.  Function calls in NQC get
expanded out (similar to inline functions in C++).

If anyone could clarify
the limitations of NQC variables, as well as how the limitations apply to
arrays, I would greatly appreciate it.

In general, making variables local to a task/function/sub will allow the
compiler to more efficiently make use of the RCX storage since it can
place those variables wherever it wants.  It can also figure out how to
reuse storage locations (either across tasks or even within a task if
the variable lifetimes don't overlap).

Arrays must fit entirely in local or global storage - I don't try to
split the array across the storage.  In theory this means a hard limit
of 32, although in many cases you can't even use that large an array.

Dave Baum

--
reply to: dbaum at enteract dot com



Message is in Reply To:
  maximum number of variables in RCX2 ?
 
When using the RCX2 target, the NQC manual (Section 2.2.4) states that 32 global variables, and 16 local variables (per task) are allowed. Does this mean that the whole program can only have 48 variables total when using only one task, ie. "main" , (...) (23 years ago, 20-Feb-02, to lugnet.robotics.rcx.nqc)

5 Messages in This Thread:




Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR