Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI-Nspire => Topic started by: lkj on March 11, 2015, 01:41:14 pm

Title: nAssembler - Nspire on-calc assembler
Post by: lkj on March 11, 2015, 01:41:14 pm
As the title suggests, this is an on-calc assembler for the Nspire :)
It's written in python, so you need micropython on your calc.
All instructions I'm aware of are supported (except CDP, LDC, STC. They are useless on the Nspire)
What's still missing are some pseudoinstructions which don't add functionality but make your life easier,
like for example automatically creating x when you write LDR R0, =x
There is also no linker or anything which means that programs are just translated to binary in the order
they are written and the first line is also the entry point.
Read the readme in the spoiler below for more details on the assembly language syntax used or look at the example.


Please report bugs, missing instructions and feature suggestions.
The code is available at https://github.com/lkjcalc/nAssembler (https://github.com/lkjcalc/nAssembler)

Download from tiplanet archives: https://tiplanet.org/forum/archives_voir.php?id=821835 (https://tiplanet.org/forum/archives_voir.php?id=821835)


Spoiler For Readme:
Usage
-----
Install micropython on your calc.
Launch the nassembler.py.tns file using micropython.
The program will ask you to specify the input file (containing the assembly source code)
and the output file (where the binary will be stored).
You have to specify the full path (for example /documents/test/clrscr.asm.tns)
If there are no errors, micropython will now tell you "Press any key to exit".
You should now see the output file after refreshing the docbrowser
(just go to the homescreen and back to the docbrowser).

Assembly language
-----------------
(Also look at the examples)
IMPORTANT (syntax is not very flexible at the moment):
-Instruction names must be preceded by whitespace
-Labels must not be preceded by any whitespace
-The instruction names and syntax are like in standard ARM assembly
(like in the official ARM online documentation)
-No automatic substitution of e.g. MVN for MOV if the immediate value can only be encoded in the inverted case
-Two operands were three are required is not allowed (no implicit destination register), e.g. "ADD r0,#28" must be written out as "ADD r0,r0,#28"

All usual instructions are supported:
ADC(S), ADD(S), AND(S), B, BIC(S), BL, BX, CLZ, CMP, CMN,
EOR(S), LDM.., LDR(B/T/BT/H/SH/SB), MCR, MLA(S), MOV(S),
MRC, MRS, MSR, MUL(S), MVN(S), ORR(S),
RSB(S), RSC(S), SBC(S), SMLAL(S), SMULL(S), STM..,
STR(B/T/BT/H), SUB(S), SVC/SWI, SWP(B), TEQ, TST, UMLAL(S), UMULL(S)

The DCD, DCDU, DCW, DCWU, DCB and ALIGN directives are supported.

The ADR pseudo instruction is now also implemented.

Some other pseudo instruction (like PUSH etc) are not implemented.
Other instructions may be missing (report if you need one).

The first line of the source is also the entry point of the program.

Numeric literals:
Prefix with 0x for hexadecimal numbers, 0 for octal, 0b for binary.
Single characters enclosed in single quotes ' are interpreted as their ascii value
You can use DCB "some string" to create a string.

