Homebrew Is in-line assembly possible?

  • Thread starter Thread starter sblast3
  • Start date Start date
  • Views Views 1,289
  • Replies Replies 4

sblast3

Well-Known Member
Member
Joined
Dec 27, 2014
Messages
166
Reaction score
73
Trophies
1
XP
309
Country
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!
 
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!
 
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!
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.
 

Site & Scene News

Popular threads in this forum