urizackhem
Posts: 4
Joined: Mon May 25, 2015 7:01 am
Location: Kfar Saba, Israel

assembly on Rpi 2

Sat Mar 05, 2016 4:58 pm

Hi,
I have been studying how to program in assembly on the Rpi-2. I use raspbian wheezy, and gcc-4.9

I compile the following:

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <sys/time.h>

static float asm_sqrt(float x)
{
	float y;
	asm ("flds s0, %[va2]\n\t"
		"FSQRTS s16, s0"
		"fsts s16, %[va3]\n\t" : [va3]"=m"(y) : [va2]"m"(x) : "s0" , "s16");
	return y;
}

int  main()
{
	float x , y;
	struct timeval time1;
	gettimeofday(&time1 , 0);
	srand(time1.tv_sec * 1000000 + time1.tv_usec);
	x = (float)rand() / (float)RAND_MAX;
	y = asm_sqrt(x);
	printf("%f -> %f\n" , x , y);
	return 0;
}
with:
gcc-4.9 -O3 -lm sqrt_asm_test.c
and I get:
...
Error: VFP single precision register expected -- 'fsqrts s16, s0fsts s16,[sp,#12]'
What's wrong? Please advise.
Thank you.

User avatar
Paeryn
Posts: 2986
Joined: Wed Nov 23, 2011 1:10 am
Location: Sheffield, England

Re: assembly on Rpi 2

Sat Mar 05, 2016 11:02 pm

urizackhem wrote:Hi,
I have been studying how to program in assembly on the Rpi-2. I use raspbian wheezy, and gcc-4.9

I compile the following:

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <sys/time.h>

static float asm_sqrt(float x)
{
	float y;
	asm ("flds s0, %[va2]\n\t"
		"FSQRTS s16, s0"
		"fsts s16, %[va3]\n\t" : [va3]"=m"(y) : [va2]"m"(x) : "s0" , "s16");
	return y;
}

int  main()
{
	float x , y;
	struct timeval time1;
	gettimeofday(&time1 , 0);
	srand(time1.tv_sec * 1000000 + time1.tv_usec);
	x = (float)rand() / (float)RAND_MAX;
	y = asm_sqrt(x);
	printf("%f -> %f\n" , x , y);
	return 0;
}
with:
gcc-4.9 -O3 -lm sqrt_asm_test.c
and I get:
...
Error: VFP single precision register expected -- 'fsqrts s16, s0fsts s16,[sp,#12]'
What's wrong? Please advise.
Thank you.
You haven't embedded a newline after the FSQRTS instruction so the following line has been joined on the end, it should be

Code: Select all

	asm ("flds s0, %[va2]\n\t"
		"FSQRTS s16, s0\n\t"
		"fsts s16, %[va3]\n\t" : [va3]"=m"(y) : [va2]"m"(x) : "s0" , "s16");
She who travels light — forgot something.

urizackhem
Posts: 4
Joined: Mon May 25, 2015 7:01 am
Location: Kfar Saba, Israel

Re: assembly on Rpi 2

Sun Mar 06, 2016 3:57 am

Thank you very much!

Return to “Bare metal, Assembly language”