I've recently been working on a library of routines for the Prizm. I intend these to eventually form the basis of an on-calc language similar to Axe, but the routines are for the moment being written so that Assembly programmers can use them. At the moment, I am working on multiple libraries, of which the math library is the farthest along. Here are a few routines in case anyone wants to use them.


Code:
/* Mod */

Info:
   Performs the operation R1 Mod R2
   12 bytes
   7 cycles
   Unsigned
   Can operate in both processing modes
   Inline function
   
  Registers Destroyed:
   R1
   R2
   R3
   MACH

SH3 Hex:
   6133321432150009010A3138



Code:
/* Arbitrary precision addition (unsigned) */

Info:
   Performs the unsigned operation R1+R2
   30 bytes
    12*(# of bytes in operands)+4 cycles
   Inline function

  Registers Destroyed:
   R0
   R1
   R2
   R3
   R4
   R5
   R6
   R7
   SR
SH3 Hex:   
   E000400455106620365E070233008D05246441104210470EAFF406292460



Code:
/* Arbitrary precision subtraction (unsigned) */

Info:
   Performs the unsigned operation R1-R2
   28 bytes
    13*((# of bytes in operands)-1)+9 cycles
   Inline function

  Registers Destroyed:
   R0
   R1
   R2
   R3
   R4
   R5
   R6
   R7
   SR

  Other notes:
   Don't let R2 be greater than R1!
   R1 and R2 are pointers to the locations of the least significant bytes (highest addresses) of the operands in memory.
   R3 hold the number of bytes of the operands. If the operands differ in size, zero extend the shorter one. Must be greater than 0.
   R4 holds a pointer to the least significant byte (highest address) of the output location.
   The output location must have at most R3+1 bytes available for the answer.

SH3 Hex:
   E000400465106620365A070233008D05246441104210470EAFF47001



Code:
/* Linear Congruential Random Number Generator */
R1 == R4*R1 mod R3

Info:
   40 bytes
   Subroutine, not an inline function.
  Other info:
   The routine automatically loads a constant seed.
   If you would like to seed it yourself, then set the least significant bit of R0 and put the seed in R1. The output is returned in R5.
   If you call this routine multiple times, then you are responsible for seeding the RNG in R1 with the results of the previous computation from R5.

SH3 Hex:
   40058F0D73173415D304010A6513335433550009050A3518000B000905F5E101AFF1D10002D63A86


Let me know if you have any routines you'd like to submit, optimizations to make or bugs to report.
I can't believe I missed this the first time around! Perhaps we need a stickied topic for nifty routines like we have in the z80 ASM and TI-BASIC subfora?
A couple of those don't quite work because I screwed up my division.
Qwerty.55 wrote:
A couple of those don't quite work because I screwed up my division.
Out of curiosity, did you take a look at the Z80 Bits routines and try to port those? If not, those might be a valuable resource.
I looked at some other Assembly implementations, but I made some SuperH specific optimizations to those routines.
Qwerty.55 wrote:
I looked at some other Assembly implementations, but I made some SuperH specific optimizations to those routines.
Ah, excellent, that's great to hear. I'll try to get myself learning SH3 ASM so I can help out, although for the sake of speed, I'm probably intending for my first few programs to be in C. I think an early order of business will definitely be a Doors CS port to the Prizm to allow us to load arbitrary ASM programs.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
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

 

Advertisement