• Axe Q&A 5 5
Currently:  

Author Topic: Axe Q&A  (Read 580988 times)

0 Members and 4 Guests are viewing this topic.

Offline parserp

  • Hero Extraordinaire
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1455
  • Rating: +88/-7
  • The King Has Returned
    • View Profile
Re: Axe Q&A
« Reply #1485 on: May 07, 2012, 03:45:10 pm »
If I have 8 chars stored in L1, and I want to copy them to str0+1, the following code works in a normal program, but not in an app.
Code: [Select]
:Copy(L1,Str0+1,8)

Why is that?

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Axe Q&A
« Reply #1486 on: May 07, 2012, 03:59:16 pm »
I'm guessing you are defining Str0 to be a pointer to a block of data set aside inside of your executable, perhaps like this:

Buff(10)→Str0

This works fine for programs, as they are run from RAM so the 10-byte block of data is contained inside of the program in RAM. But applications are run from ROM, which you probably know stands for read-only memory. And as the name suggests, you cannot* write data to ROM, so attempting to write data back to Str0, which is part of your application in ROM, will fail.

The solution for applications is to use a section of safe RAM or an appvar to hold any data that will be modified.


* Data can be written to ROM, but it's through a complicated method of interfacing with the flash chip that usually involves backing up a whole 64KB of data, erasing the original 64KB of data, and then copying the 64KB back to its original location with the desired changes made.
« Last Edit: May 07, 2012, 04:02:21 pm by Runer112 »

Offline parserp

  • Hero Extraordinaire
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1455
  • Rating: +88/-7
  • The King Has Returned
    • View Profile
Re: Axe Q&A
« Reply #1487 on: May 07, 2012, 04:10:27 pm »
O.O That is exactly what I was doing. Now it makes sense. Thanks! :D
Spoiler For Spoiler:
* parser padwan nominates Runer112 the official omnimaga mind reader :P
« Last Edit: May 07, 2012, 04:10:50 pm by parser padwan »

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Axe Q&A
« Reply #1488 on: May 08, 2012, 01:47:21 am »
Me again, with my conditional comments :P
The problem with ending a conditional comment with "..." is that if I do the code 1 (below), the parser would understand the code 2 (below)

     Code 1:
code
...If Const
code
...
code
...
code
...
etc

     Code 2:
code
...If Const
code
...
code
...
code
...
etc

If the conditional comment ended with "...End", the parser would know the difference between a beginning and an end.
So would it be possible to change this in Axe, so that we end a conditional comment with "...End" ?
« Last Edit: May 11, 2012, 02:13:59 pm by Hayleia »
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline C0deH4cker

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 258
  • Rating: +11/-1
    • View Profile
    • iNinjas Forum/Repo
Re: Axe Q&A
« Reply #1489 on: May 14, 2012, 07:21:27 pm »
Can recursive functions be created in Axe? Like a simple fibonacci sequence generator or factorial function?

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Axe Q&A
« Reply #1490 on: May 14, 2012, 10:11:25 pm »
You can, but it's not recommended because each nested call takes space on the stack, and going too deep leaves you with a nice stack overflow.




Offline C0deH4cker

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 258
  • Rating: +11/-1
    • View Profile
    • iNinjas Forum/Repo
Re: Axe Q&A
« Reply #1491 on: May 14, 2012, 11:28:07 pm »
For some reason, even a simple factorial program did not work correctly for me.

Code: [Select]
Lbl Fact
If r1 <= 1
1:Return
End
r1*Fact(r1-1):Return

Can somebody post a working sample?
« Last Edit: May 14, 2012, 11:28:26 pm by C0deH4cker »

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Axe Q&A
« Reply #1492 on: May 15, 2012, 12:11:39 am »
How big are the numbers you're testing with?

EDIT: In your code, r1 gets overwritten. You need to call FACT as sub(FACTr,r1-1).
« Last Edit: May 15, 2012, 12:13:08 am by Deep Thought »




Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Axe Q&A
« Reply #1493 on: May 15, 2012, 12:45:58 am »
For some reason, even a simple factorial program did not work correctly for me.

Code: [Select]
Lbl Fact
If r1 <= 1
1:Return
End
r1*Fact(r1-1):Return

Can somebody post a working sample?

Your routine worked fine for me. :) Just note that, for factorials of numbers larger than 8, the calculation will overflow so the result returned will be incorrect.

EDIT: In your code, r1 gets overwritten. You need to call FACT as sub(FACTr,r1-1).

Actually this is not the case. Once *Fact( is reached, the first r1 has already been pushed onto the stack.



And because I can't resist optimizing, here is a very optimized recursive factorial function I came up with, weighing in at 17 bytes. ;D

Code: [Select]
Lbl Fact
!If
Return +1
End
Return *(-1Fact())

Offline C0deH4cker

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 258
  • Rating: +11/-1
    • View Profile
    • iNinjas Forum/Repo
Re: Axe Q&A
« Reply #1494 on: May 15, 2012, 03:48:52 pm »
Lol thanks! And youre right, my way did work, but i was typing it on here from memory and also working it out in my head when i typed it, so i typed a correct version instead.


My Fibonacci program just causes a RAM Clear, probably due to a stack overflow. Z80 processors aren't very good with recursion, are they?

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Axe Q&A
« Reply #1495 on: May 15, 2012, 04:08:47 pm »
They are fine with recursion, it just takes a lot of memory the way Axe does it, since it backs up all 6 variables each time you call the routine

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Axe Q&A
« Reply #1496 on: May 15, 2012, 04:26:09 pm »
They are fine with recursion, it just takes a lot of memory the way Axe does it, since it backs up all 6 variables each time you call the routine

Nope, Axe only backs up the function variables that you would overwrite with the call. So something like sub(LBLr,A) only pushes 2 words onto the stack, the previous value of r1 and the return address (required for any function call).

My Fibonacci program just causes a RAM Clear, probably due to a stack overflow. Z80 processors aren't very good with recursion, are they?

That depends how deep you need to recurse. The OS has allocated 400 bytes for the stack, which gives you space for 200 stack entries. You can expect about 20 of these to be in use when your program is run, so you have an allowance of roughly 180 stack entries. That's about 90 recursive calls with one argument, 60 recursive calls with two arguments, etc. So as long as you don't overflow the stack, the z80 is fine at recursion. Overflow the stack, and expect a RAM clear.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Axe Q&A
« Reply #1497 on: May 15, 2012, 04:31:55 pm »
Oh that's good!  However, some functions like fibonacci might be easy to implement with recursion, but they they are incredibly inefficient >.<

Offline C0deH4cker

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 258
  • Rating: +11/-1
    • View Profile
    • iNinjas Forum/Repo
Re: Axe Q&A
« Reply #1498 on: May 16, 2012, 10:50:35 pm »
Yeah. I could easily write it without recursion (I wrote a fibonacci function in asm before), but recursion is just easier, and I think it is more fun due to the different method of thinking required for programming recursively.

Offline piston

  • LV0 Newcomer (Next: 5)
  • Posts: 1
  • Rating: +0/-0
    • View Profile
Re: Axe Q&A
« Reply #1499 on: May 25, 2012, 12:04:10 pm »
Where can I find the Freq() function?
Also what do the green Key:Sinreq mean? Is that supposed to be an indication as to where i can find Freq() ?