From ps2 asm to psp asm.

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Kojima
Posts: 275
Joined: Mon Jun 26, 2006 3:49 am

From ps2 asm to psp asm.

Post by Kojima »

Can anyone spot why this doesn't work?
It's a simple multply test that works perfectly on the ps2, but on the psp (using the c++ compiler not c) it fails, saying mult $5,$5,$3 is an illegal operand.

Code: Select all


void AddTest() 
{ 

int num1=5; 
int num2=10; 
int out=0; 
asm __volatile__ ("\n\ 
mult %0,%1,%2\n\  // <<<<
"&#58;"=r"&#40;out&#41;&#58;"r"&#40;num1&#41;,"r"&#40;num2&#41;&#41;; 

	printf&#40;"Result&#58;%d \n",out&#41;; 
&#125;
Are there major differences between ps2/psp asm in inline usage or do I just need to modify it a little?
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

Probably because on the allegrex it only supports the mult s, t form with the result going to the HI and LO regs I would expect.
Kojima
Posts: 275
Joined: Mon Jun 26, 2006 3:49 am

Post by Kojima »

ah ok, thanks.
Kojima
Posts: 275
Joined: Mon Jun 26, 2006 3:49 am

Post by Kojima »

Anyone know why this doesn't work on psp?

ori $15,$0,%1\n\

I'm just trying to set register 15 with the value of operand 1 but it says "Error:Register value used as an expression"

Has ori changed from ps2 too?
TyRaNiD
Posts: 907
Joined: Sun Jan 18, 2004 12:23 am

Post by TyRaNiD »

no ori is the same as it ever was, the third parameter is an immediate value not the a register, if you use a register then use normal or.
Kojima
Posts: 275
Joined: Mon Jun 26, 2006 3:49 am

Post by Kojima »

Whoops, ok thanks. Still learning as I go.
Kojima
Posts: 275
Joined: Mon Jun 26, 2006 3:49 am

Post by Kojima »

Can anyone see why this pice of asm hangs?

Code: Select all

num1 =5;
num2 = 10;
out = 0;
to = 5;
asm __volatile__ &#40;"\n\ 
ori $5,$0,0\n\
ori $17,$0,0\n\
loop&#58;\n\
mul %1,%2\n\
mflo $16\n\
addu $19,$16,$17\n\
move $17,$19\n\
addu $5,$5,1\n\
bne $5,%3,loop\n\
nop\n\
move %0,$17\n\
"&#58;"=r"&#40;out&#41;&#58;"r"&#40;num1&#41;,"r"&#40;num2&#41;,"r"&#40;to&#41;&#41;; 
in c++ terms it's only doing this,

Code: Select all

int num1=5; 
int num2=10; 
int out=0; 
int to = 5;
float r17,r16;
r16=0;
r17=0;
for&#40;int i=0;i<to;i++&#41;
&#123;
	float res = num1*num2;
	r16 = res;
	r17 = r16+r17;
&#125;
User avatar
Saotome
Posts: 182
Joined: Sat Apr 03, 2004 3:45 am

Post by Saotome »

I think it's because of this one:

Code: Select all

addu $5,$5,1
the third parameter is an immediate but you're using addu instead of addiu. I believe in this case it's as if you're using addu $5,$5,$1 and if $1 != 1 then it doesn't work like it should ;)
infj
Kojima
Posts: 275
Joined: Mon Jun 26, 2006 3:49 am

Post by Kojima »

Thanks, still hangs though :)

Here's my new attempt at it,

Code: Select all


void AddTest&#40;&#41; 
&#123; 


int num1=5; 
int num2=10; 
int out=0; 
int to = 5;
float r17,r16;
r16=0;
r17=0;
for&#40;int i=0;i<to;i++&#41;
&#123;
	float res = num1*num2;
	r16 = res;
	r17 = r16+r17;
&#125;
printf&#40;"C Res&#58;%f",r17&#41;;

num1 =5;
num2 = 10;
out = 0;
to = 5;
asm __volatile__ &#40;"\n\ 
ori $5,$0,0\n\
ori $17,$0,0\n\
loop&#58;\n\
mul %1,%2\n\
mflo $16\n\
addu $19,$16,$17\n\
move $17,$19\n\
addiu $5,$5,1\n\
bne $5,%3,loop\n\
nop\n\
move %0,$17\n\
"&#58;"=r"&#40;out&#41;&#58;"r"&#40;num1&#41;,"r"&#40;num2&#41;,"r"&#40;to&#41;&#41;; 

	printf&#40;"Asm Result&#58;%d \n",out&#41;; 
&#125;

It doesn't just hang, the psp resets, and the power light blinks on/off, I guess indicating there was a fatal error, then i have to hard reset.
Post Reply