gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

ASM > asm simple

#79679 - stewie - Sat Apr 15, 2006 3:55 am

I'm using devkitpro/gcc and I am trying to learn ARM asm. None of the examples or tutorials have a _simple_ sample file so I can putz around with it. Would someone here please be so kind as to post a very basic, small sample assembly file with the simplest command line compile/link instruction?

Thank you.

#79688 - stewie - Sat Apr 15, 2006 5:14 am

better yet, can someone help me compile this gbaguy example using gcc:

Code:

@include screen.h
@textarea

ldr r1,=REG_DISPCNT

ldr r2,=(BG2_ENABLE|MODE_3)

str r2,[r1]

ldr r1,=0x0FF

ldr r2,=vram+2410

str r1,[r2]

label1

B label1

@pool
@endarea


Thanks![/code]

#79707 - Cearn - Sat Apr 15, 2006 1:16 pm

Code:

@ --- screen.h (presumably) ---
#define REG_DISPCNT     0x04000000

#define MODE_3          0x0003
#define BG2_ENABLE      0x0400

#define vram    0x06000000

@ --- main.s ---
    .text         @ where the code should go
    .code   32    @ code type (ARM in this case)
    .global main  @ makes main visible for the whole project
main:
    ldr r1,=REG_DISPCNT
    ldr r2,=BG2_ENABLE|MODE_3
    str r2,[r1]
    ldr r1,=0x0FF
    ldr r2,=vram+2410
    str r1,[r2]
.Lloop:
    b .Lloop
.pool


Assemble with:
arm-elf-gcc -x assembler-with-cpp -c -mthumb-interwork main.s -o main.o

Check out the GAS manual for more on how GNU's asm is formatted, GBATek has a full list of instructions, as do a number of other sites. Also try compiling your C code with -S, which will give you the generated assembly.

#79773 - stewie - Sat Apr 15, 2006 10:19 pm

Thanks! I can finally get started. Tonc is great, by the way.