Homebrew Is in-line assembly possible?

sblast3

Well-Known Member
Member
Joined
Dec 27, 2014
Messages
158
Trophies
0
XP
264
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
Member
Joined
Dec 27, 2014
Messages
158
Trophies
0
XP
264
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,284
Trophies
0
Location
Wisconsin
Website
twitch.tv
XP
1,583
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.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • kenenthk @ kenenthk:
    Lol AHS is getting funny two dudes and two girls get pregnant
    Gift
  • Toastee_ @ Toastee_:
    Whats AHS?
    Gift
  • gudenau @ gudenau:
    What are you supposed to do when you have a thousand dollar piece of hardware that won't work because the API the manufacturer provided doesn't want to work?
    Gift
  • kenenthk @ kenenthk:
    Ebay
    Gift
  • gudenau @ gudenau:
    Oh great.
    Gift
  • gudenau @ gudenau:
    It's a Linux bug.
    Gift
  • gudenau @ gudenau:
    Well a bug with their Linux drivers or something.
    Gift
  • gudenau @ gudenau:
    It captures 2x the amount of packets on Windows 10 in a freaking VM where USB access is slower/more latent.
    Gift
  • The Real Jdbye @ The Real Jdbye:
    what is this piece of hardware @gudenau
    Gift
  • gudenau @ gudenau:
    Beagle 480
    Gift
  • T-hug @ T-hug:
    Dune 2021 1080p HDRip X264 AC3-EVO
    Gift
  • kenenthk @ kenenthk:
    Dune? Reminds me of seeing my ex naked
    Gift
  • mr_switch @ mr_switch:
    Oh yeah Dune movie is out, watching it later
    Gift
  • mr_switch @ mr_switch:
    Here is hoping 2022 is a good year for DC cinematic universe
    Gift
  • gudenau @ gudenau:
    Honestly don't really know what Dune is.
    Gift
  • gudenau @ gudenau:
    Anyone here know much about Jetbrains InteliJ Idea?
    Gift
  • Sonic Angel Knight @ Sonic Angel Knight:
    Oh, T-hug was here :blink:
    Gift
  • Sonic Angel Knight @ Sonic Angel Knight:
    Hey, where the admins at? Come in the chat. I got a idea. How bout a Sound notification or something when someone tags you in chat? :ninja:
    Gift
  • DinohScene @ DinohScene:
    Post it in the v8 feedback thread
    Gift
  • Gift
  • OzKenny1983 @ OzKenny1983:
    Post what sorry? I'm guessing we were talking about this ages ago, but I haven't been on GBATemp in almost a year so my memory is failing me :-/
    Gift
  • DinohScene @ DinohScene:
    feedback and or bugs that may have popped up since the migration to XenForo 2!
    Gift
  • OzKenny1983 @ OzKenny1983:
    Umm...I think you might have the wrong person, since that may as well have been written in Chinese. I have nothing to do with the management of this site, nor have I ever been involved. I'm just a member, and hardly even qualify as that...like I said my last post was almost a year ago lol
    Gift
  • DinohScene @ DinohScene:
    Lol no, Sonic Angel Knight had an idea, best would be to post it in that thread haha
    Gift
  • OzKenny1983 @ OzKenny1983:
    Sorry, don't know Sonic Angel Knight either...
    Gift
    OzKenny1983 @ OzKenny1983: Sorry, don't know Sonic Angel Knight either...