Author Topic: A few simple questions...  (Read 13121 times)

0 Members and 2 Guests are viewing this topic.

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
A few simple questions...
« on: August 09, 2010, 12:17:13 pm »
Hi - Axe is great, isn't it?  I just discovered it last week.
I have a few questions though:
1) How do pointers work?  I think I understand the basic concept, but I'm not entirely sure what the difference is between doing this
Code: [Select]
5->A and
Code: [Select]
5 ->{A}2) Also, I tried using the routine in the User's Manual to try to copy an external variable, but I keep getting this weird sort of hexadecimal thing
Code: [Select]
"varG"->Str1
GetCAlc(Str1)->P
Disp {P}[sup]r[/sup]>DEC          (The triangle with the DEC to the right)
And this gives me weird values - especially if I try storing decimals, large, or negative values to G.  Am I doing this wrong? 

I apologize if any of these questions are stupid...  :(
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

_player1537

  • Guest
Re: A few simple questions...
« Reply #1 on: August 09, 2010, 12:20:59 pm »
Do you understand the concept of ram?  There is a way to access the ram, and edit it.  So say that there is some ram at spot 1337 that you want to edit.  One way you could do this is:
1337->A
Data->{A

Another way (faster) would be:
Data->{1337

I'll try to explain it a little better in a minute if someone doesn't beat me (not saying that you shouldn't try to beat me to it)

Offline yunhua98

  • You won't this read sentence right.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2718
  • Rating: +214/-12
  • Go take a dive in the River Lethe.
    • View Profile
Re: A few simple questions...
« Reply #2 on: August 09, 2010, 12:24:59 pm »
I'm not an expert with Axe, and I haven't tried the external variables thing, but I believe the difference between the first two are storing a value to a location and storing a location to a pointer.  (Am I right?)
the first one stores the value to the pointer, while the second one puts the pointer at the location 5 on RAM.
And don't worry about asking questions you think may be stupid, because we are all here to help.

If I'm wrong about this, will someone please correct me?  I find myself having trouble with pointers as well, this may or may not be why.  ;)


Spoiler For =====My Projects=====:
Minor setback due to code messing up.  On hold for Contest.
<hr>
On hold for Contest.


Spoiler For ===Staff Memberships===:






Have you seen any good news-worthy programs/events?  If so, PM me with an article to be included in the next issue of CGPN!
The Game is only a demo, the code that allows one to win hasn't been done.
To paraphrase Oedipus, Hamlet, Lear, and all those guys, "I wish I had known this some time ago."
Signature Last Updated: 12/26/11
<hr>

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: A few simple questions...
« Reply #3 on: August 09, 2010, 12:31:15 pm »
Glad you like it!

1) The first one stores the value 5 into the A variable.  The second one stores a value 5 somewhere in ram at the address A.  You can think of memory as a bunch of boxes, so if A were 1000, you'd be putting a 5 into the 1000th box.  But there are only a few boxes you can use (the free ram) since the operating system uses so many of them.  So don't actually try storing anything to {1000} because that's OS territory.  Overwriting OS stuff is a common cause of ram clears.

2) Real Numbers are stored in the most bizarre format so its extremely hard to read them, I will be adding a converter command eventually.  The first byte is some kind of bit field that also controls the negative sign, the next byte holds the exponent and then the next 7 bytes after that holds the number, but in BCD format (binary coded decimal) so you can't just read it off like a number.
___Axe_Parser___
Today the calculator, tomorrow the world!

_player1537

  • Guest
Re: A few simple questions...
« Reply #4 on: August 09, 2010, 12:31:49 pm »
The way I read that code is:
store 5 to A
and
store 5 to at A

Because first stores it to the variable A (which is just a location in ram [L1-54 iirc])  and the second one stores to the location of A.  So if A is 666, it will try to store 5 to the location 666

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: A few simple questions...
« Reply #5 on: August 09, 2010, 12:39:57 pm »
I recommend against storing to RAM values you are not sure what they are. To store temporary data, I recommend using L1, for example. Those are called SafeRAM areas (idk if I spelled it right) and in L1, for instance, there is about 712 bytes of space to store stuff. Be careful when using the others, though, such as L2 through L6. You need to check the commands.html file to see what they may conflict with.

Also welcome to the forums. Glad you like Axe :)

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: A few simple questions...
« Reply #6 on: August 09, 2010, 01:39:28 pm »
just wanted to add in that with external var support, you should generally stick with storing to Strings and appvars. lists, matrices and real variables have complicated formats so they can hold large numbers and decimals.

as for pointers, maybe this will help. imagine RAM as like a train. and each segment of the train is numbered: 0, 1, 2, 3, 4, 5 etc. It's very orderly. to get a segment of the train, you use curly brackets {}. {0} would return whatever number is in the first box of RAM. as quigibo said, do not overwrite this data, as the OS uses it, and you could easily screw up your calculator by just filling random addresses with numbers. However, quigibo has "safe RAM" areas in axe, which you can modify as you wish, as DJ said, they're L1-L6. L1-L6 are called "pointers". i personally like to call them in my head as "markers", since to me they mark segments of the train. each safe RAM segment contains a certain number of boxes. so 5->{L1} stores 5 into the box at L1. now i've been using the term "box" to describe each segment on the train, aka each segment of RAM. for the record, each segment of RAM is 1 byte. i won't get technical, but basically that means you can store between 0 and 255 into each box. if you try 256->{L1}, the numbers loop back around. so L1 will hold the value 0. 0=256. 1=257. i know. crazy. however, variables A-Z+theta can hold up to 65535.

variables have always intrigued me at first, as i never understood them in Axe. one more long paragraph:

A-Z+Theta are pointers. they point to a box number. 0->A does not store the value 0 into A. it tells A to "point" to RAM address 0. remember how L1-L6 are just "markers" on the train of RAM? same thing with variables. basically, you should rarely use curly brackets {} around just a variable, as that will usually turn out to be some information that the OS uses to run, and if overwritten, may RAM clear. basically, variables are like markers of RAM addresses.


Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: A few simple questions...
« Reply #7 on: August 10, 2010, 12:37:42 pm »
Okay, so to summarize...
If I do 5->A, the calculator will create a (temporary?) variable, and store 5 to it?
And if I do 5->{A}, the calculator will go to location A in the RAM and overwrite whatever was there then store 5 to it?
And I should avoid using curly braces except for L1 and L2.
Stick to strings and appvars, because the other data types are weird.
Am I right?

Also, I have several more questions:
3) How much is a byte?  I think nemo said that 1 byte can hold up to 255, so would that mean that 1 byte is equal to 2 hexadecimal characters? (like FF would be 1 byte?)
4) DJ Ommimaga said that there are about 712 bytes of space in L1 (and probably L2) - so I would use those two if I wanted to construct a list of some kind?
5) What are the differences between the variables A-Theta and using Str, Pic, and GDB?  Is it safe to use curly braces around those?
6) I think curly braces are used primarily for creating lists in safe RAM spaces - my numbers would be in sequential order.  Is that correct?  What other things can pointers be used for?
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: A few simple questions...
« Reply #8 on: August 10, 2010, 01:09:46 pm »
you're somewhat right. you can treat A-Z and theta as normal vars as you would in BASIC (just don't go over 65535, negatives are a little trickier to figure out, and don't try to store a floating point). if you do 5->A, A will be a pointer to the RAM address 5. it's not really necessary to understand this. but you should know that doing Expression->{A} is generally bad, because you're overwriting RAM that the OS may need to function.
curly braces are your friend, if you're using L1-L6 and static pointers (GDB, Pic, Str). quick code example. say you have a list of 5 numbers. 2,12,38,25 and 3. how might you create this list?
Code: [Select]
.HEADER
[020C261903]->GDB1    .Stores the data as hexadecimal
Data(2,12,38,25,3)->GDB2    .Stores the same data in GDB2.
For(A,0,4
Disp {GDB1+A}>Dec,i       .imaginary i. GDB1 can be replaced with GDB2 for the same results.
End

alright. for starters, what are GDB1 and GDB2? they are static pointers. they basically mark some data. each piece of data is only one byte (two bytes is more advanced). curly brackets return the byte that the pointer points to. this is another way of saying that a curly bracket takes the marker (GDB1) and returns whatever is inside of it (2). since data is stored linearly in RAM, we can add one to GDB1 to get the next byte. {GDB1} will return what's at GDB1 (which is 2) and {GDB1+1} will return the next byte (12).

hopefully that helps. it takes awhile to get used to.

and yes, when you're using external variables, strings and appvars are the easiest to deal with.

3) yes. FF is one byte. F is a half-byte (also known as a "nibble"). a bit is either a 0 or a 1. a byte is 8 bits. meaning, a byte is 8 1's or 0's. since there are two possible values a bit can hold (a 0 or a 1), and a byte has 8 bits, a byte can hold 2^8=256 different values. 0-255.

