Homebrew Is in-line assembly possible?

sblast3

Well-Known Member
OP
Member
Joined
Dec 27, 2014
Messages
166
Trophies
0
XP
307
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!
 

sblast3

Well-Known Member
OP
Member
Joined
Dec 27, 2014
Messages
166
Trophies
0
XP
307
Country
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!
 

Fishaman P

Speedrunner
Member
Joined
Jan 2, 2010
Messages
3,322
Trophies
1
Location
Wisconsin
Website
twitch.tv
XP
2,186
Country
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!
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

General chit-chat
Help Users
  • No one is chatting at the moment.
    SylverReZ @ SylverReZ: @OctoAori20, Thank you. Hope you're in good spirits today like I am. :)