Feature suggestions/Bug reports
--------------------------------------------
Here or in the following places:
Topic on tiplanet: https://tiplanet.org/forum/viewtopic.php?t=16174&p=178789
Code on github: https://github.com/lkjcalc/nAssembler (https://github.com/lkjcalc/nAssembler)
Title: Re: nAssembler - Nspire on-calc assembler
Post by: Matrefeytontias on March 11, 2015, 04:59:10 pm
Damn that's awesome ! :D Many people have been wanting that to happen. Congratulations for making it happen !
Title: Re: nAssembler - Nspire on-calc assembler
Post by: Harry5862 on March 13, 2015, 11:23:47 am
I cant open nAssembler.
I have installed Ndless 3.6 and nAssembler in the same directory as micropython.
Why??
Any suggestion?
Title: Re: nAssembler - Nspire on-calc assembler
Post by: lkj on March 13, 2015, 04:04:37 pm
Have you opened micropython at least once before opening nAssembler?
Did you rename one of the files?
Title: Re: nAssembler - Nspire on-calc assembler
Post by: Harry5862 on March 14, 2015, 02:47:58 am
no ,what should I type in then.
If I run micropython I cant exit?
And if I run nAssembler it just Show a blackscreen for 1 sec and then go back to the normal Screen.
BTW:CX CAS HW-J
Title: Re: nAssembler - Nspire on-calc assembler
Post by: lkj on March 14, 2015, 08:14:55 am
You should just open it once and quit again.
Maybe your micropython is older than the one I used to test it. In the version I use you can exit by pressing the  ESC key.
Can you try it again with the version at https://tiplanet.org/forum/archives_voir.php?id=89439 (https://tiplanet.org/forum/archives_voir.php?id=89439)?
Title: Re: nAssembler - Nspire on-calc assembler
Post by: Harry5862 on March 14, 2015, 02:26:52 pm
Ok it creates the file but I cant see the file in the normal file browser.
In Ndless Commander I can see the file but cant run it?
Title: Re: nAssembler - Nspire on-calc assembler
Post by: lkj on March 14, 2015, 04:38:19 pm
You should always append ".tns" to the name or it won't show up in the normal file browser. I'm not sure you can run programs in Ndless Commander?
Title: Re: nAssembler - Nspire on-calc assembler
Post by: Harry5862 on March 15, 2015, 04:19:28 am
OK now it works
I must leave the file browser and reload it. :banghead:
thx lkj
Title: Re: nAssembler - Nspire on-calc assembler
Post by: lkj on March 15, 2015, 02:42:51 pm
I'm glad it works now :)
Title: Re: nAssembler - Nspire on-calc assembler
Post by: neuronix on January 23, 2017, 07:53:18 am
When do you post a new update?
Title: Re: nAssembler - Nspire on-calc assembler
Post by: lkj on January 23, 2017, 04:45:54 pm
I didn't know anyone ever used this, so I didn't continue work on it  :P
What useful features are missing in your opinion?
Title: Re: nAssembler - Nspire on-calc assembler
Post by: neuronix on February 02, 2017, 04:12:45 am
Do you think that's possible to make a C compiler, in ARM, then compile the new code with nAssembly?
Title: Re: nAssembler - Nspire on-calc assembler
Post by: lkj on February 02, 2017, 07:54:22 am
Writing a new compiler for C, in assembly, would be a huge project. I don't think it's realistically possible.
Porting some existing compiler would be easier, but may still be hard.
Title: Re: nAssembler - Nspire on-calc assembler
Post by: neuronix on February 02, 2017, 07:58:51 am
Yes, it is a huge project, but a good project ;)
Title: Re: nAssembler - Nspire on-calc assembler
Post by: Chirlian on February 27, 2017, 11:17:22 am
Hi ikj,
may be there are some things missing, that only few people shows interest to your assembler.
Some points:
-installing should be easy. In the text file its explained, but not every beginner is able to work with it. A step by step describing would be better and it should content every step, also installing ndless and microphyton and pyWrite or another editor. Should folders me made? Which and where? For example, it's not clear in the beginning, that files have to be put in an ndless folder at root.
For example, I didnt get the nassembler to work up to now (already asking vogtinator about this).
Am using a nspire cx cas,
using os 4.4,
installed ndless 4.4,
started micropython (134/146) one time, as its told,
started nassembler but get error abour file format not supported.
May be that and the not so clear installation info hinders some interested people to try it.
Some simple lessons how to make the first short programs would be very helpful, some example programs you have already in your zip.
If you like I can give some more hints to that point.
cu
klaus

I didn't know anyone ever used this, so I didn't continue work on it  :P
What useful features are missing in your opinion?
Title: Re: nAssembler - Nspire on-calc assembler
Post by: Chirlian on March 03, 2017, 10:37:44 am
It's working now, was a simple mistake I made: for testing micropython 134 and 146 I did rename the both files (micropython 134 for example). So the .py files couldn't get connected and also nAssembler didn't run. Now everthing works.