4) in the Commands document, the lengths of L1-L6 are defined. using L1 is the safest to use, so i'd say that L1 is probably the best to use.

5) i kinda explained this above, but to reiterate. A-Theta are pointers, but the RAM they point to can be changed. Str, Pic and GDB are static pointers. that means you tell them what data to point to at the beginning of the program, and they will point there throughout the program. using curly braces around Str, Pic and GDB is definitely ok.

6) curly braces are used to get a value from a pointer. it's very useful for lists of numbers, such as map data. i'm not sure what other things pointers can be used for, a computer/ASM programmer probably uses them more creatively.


Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: A few simple questions...
« Reply #9 on: August 13, 2010, 01:48:27 pm »
Mm - I've been messing around with pointers for a couple of days now, and I think I've sort of got the hang of it - or at the very least, I'm not going to do something stupid.  :P
So, thanks!

I have another question though - in the list of commands, it says something about interrupts - what are interrupts, and how do I use them?
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline calcdude84se

  • Needs Motivation
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2272
  • Rating: +78/-13
  • Wondering where their free time went...
    • View Profile
Re: A few simple questions...
« Reply #10 on: August 13, 2010, 02:05:18 pm »
Interrupts are something the calculator generates at a fixed rate. The normal speed is about 110Hz, or 110 times every second.
FnOff will turn these off. This gives you slightly faster speed, and you can do some stuff you normally couldn't because the OS would mess with it (Like linking). However, you cannot use the normal getKey, but you instead have to use getKey(9) et al. (Well, if you use fnInt( you can't. But otherwise it would just turn them back on anyway) FnOn turns these back on.
fnInt( can be used to make your own interrupt. The normal interrupt is the OS's and does stuff like check for keys, link activity, etc. To use your own interrupt, you use fnInt(LB,F), where LB is the subroutine you want to execute on the interrupt and F is how often to execute it. It can be 0, 2, 4, or 6 and must be a constant, not a variable.
Say you had a subroutine I. To make it an interrupt that executes as often as possible, you can use fnInt(I,0 to set it up.
The routine I will execute at 110Hz. Note that you shouldn't use DispGraph or either of its modified versions in an interrupt.
In addition, DispGraphrr might need an FnOn after it because it disable interrupts.
"People think computers will keep them from making mistakes. They're wrong. With computers you make mistakes faster."
-Adam Osborne
Spoiler For "PartesOS links":
I'll put it online when it does something.

Offline FinaleTI

  • Believe in the pony that believes in you!
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1830
  • Rating: +121/-2
  • Believe in the pony that believes in you!
    • View Profile
    • dmuckerman.tumblr.com
Re: A few simple questions...
« Reply #11 on: August 13, 2010, 03:38:24 pm »
In addition to calcdude's post, in the latest version of Axe, there is a bug involving the label you use for an interrupt.

Quote from: Runer112
Actually, you may be onto something. I assumed 0.4.3 fixed the label errors, but apparently it didn't. The problem appears to be with the fnInt()  command. As far as I can see, the problem is that, using whatever shortened character set Quigibo uses to store label name data (if I had to guess, 0-9 A-Z), the first character of the label name called is always misinterpreted. It seems that this character is stored with a value 10 less than what it should be. In one of my programs, I want to enable "INT" as an interrupt. When compiling, fnInt(INT,6) throws a missing label error, claiming that "8NT" is missing. fnInt(ZNT,6)  throws an error, claiming that "PNT" is missing. In both of these names returned, the first character has a value 10 less than what it should be. fnInt(SNT,6), however, compiles correctly, as S is 10 letters ahead of I in the alphabet.

This error only appears to happen with fnInt(), not sub() or Goto.


Spoiler For Projects:

My projects haven't been worked on in a while, so they're all on hiatus for the time being. I do hope to eventually return to them in some form or another...

Spoiler For Pokemon TI:
Axe port of Pokemon Red/Blue to the 83+/84+ family. On hold.

Spoiler For Nostalgia:
My big personal project, an original RPG about dimensional travel and a few heroes tasked with saving the world.
Coding-wise, on hold, but I am re-working the story.

Spoiler For Finale's Super Insane Tunnel Pack of Doom:
I will be combining Blur and Collision Course into a single gamepack. On hold.

Spoiler For Nostalgia Origins: Sky's Story:
Prequel to Nostalgia. On hold, especially while the story is re-worked.

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: A few simple questions...
« Reply #12 on: August 16, 2010, 12:42:05 am »
I'm not entirely sure about the variables in Axe either.

I was trying to code a basic gravity simulation using a single pixel as a ball. What I ended up writing was:

Code: [Select]
.AA
ClrDraw
47->X
5->Y
0->V
Rect(0, 60, 96, 4)
For(A, 0, 200)
DispGraph
V-9.8->V
Y+V->Y
Pxl-On(X,Y)
Pause
If Y+2V>60
-V->V
End
End

When the code is compiled and run, it displays the initial graphics and then runs the rest of the program without moving the pixel. Looking at the documentation accompanying Axe, I can see that the included Pong program uses similar variable assignment, so I'm unsure of what exactly the problem is. Any help would be greatly appreciated. Axe takes a bit of getting used to, although the speed is a breath of fresh air after TI-BASIC.
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: A few simple questions...
« Reply #13 on: August 16, 2010, 12:47:09 am »
Well im not sure what the compiled program is doing, but i know what the problem is

V-9.8->V

Axe works with integers only, so this line doesn't do what you think it does.  I am surprised it actually compiles, but it might have to do with the fact that a period designates the start of a comment.  My guess is that it is reading the code like this

V-9

Which doesn't do anything to V, and so your velocity never changes, and your pixel doesn't move.

Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: A few simple questions...
« Reply #14 on: August 16, 2010, 01:14:54 am »
No decimals? I suppose that I'd have to approximate with 10, then. That works, although it appears that I'll have to modify my formulae to get a more realistic "bounce." This simulation would be a lot more suited to a mathematically inclined language like TI-BASIC. Oh well, what's a challenge if not a chance to learn [and clear your RAM in the process]?
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