Baking Pi: Transfer to C code
Posted: Wed Sep 25, 2013 2:07 pm
Hi,
I just finished OK02 in the Baking Pi tutorial. I can now make the LED blink on and off.
So I wrote an assembly program "blink" to make the LED blink x times, where x is the value passed in r0.
I also tried transferring control to C code, since this is obviously a good step towards increased productivity.
My _start looks like this:
kmain looks like this:
fibonacci looks like this:
if kmain calls fibonacci(0), the LED blinks once, as expected.
However, any other argument for fibonacci causes no blinks.
I'm using YAGARTO on Windows, using gcc to compile both C and assembly.
Is there anything glaringly obvious that's wrong with this code?
Is there something I should know when calling C code from assembly?
I just finished OK02 in the Baking Pi tutorial. I can now make the LED blink on and off.
So I wrote an assembly program "blink" to make the LED blink x times, where x is the value passed in r0.
I also tried transferring control to C code, since this is obviously a good step towards increased productivity.
My _start looks like this:
Code: Select all
.section init
.globl _start
_start:
b kmainCode: Select all
int kmain()
{
blink(fibonacci(5));
}
Code: Select all
int fibonacci(int x)
{
if (x == 0)
{
return 1;
}
else if (x == 1)
{
return 1;
}
else
{
return fibonacci(x - 1) + fibonacci(x - 2);
}
}
However, any other argument for fibonacci causes no blinks.
I'm using YAGARTO on Windows, using gcc to compile both C and assembly.
Is there anything glaringly obvious that's wrong with this code?
Is there something I should know when calling C code from assembly?