minumum hello world asm code for psp-as?

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Heimdall
Posts: 245
Joined: Thu Nov 10, 2005 1:29 am
Location: Netherlands
Contact:

minumum hello world asm code for psp-as?

Post by Heimdall »

Hi guys, any of you can help me how and post a simple piece of asm code that i can build directly using psp-as?

I mean i'm not interested in gcc asm, i want the real deal :) I want to research some code generation stuff, but i'm kind of stuck on how to bootstrap my application.

Thanks!
[wl]
Posts: 13
Joined: Fri May 05, 2006 2:16 am

Post by [wl] »

you may get .s file, if u add "-save-temps"(without quotes) flag to CFLAGS in your makefile, to see the "right" structure of program, which can be compiled
Noko
Posts: 23
Joined: Sat Sep 06, 2008 8:35 pm

Post by Noko »

Code: Select all

Andrey:/cygdrive/b/src/noscript$ cat>hello.c
#include "stdio.h"

int main(int argc,char **argv){
        printf("Hello world!\n");
        return 0;
}

[1]+  Stopped                 cat > hello.c
Andrey:/cygdrive/b/src/noscript$ psp-gcc hello.c -S -o hello.S
Andrey:/cygdrive/b/src/noscript$ cat hello.S
        .file   1 "hello.c"
        .section .mdebug.eabi32
        .section .gcc_compiled_long32
        .previous
        .rdata
        .align  2
$LC0:
        .ascii  "Hello world!\000"
        .text
        .align  2
        .globl  main
        .ent    main
main:
        .frame  $fp,16,$31              # vars= 8, regs= 2/0, args= 0, gp= 0
        .mask   0xc0000000,-4
        .fmask  0x00000000,0
        .set    noreorder
        .set    nomacro

        addiu   $sp,$sp,-16
        sw      $31,12($sp)
        sw      $fp,8($sp)
        move    $fp,$sp
        sw      $4,0($fp)
        sw      $5,4($fp)
        lui     $2,%hi($LC0)
        addiu   $4,$2,%lo($LC0)
        jal     puts
        nop

        move    $2,$0
        move    $sp,$fp
        lw      $31,12($sp)
        lw      $fp,8($sp)
        addiu   $sp,$sp,16
        j       $31
        nop

        .set    macro
        .set    reorder
        .end    main
        .size   main, .-main
        .ident  "GCC: (GNU) 4.1.0 (PSPDEV 20060507)"
Andrey:/cygdrive/b/src/noscript$ psp-as hello.S -o hello.o
Andrey:/cygdrive/b/src/noscript$ 
Heimdall
Posts: 245
Joined: Thu Nov 10, 2005 1:29 am
Location: Netherlands
Contact:

Post by Heimdall »

Thanks,

Of course, dah!!! i'm really slow today :) i can use GCC to make it!!!
J.F.
Posts: 2906
Joined: Sun Feb 22, 2004 11:41 am

Post by J.F. »

Calling the sdk from assembly is easy - just put the arguments into a0-a3, and t0-t3. If you have more than 8 args (not often, but does sometimes happen), put the rest on the stack. Then just do "jal sdk_fn_name". jal has a delay slot, so don't forget that. Also don't forget the ABI... many registers may be destroyed by the called function. Only s0-s8 and a couple other regs won't be walked on.
Post Reply