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 > loop problem

#21809 - realV - Sun Jun 06, 2004 6:57 pm

Please help me , i programmed my GBA in goldroad but now i will programm it in GAS but i got a problem.

ldr r3,=100

.loop:
@some code
subs r3,r3,#1
bne .loop

i compile this code

./arm-as code.s -o code.gba

The loop dosn't work. But why ? Please help me someone.

#21818 - Lord Graga - Sun Jun 06, 2004 9:16 pm

one problem could be that the code is misalligned with itself! it might be compiled with another base than the one that it's actually meant for by you. This might be a question about fixing the header.

#21823 - DekuTree64 - Sun Jun 06, 2004 10:47 pm

Yeah, that code itself is perfectly fine, so the problem must be elsewhere. If compiling your source file directly into a .bin like that works when you use a .c file, it should work with a .s too. I've always compiled things into .o files and linked them seperately, so I'm not sure if that woud work.
Can I see your whole AgbMain function? It could be an alignment problem, which would be fixable by putting an .align before your function label, but whatever it is, more code would help.
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#21831 - Lupin - Mon Jun 07, 2004 8:14 am

how do you know that the loop doesn't work, it doesn't do anything =)
_________________
Team Pokeme
My blog and PM ASM tutorials

#21836 - realV - Mon Jun 07, 2004 1:16 pm

I found the problem.

arm-as main.s -o main.elf

and

arm-ld main.elf -o main.gba

and ok the code works.

Thx for help :)

#21850 - sajiimori - Mon Jun 07, 2004 7:25 pm

Quote:

arm-as main.s -o main.elf

Here you are creating an .o file with a funny name, not an ELF file.
Quote:

arm-ld main.elf -o main.gba

Here you are creating an ELF file with a funny name, not a raw binary. It will only work on an emulator.

#21851 - realV - Mon Jun 07, 2004 9:57 pm

Thats right i start this progrs only on a emu.

#21852 - sajiimori - Mon Jun 07, 2004 11:10 pm

You may have missed my point. The reason you had a problem originally is because you didn't know what kinds of files you were creating.

The assembler creates object files (normally given the extension .o), and the linker (by default) produces ELF files (normally given the extension .elf). You gave your object file the extension .elf and your ELF file the extension .gba.

It still works, but it also makes the source of the problem apparent.