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 > "if/else" statements?

#110334 - DimondEdge - Mon Nov 27, 2006 10:56 pm

How would I do them in ASM (ARM) ? Let's say I want to do this C in asm:
Code:

if (a != b)
{
    printf("Foo\n");
    exit(0);
}
else
   exit(0);

How would I do that?

Thanks!
De

#110337 - sajiimori - Mon Nov 27, 2006 11:07 pm

All such questions have an easy answer:
Code:

gcc -S myFile.c
type myFile.s

#110388 - ProblemBaby - Tue Nov 28, 2006 4:54 am

if (a != b)
{
printf("Foo\n");
exit(0);
}
else
exit(0);

Code:

@ r0 = a, r1 = b
cmp r0, r1
beq 1f
stmfd sp!, {r0-r3, lr}
ldr r0, =textstring
BL printf
ldmfd sp!, { r0-r3, lr}
b 2
1:

2:


etc..
Havent test it, but it should be correct.

#110486 - Miked0801 - Tue Nov 28, 2006 9:15 pm

Saji's answer is better. Let the compiler show you what it thinks that statement is.