Is in-line assembly possible?

Discussion in '3DS - Homebrew Development and Emulators' started by sblast3, Dec 20, 2015.

  1. sblast3
    OP

    sblast3 GBAtemp Regular

    Member
    130
    58
    Dec 27, 2014
    United States
    For a school project, I want to get (very basic) assembly code to run on the 3DS. I'm not very familiar with C and I'm not sure how to implement in-line ASM without getting errors. Here's the Hello World C code I'm using:

    Code:
    
    #include <string.h>
    #include <3ds.h>
    #include <stdio.h>
    
    int main()
    {
     
       gfxInitDefault();
       consoleInit(GFX_TOP, NULL);
       
       printf("Hello world\n");
    
       // Main loop
       while (aptMainLoop())
       {
         gspWaitForVBlank();
         hidScanInput();
    
         u32 kDown = hidKeysDown();
         if (kDown & KEY_START)
           break; //Break in order to return to hbmenu
    
         // Flush and swap frame-buffers
         gfxFlushBuffers();
         gfxSwapBuffers();
       }
    
       gfxExit();
       return 0;
    }
    
    Any ideas? I saw that the PastaCFW source code had external .asm files, but I'm not sure how they were called in the C code. Simply moving a value to eax would suffice!
     
  2. zoogie

    zoogie simple pimp tool

    Member
    6,515
    8,388
    Nov 30, 2014
    United States
    Last edited by zoogie, Dec 20, 2015
    sblast3 likes this.
  3. sblast3
    OP

    sblast3 GBAtemp Regular

    Member
    130
    58
    Dec 27, 2014
    United States
    zoogie likes this.
  4. sblast3
    OP

    sblast3 GBAtemp Regular

    Member
    130
    58
    Dec 27, 2014
    United States
    I've made some progress, but I'm struggling to get ASM to print on the 3DS. From what I understand, SWI 0 prints the value pointed to in R1 of length R2, but when I do that nothing happens.

    Code:
    asm volatile(
      "string:;"
      ".ascii \"Hello Worldn\";"
       
      "_start:;"
      "LDR R1, =string;"
      "MOV R2, #12;"
      "SWI 0;"
    );
    
    I'm sure I made loads of errors. Any help would be greatly appreciated!
     
  5. Fishaman P

    Fishaman P Speedrunner

    Member
    3,243
    507
    Jan 2, 2010
    United States
    Wisconsin
    Ah, but do you know where it prints to? The default target probably isn't the screen buffer, but rather a debug log or something like that.
     
    UraKn0x, sblast3 and cearp like this.