Hi ikj,
may be there are some things missing, that only few people shows interest to your assembler.
Some points:
-installing should be easy. In the text file its explained, but not every beginner is able to work with it. A step by step describing would be better and it should content every step, also installing ndless and microphyton and pyWrite or another editor. Should folders me made? Which and where? For example, it's not clear in the beginning, that files have to be put in an ndless folder at root.
For example, I didnt get the nassembler to work up to now (already asking vogtinator about this).
Am using a nspire cx cas,
using os 4.4,
installed ndless 4.4,
started micropython (134/146) one time, as its told,
started nassembler but get error abour file format not supported.
May be that and the not so clear installation info hinders some interested people to try it.
Some simple lessons how to make the first short programs would be very helpful, some example programs you have already in your zip.
If you like I can give some more hints to that point.
cu
klaus

It's not the big thing but some simple aspects:
-as I said, a little more detailed instruction for all installing steps would be easier for the not so used ones. For example:

1. Get the actual OS version (now 4.4.0.xxx) from
https://education.ti.com/de/software/details/en/E7EE7A44207B41069B05C45A8149A7F9/ti-nspirecx_os
(don't know if links are allowed, otherwise a description how to get it from TI)
2. Install it. TI Link Software is needed.
if TI Link is not installed, load it from
https://education.ti.com/de/software/search/ti-nspire-cx-cas
and install it
3. backup everything on your nspire, all files will be deleted!
4. Start TI Link, connect your Nspire to your PC and install the new OS. Wait until all is done.

and so on. It's more in the style of 'XXX for dummies' or the 'Leittext Methode' (did work with it in education and it worked rather good. Especially beginners did like it.

Then some short lessons to help the people to learn how to handle the assembler, some basic infos and the example code for the first steps would hold it small and simple. Your examples can used for it very good. I think, what to do would be more some optical work and the principle of small steps as above. If you like I would try to do also some work for this (good chance to learn more about assembler...). It's clear to me that it can be a try to interest people and noone could say if this works. On worst case it would make loosing some time and work, but in every case it's a chance to get some more training by doing this (designing the lessons for example, improving my rude english :-)).
I didn't know anyone ever used this, so I didn't continue work on it  :P
What useful features are missing in your opinion?
[/quote]
Title: Re: nAssembler - Nspire on-calc assembler
Post by: lkj on March 04, 2017, 05:50:21 am
There has recently been some activity in the thread on tiplanet, and as a result I also made some updates, adding CLZ, ADR, and fixing a bug. I forgot to update the file in the first post, so now I removed it and added a link to the download on tiplanet, which should always be up to date.


It's working now, was a simple mistake I made: for testing micropython 134 and 146 I did rename the both files (micropython 134 for example). So the .py files couldn't get connected and also nAssembler didn't run. Now everthing works.
I'm glad that it works now. Thanks for your many comments. I'm going to reply to some of their concerns below.

I agree that more documentation, more examples and some explanations of the examples would help. But my main reasons for starting this project were that I was interested in writing an assembler, had a lot of time with nothing to do, and I was always a bit annoyed that it was impossible to write native programs for the Nspire on-calc. Nowadays, I don't have much time, and I've accomplished my main goal of writing an on-calc assembler with most of the useful features.

I may try to write another example or two, but for more, other people will have to do it. So, you're welcome to do it  ;)

There probably already are some ARM assembler tutorials on the internet, for example for the GBA, but they can't explain the things specific to the Nspire, e.g. how to read the keyboard or display stuff (see https://hackspire.org (https://hackspire.org) and in particular https://hackspire.org/index.php/Memory-mapped_I/O_ports (https://hackspire.org/index.php/Memory-mapped_I/O_ports) for that kind of thing), and they probably use some pseudo-instructions I didn't implement or some different syntax, which will require some experimenting and/or googling to adapt to nAssembler.

