Shop OBEX P1 Docs P2 Docs Learn Events
LMM programming — Parallax Forums

LMM programming

richaj45richaj45 Posts: 179
edited 2012-06-01 08:30 in Propeller 1
Hello:

Has any one written pasm programs in the large memory model directly?

That is a large assemble program using the interpreted instructions for am LMM engine.

If so, which tool is used to assemble the source code?

Thank you,
rich

Comments

  • BeanBean Posts: 8,129
    edited 2012-05-31 09:27
    I would suggest BST.
    That is what PropBASIC uses to compile the LMM code that it generates.

    Bean
  • Heater.Heater. Posts: 21,230
    edited 2012-05-31 09:34
    Or you could use the assembler that propgcc uses, gas normally run under the command name "as".
    Don't forget, it is not just a case of writing LMM code. You need an LMM kernel to run the resulting instructions and something to start that kernel with. propgcc of course has all that. You can probably do it with Catalina as well.
  • RossHRossH Posts: 5,512
    edited 2012-05-31 15:37
    Heater. wrote: »
    Or you could use the assembler that propgcc uses, gas normally run under the command name "as".
    Don't forget, it is not just a case of writing LMM code. You need an LMM kernel to run the resulting instructions and something to start that kernel with. propgcc of course has all that. You can probably do it with Catalina as well.

    Heater is correct - with LMM the code has to be written to match the kernel that will execute it. But you don't need a special LMM assembler - BST, Homespun or even the Parallax Spin compiler can do it (but note that the latter is limited to 32k of code, the former are not).

    Ross.
  • richaj45richaj45 Posts: 179
    edited 2012-05-31 16:22
    Thanks for your response.

    So were can i find the source code for one of these LMM engines that was mentioned?

    cheers,
    rich
  • RossHRossH Posts: 5,512
    edited 2012-05-31 20:21
    richaj45 wrote: »

    So were can i find the source code for one of these LMM engines that was mentioned?

    cheers,
    rich

    With Catalina, just download any version (the latest version is here), install it and look in the folder target for the file Catalina_LMM.spin - this is the Spin/PASM source code for the Catalina LMM kernel, and it will be automatically included in any C program. While you could load and start it manually, a simple way to run your own hand-written LMM PASM program with Catalina is to call it from C function. For instance, here is a working example:

    Save the following C program as example.c:
    #include <stdio.h>
    
    extern int find(int);
    
    void main(void) {
       int cog = find(0);
       printf ("kernel found running on cog %d\n", cog);
    }
    

    This program simply calls a function (called find) with the parameter 0 (for the kernel) and prints the result (which will be the cog on which the kernel is found).

    The function find was hand written to follow the Catalina conventions and is shown below (save it as find.e):
    ' Catalina Code
    DAT ' code segment
    ' Catalina Export find
    ' Catalina Import _registry
     long ' align long
    
    
    C_find
     jmp #CALA
     long @C__registry
     mov r4, r0
     mov r0, #0
    C_find_L1
     rdlong r3, r4
     shr r3, #24
     cmp r3, r2 wz
     jmp #BR_Z
     long @C_find_L2
     add r4, #4
     add r0, #1
     cmp r0, #8 wc,wz
     jmp #BR_B
     long @C_find_L1
     neg r0, #1
    C_find_L2
     jmp #RETN
    
    
    ' end
    

    You would compile this with the command:
    catalina example.c find.e -lci
    
    The conventions that such hand written PASM programs must follow (e.g. how to accept and pass parameters, what PASM instructions cannot be used in LMM programs, and how to invoke various "primitives" implemented in the LMM kernel) are described in the Catalina Reference Manual.

    Ross.
  • RossHRossH Posts: 5,512
    edited 2012-05-31 20:46
    Sorry, rich - just had to fix an error in the post above. I pasted in the wrong file!

    Ross.
  • Dave HeinDave Hein Posts: 6,347
    edited 2012-06-01 04:50
    You could try the SpinLMM object at http://obex.parallax.com/objects/635/ . This object patches an LMM interpreter into the Spin interpreter, which allows you to call LMM routines from a Spin program. The documentation describes how the LMM interpreter works, and it gives some simple examples of LMM code.
  • richaj45richaj45 Posts: 179
    edited 2012-06-01 08:30
    Thanks much for your response.

    I am going to start looking at the code you all have pointed me to.

    cheers,
    rich
Sign In or Register to comment.