Author Topic: nAssembler - Nspire on-calc assembler  (Read 34712 times)

0 Members and 1 Guest are viewing this topic.

Offline neuronix

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 108
  • Rating: +0/-0
    • View Profile
Re: nAssembler - Nspire on-calc assembler
« Reply #30 on: September 17, 2017, 03:49:18 pm »
It doesn't work. Nothing is displayed :(

Offline lkj

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 485
  • Rating: +58/-1
    • View Profile
Re: nAssembler - Nspire on-calc assembler
« Reply #31 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
« Last Edit: September 17, 2017, 04:09:45 pm by lkj »

Offline neuronix

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 108
  • Rating: +0/-0
    • View Profile
Re: nAssembler - Nspire on-calc assembler
« Reply #32 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
« Last Edit: September 18, 2017, 12:24:49 pm by Eeems »

Offline Jim Bauwens

  • Lua! Nspire! Linux!
  • Editor
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1881
  • Rating: +206/-7
  • Linux!
    • View Profile
    • nothing...
Re: nAssembler - Nspire on-calc assembler
« Reply #33 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.

Offline neuronix

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 108
  • Rating: +0/-0
    • View Profile
Re: nAssembler - Nspire on-calc assembler
« Reply #34 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?

Offline lkj

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 485
  • Rating: +58/-1
    • View Profile
Re: nAssembler - Nspire on-calc assembler
« Reply #35 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.

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.

Offline neuronix

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 108
  • Rating: +0/-0
    • View Profile
Re: nAssembler - Nspire on-calc assembler
« Reply #36 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.

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! :(

Offline lkj

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 485
  • Rating: +58/-1
    • View Profile
Re: nAssembler - Nspire on-calc assembler
« Reply #37 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.

Offline neuronix

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 108
  • Rating: +0/-0
    • View Profile
Re: nAssembler - Nspire on-calc assembler
« Reply #38 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?

Offline lkj

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 485
  • Rating: +58/-1
    • View Profile
Re: nAssembler - Nspire on-calc assembler
« Reply #39 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.

Offline neuronix

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 108
  • Rating: +0/-0
    • View Profile
Re: nAssembler - Nspire on-calc assembler
« Reply #40 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
« Last Edit: September 19, 2017, 04:39:43 pm by neuronix »

Offline lkj

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 485
  • Rating: +58/-1
    • View Profile
Re: nAssembler - Nspire on-calc assembler
« Reply #41 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.

Offline neuronix

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 108
  • Rating: +0/-0
    • View Profile
Re: nAssembler - Nspire on-calc assembler
« Reply #42 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 :(

Offline neuronix

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 108
  • Rating: +0/-0
    • View Profile
Re: nAssembler - Nspire on-calc assembler
« Reply #43 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
« Last Edit: October 28, 2017, 07:00:45 pm by Eeems »

Offline lkj

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 485
  • Rating: +58/-1
    • View Profile
Re: nAssembler - Nspire on-calc assembler
« Reply #44 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.