Also, grosged over on tiplanet wrote a small demo and a short explanation of ARM assembly, but it's in French. (example link: https://tiplanet.org/forum/archives_voir.php?id=839558 (https://tiplanet.org/forum/archives_voir.php?id=839558), the file nsprtest.s is the code compatible with nAssembler)

Title: Re: nAssembler - Nspire on-calc assembler
Post by: Chirlian on March 04, 2017, 12:54:51 pm
Nice!

There has recently been some activity in the thread on tiplanet, and as a result I also made some updates, adding CLZ, ADR, and fixing a bug. I forgot to update the file in the first post, so now I removed it and added a link to the download on tiplanet, which should always be up to date.


It's working now, was a simple mistake I made: for testing micropython 134 and 146 I did rename the both files (micropython 134 for example). So the .py files couldn't get connected and also nAssembler didn't run. Now everthing works.
Quote
I'm glad that it works now. Thanks for your many comments. I'm going to reply to some of their concerns below.

Quote
I agree that more documentation, more examples and some explanations of the examples would help. But my main reasons for starting this project were that I was interested in writing an assembler, had a lot of time with nothing to do, and I was always a bit annoyed that it was impossible to write native programs for the Nspire on-calc. Nowadays, I don't have much time, and I've accomplished my main goal of writing an on-calc assembler with most of the useful features.

Quote
I may try to write another example or two, but for more, other people will have to do it. So, you're welcome to do it  ;)

Jessus, Mary and Jo'... you say this to ME? IoI. There was a time when I was a little trying with Z80 Assembler on my ZX Specci. Hm, must have at 1983 or so... And by the time there came some nice books from UK about machine code routines and lastly the whole commented ROM of the Specci. So all system call could be used from the usual languages. Now i had what I needed but then my study ended, I got a job for long time and the lot of free time was gone. So how is it about the nspire os? Up to now I didnt find any large file or book w/o commented os routines, system calls, system variables. Some must be known, otherwise you wouldn't use a print function, input file and others in your code.

Quote
There probably already are some ARM assembler tutorials on the internet, for example for the GBA, but they can't explain the things specific to the Nspire, e.g. how to read the keyboard or display stuff (see https://hackspire.org (https://hackspire.org) and in particular https://hackspire.org/index.php/Memory-mapped_I/O_ports (https://hackspire.org/index.php/Memory-mapped_I/O_ports) for that kind of thing), and they probably use some pseudo-instructions I didn't implement or some different syntax, which will require some experimenting and/or googling to adapt to nAssembler.

Yes, by searching I found several tutorials, it's very nice. Good, that the arm cpus are so much used. Indeed, what you telling about nspire os is the main point. Using/usability of an assembler depends from the documentation of the used machine. Also important, if this mc programs can easily be used from the usual languages as lua, python, c++, c. Should be simple calls that can easy done. And especially grafik routines, of course. I think, everyone, who is programming the nspire would be interested in this.

Quote
Also, grosged over on tiplanet wrote a small demo and a short explanation of ARM assembly, but it's in French. (example link: https://tiplanet.org/forum/archives_voir.php?id=839558 (https://tiplanet.org/forum/archives_voir.php?id=839558), the file nsprtest.s is the code compatible with nAssembler)

Yes, and I will translate it by the time. Will surely need a little longer. In french I got at school usually the lowest note (from 1-6), the 6. But under those, who got ever the 6, I was one of the best. Means the 'best of the worst'. Sounds good, eh? :-) So it may need some time, also with using babelfish. Some time before, I saw a small list with os system calls. Damn, i don't remember where.

The resonance at TI Planet when you presented nAssembler was good, so I think there may be some who like to support the usage of it.

One first suggestion to the nAssembler: the handling is rather uncomfortable by typing the complete paths with the nspire keys. Could a file like the batch files of ms dos (in python?) make it simpler? Setting the paths to a constant one means that only the program name must be entered. If one has longer to do with a program he could also set the name in this batch file constant, so the the whole turnaround would be much shorter and simpler.
Title: Re: nAssembler - Nspire on-calc assembler
Post by: Chirlian on March 05, 2017, 05:28:34 pm
I wrote about making the handling of nAssembler easier-so I tried by myself. But without being used in python I had no success. Was changing your code a little bit (yes, I know, it's a sacrileg), so that not the path but only the file name must be entered or in the other version path & filename get fixed to get a quick turnaround:

when I change your code at the end of the nassembler file

def calc_assemble():
   
    inf = input('in:')
    outf = input('out:')
    return assembler(inf, outf)

to

def calc_assemble():
   
    inf = /documents/ndless/example.asm.tns
    outf = /documents/ndless/example.prg.tns
    return assembler(inf, outf)

or

def calc_assemble():

    inf = /documents/ndless/
    inf = inf + input('in:')
    outf = /documents/ndless/
    outf = outf + input('out:')
    return assembler(inf, outf)

all that doen't work, I get the 'File "/documents/ndless/nAssembler.py.tns", line 1600 Syntax Error: invalid Syntax. Tried also backslash for slashes but same reaction. Am wondering why I see 'nAssembler.py.tns' at the end of the string and not 'Example.asm.tns' as i wrote.
Title: Re: nAssembler - Nspire on-calc assembler
Post by: Chirlian on March 09, 2017, 05:55:39 pm
I wrote about making the handling of nAssembler easier-so I tried by myself. But without being used in python I had no success. Was changing your code a little bit (yes, I know, it's a sacrileg), so that not the path but only the file name must be entered or in the other version path & filename get fixed to get a quick turnaround:

when I change your code at the end of the nassembler file

def calc_assemble():
   
    inf = input('in:')
    outf = input('out:')
    return assembler(inf, outf)

to

def calc_assemble():
   
    inf = /documents/ndless/example.asm.tns
    outf = /documents/ndless/example.prg.tns
    return assembler(inf, outf)

or

def calc_assemble():

    inf = /documents/ndless/
    inf = inf + input('in:')
    outf = /documents/ndless/
    outf = outf + input('out:')
    return assembler(inf, outf)

all that doen't work, I get the 'File "/documents/ndless/nAssembler.py.tns", line 1600 Syntax Error: invalid Syntax. Tried also backslash for slashes but same reaction. Am wondering why I see 'nAssembler.py.tns' at the end of the string and not 'Example.asm.tns' as i wrote.
Found it now, was not so difficult:
inf="/documents/ndless/example.asm.tns"
and
outf="/documents/ndless/example.prg.tns"
so the turnaround gets a little faster. Now I am trying to get the clrscrn/countdown routine of grosged/TI Planet to assemble with nassembler. Last problem is the .word instruction. Hm, I saw this point anywhere in a forum...
Title: Re: nAssembler - Nspire on-calc assembler
Post by: lkj on March 10, 2017, 12:30:37 pm
About the system calls: Yes, I guess it would be useful to have some way to access them with nAssembler. In programs compiled on the pc, ndless provides them.
Since neither reading keypad state nor displaying stuff on the screen uses them, you can actually already do many things without them, but there's obviously no file reading/writing.

.word is just called dcd here.
Title: Re: nAssembler - Nspire on-calc assembler
Post by: gr0sged on March 11, 2017, 12:35:16 pm
Hello there!.. my very 1st post, here we go :)

Well!.. lkj, I had a question : do you intend to add a directive in nAssembler which would allow us to include binary files ? (I think about the useful directive .incbin (https://sourceware.org/binutils/docs/as/Incbin.html) available in Gnu Assembler)
Title: Re: nAssembler - Nspire on-calc assembler
Post by: lkj on March 13, 2017, 06:24:04 pm
Sounds useful and simple to implement. I'll add it when I have time.
Title: Re: nAssembler - Nspire on-calc assembler
Post by: Chirlian on March 14, 2017, 08:39:30 pm
So it seems there is no os reassemble listing (with some comments)? Ok, in those days when we got such a book for the speccy it were 16 kb of rom. So making such a thing for the now 13 mb that the os contents would be an endless work. If there comes no infos from TI it may be to timesucking, esp. for a single person.
But when ndless contents some system calls, their programmers must know about them. However, they won't shout around with this knowledge that they got surely not without some trouble.
Thanks for the hint about .word/dcd!
About the system calls: Yes, I guess it would be useful to have some way to access them with nAssembler. In programs compiled on the pc, ndless provides them.
Since neither reading keypad state nor displaying stuff on the screen uses them, you can actually already do many things without them, but there's obviously no file reading/writing.

.word is just called dcd here.
Title: Re: nAssembler - Nspire on-calc assembler
Post by: lkj on April 03, 2017, 02:18:01 pm
The INCBIN directive is now implemented. The syntax is
INCBIN path
, i.e. no double quotes or anything around the path. It includes the file content at the location of the INCBIN. path can be an absolute path or a relative path (relative to the  directory containing the source file).
Download at https://tiplanet.org/forum/archives_voir.php?id=821835 (https://tiplanet.org/forum/archives_voir.php?id=821835).

So it seems there is no os reassemble listing (with some comments)? Ok, in those days when we got such a book for the speccy it were 16 kb of rom. So making such a thing for the now 13 mb that the os contents would be an endless work. If there comes no infos from TI it may be to timesucking, esp. for a single person.
But when ndless contents some system calls, their programmers must know about them. However, they won't shout around with this knowledge that they got surely not without some trouble.
No, since TI doesn't support native programming on the Nspire. The people working on ndless have found many system calls over the years, though. Since ndless is open source, the addresses can be found there (https://github.com/ndless-nspire/Ndless/tree/master/ndless/src/tools/MakeSyscalls/idc (https://github.com/ndless-nspire/Ndless/tree/master/ndless/src/tools/MakeSyscalls/idc)). But copying them from there and hardcoding them in your assembly source is very annoying, because the addresses are different for every OS version and for the different models. So it would be much nicer if nAssembler had some support for syscalls.
Edit: It's actually easier than that. Since ndless executes the assembled program, we can actually use its way to handle syscalls: Ndless installs a SWI handler, so we can just use the SWI (software interrupt) instruction to call syscalls. The syntax is "SWI swinum", where swinum is the number of the syscall you want, from the list at https://github.com/ndless-nspire/Ndless/blob/master/ndless-sdk/include/syscall-list.h (https://github.com/ndless-nspire/Ndless/blob/master/ndless-sdk/include/syscall-list.h). So for example "SWI 0" to call fopen.
Title: Re: nAssembler - Nspire on-calc assembler
Post by: neuronix on September 10, 2017, 11:26:21 am
And how can I send arguments to swi?
Title: Re: nAssembler - Nspire on-calc assembler
Post by: lkj on September 11, 2017, 03:04:37 am
If I remember correctly you pass arguments as with normal function calls, that is in r0, r1 etc
Title: Re: nAssembler - Nspire on-calc assembler
Post by: neuronix on September 15, 2017, 03:37:42 pm
so, for #define e_puts 22 // int nuc_puts(const char *p1)
it's my code:
Code: [Select]
main
    stmfd sp!, {r0-r12, lr}
    adr r0, text
    swi #22
    bl wait
    ldmfd sp!, {r0-r12, pc}

wait
    stmfd sp!, {r0-r12, lr}
    mvn r0, #0
    mov r0, r0, lsr #4
waitloop
    sub r0, r0, #1
    cmp r0, #0
    bgt waitloop
    ldmfd sp!, {r0-r12, pc}

text
    dcb "Hello World!"
Is it good?
Title: Re: nAssembler - Nspire on-calc assembler
Post by: lkj on September 17, 2017, 03:45:59 pm
I think it's correct.
Title: Re: nAssembler - Nspire on-calc assembler
Post by: neuronix on September 17, 2017, 03:49:18 pm
It doesn't work. Nothing is displayed :(
Title: Re: nAssembler - Nspire on-calc assembler
Post by: lkj on September 17, 2017, 04:03:14 pm
Testing it in the emulator, I saw that it only prints the output to the console (i.e. over RS232, not on the screen). So seeing nothing on the screen is expected.

Edit: syscall 341 prints to the screen
Title: Re: nAssembler - Nspire on-calc assembler
Post by: neuronix on September 17, 2017, 05:18:11 pm
But 22 is the syscall puts and not printf ;)



Yes with 341, it works.
But with the syscall void gui_gc_drawLine(Gc p1, int p2, int p3, int p4, int p5), what is Gc p1? A pointer to the screen area?
And p2, p3, p4, p5? The coordinates of the line?

Edit (Eeems): Merged double post
Title: Re: nAssembler - Nspire on-calc assembler
Post by: Jim Bauwens on September 18, 2017, 05:21:59 am
Writing a new compiler for C, in assembly, would be a huge project. I don't think it's realistically possible.
Porting some existing compiler would be easier, but may still be hard.

The Tiny C Compiler (tcc) has an ARM version, so possibly that can be ported.
Title: Re: nAssembler - Nspire on-calc assembler
Post by: neuronix on September 18, 2017, 11:10:30 am
And if I want to reuse the return value of the syscall, in which register is the return value?
Title: Re: nAssembler - Nspire on-calc assembler
Post by: lkj on September 18, 2017, 05:38:26 pm
Yes with 341, it works.
But with the syscall void gui_gc_drawLine(Gc p1, int p2, int p3, int p4, int p5), what is Gc p1? A pointer to the screen area?
And p2, p3, p4, p5? The coordinates of the line?

Edit (Eeems): Merged double post
Gc is an OS variable. There is a bit of documentation on https://hackspire.org/index.php/Syscalls#Graphic_Context_API (https://hackspire.org/index.php/Syscalls#Graphic_Context_API).

And if I want to reuse the return value of the syscall, in which register is the return value?
I'd guess in R0 as usual.
Title: Re: nAssembler - Nspire on-calc assembler
Post by: neuronix on September 18, 2017, 06:25:02 pm
Gc is an OS variable. There is a bit of documentation on https://hackspire.org/index.php/Syscalls#Graphic_Context_API (https://hackspire.org/index.php/Syscalls#Graphic_Context_API).

But, for the #define e_gui_gc_drawLine 314 // void gui_gc_drawLine(Gc p1, int p2, int p3, int p4, int p5)
How I can use this in ASM?

I'd guess in R0 as usual.

I try this code :
Code: [Select]
main
    stmfd sp!, {r0-r12, lr}
    mov r0, #0xC0000010
    ldr r0, [r0]
    bl clrscrCX
    adr r0, text
    swi #46 ;tolower
    swi #341 ;disp_msg
    bl wait
    ldmfd sp!, {r0-r12, pc}

wait
    stmfd sp!, {r0-r12, lr}
    mvn r0, #0
    mov r0, r0, lsr #4
waitloop
    sub r0, r0, #1
    cmp r0, #0
    bgt waitloop
    ldmfd sp!, {r0-r12, pc}

clrscrCX
    stmfd sp!, {r0-r12, lr}
    mov r4, r0
    mov r5, #0
    mov r6, #0
    mov r7, #0
xloop
    mov r0, r4
    mov r1, r5
    mov r2, r6
    mov r11, r7
    bl setPixel
    add r5, r5, #1
    cmp r5, #320
    blt xloop
    add r6, r6, #1
    mov r5, #0
    cmp r6, #240
    blt xloop
    ldmfd sp!, {r0-r12, pc}

setPixel
    stmfd sp!, {r0}
    add r0, r0, r1, lsl #1
    add r0, r0, r2, lsl #9
    add r0, r0, r2, lsl #7
    strh r11, [r0]
    ldmfd sp!, {r0}
    bx lr

text
    dcb "HELLO WORLD!", 0

but he displays HELLO WORLD! :(
Title: Re: nAssembler - Nspire on-calc assembler
Post by: lkj on September 19, 2017, 04:14:12 am
Hackspire says what the arguments do:
Quote
void gui_gc_drawLine(Gc, int x1, int y1, int x2, int y2) - Draws a line from <x1,y1> to <x2,y2>.

So you need to store Gc in r0, r1=x1, r2=y1, r3=x2, and then push y2 onto the stack. I'll write more later.
Title: Re: nAssembler - Nspire on-calc assembler
Post by: neuronix on September 19, 2017, 05:36:37 am
I know for put x1 in r1, y1 in r2, etc. But in r0 I should put Gc. But how can I define a Gc in asm?
Title: Re: nAssembler - Nspire on-calc assembler
Post by: lkj on September 19, 2017, 09:22:49 am
You don't construct a new one, you should get a pointer of the one used by the OS. It seems to be syscall 298, but I'm not sure if you can really just call it to get the pointer. It's a bit complicated to use the GC and you should read the documentation on hackspire if you really want to. It seems that its use has been deprecated in Ndless anyway.

Code: [Select]
main
    stmfd sp!, {r0-r12, lr}
    mov r0, #0xC0000010
    ldr r0, [r0]
    bl clrscrCX
    adr r0, text
    swi #46 ;tolower
    swi #341 ;disp_msg
    bl wait
    ldmfd sp!, {r0-r12, pc}

wait
    stmfd sp!, {r0-r12, lr}
    mvn r0, #0
    mov r0, r0, lsr #4
waitloop
    sub r0, r0, #1
    cmp r0, #0
    bgt waitloop
    ldmfd sp!, {r0-r12, pc}

clrscrCX
    stmfd sp!, {r0-r12, lr}
    mov r4, r0
    mov r5, #0
    mov r6, #0
    mov r7, #0
xloop
    mov r0, r4
    mov r1, r5
    mov r2, r6
    mov r11, r7
    bl setPixel
    add r5, r5, #1
    cmp r5, #320
    blt xloop
    add r6, r6, #1
    mov r5, #0
    cmp r6, #240
    blt xloop
    ldmfd sp!, {r0-r12, pc}

setPixel
    stmfd sp!, {r0}
    add r0, r0, r1, lsl #1
    add r0, r0, r2, lsl #9
    add r0, r0, r2, lsl #7
    strh r11, [r0]
    ldmfd sp!, {r0}
    bx lr

text
    dcb "HELLO WORLD!", 0

but he displays HELLO WORLD! :(
Yeah, tolower doesn't take a string argument. It only takes a single character and returns the lowercase version. Apparently it interprets the pointer as a non-uppercase character and returns it unchanged.

To make it work, you have to write  your own routine to change the whole string to lowercase.
Title: Re: nAssembler - Nspire on-calc assembler
Post by: neuronix on September 19, 2017, 10:11:19 am
So I can't use any graphics syscalls? And I have already watched the hackspire doc but I can't found any adresse to use Gc in arm asm
Title: Re: nAssembler - Nspire on-calc assembler
Post by: lkj on September 21, 2017, 05:52:48 am
You can always write a program in C on the computer, compile it with ndless, and then disassemble it to see how to do things. Compiling and disassembling the nGc sample would probably also be enough.
Title: Re: nAssembler - Nspire on-calc assembler
Post by: neuronix on September 21, 2017, 09:53:30 am
I haven't the SDK Ndless, I can't install it on my computer. I already tried :(
Title: Re: nAssembler - Nspire on-calc assembler
Post by: neuronix on October 25, 2017, 07:04:48 am
Is it possible to add smulbb, smulbt, smultb and smultt?
Signed 16 bit MULtiplication of Bottom half of first operand with Bottom half of second operand => SMULBB
And for smulbt or smultb or smultt :
T is Top and B is Bottom




And smlabb smlabt smlatb and smlatt also exist. It's same as mla, but with signed and bottom or top.

Edit (Eeems): Merged double post
Title: Re: nAssembler - Nspire on-calc assembler
Post by: lkj on February 26, 2018, 01:17:14 pm
Sorry, I was too busy with university this year to work on this. I just uploaded an updated version on tiplanet, but it doesn't include these instructions yet. Only the "include" instruction, to include other source files. I'll try to implement these multiplies if I have time.