Experiment and I have just put together a little snippet in PowerPC which concatenates two strings together and returns the result. There are two functions that we have created (one gets the length of a string, and the other actually does the concatenation stuff). Not much to say about it, but if anyone is wondering how to compile it, you really can’t unless you have some kind of machine that supports it (XDK).
int strLength(const char* str)
{
_asm
{
li r4, 0
loop:
lbz r5, 0(r3)
cmplwi r5, 0
beq exitFunc
addi r3, r3, 1
addi r4, r4, 1
b loop
exitFunc:
mr r3, r4
}
}
char* concatStr(const char* str1, const char* str2)
{
_asm
{
//store these registers so we can pop them off later
stw r31, -10h(r1)
stw r30, -18h(r1)
mr r31, r3
mr r30, r4
bl strLength
mr r9, r3 //len of str1 is in r9
mr r3, r30
bl strLength
mr r10, r3 //len of str2 is in r10
add r11, r9, r10
addi r11, r11, 1 //len of concated string is in r11
//push these registers on the stack so we can get them back after malloc screws them up
stw r9, -20h(r1)
stw r10, -28h(r1)
stw r11, -30h(r1)
mr r3, r9
bl malloc
//get dem values back
lwz r9, -20h(r1)
lwz r10, -28h(r1)
lwz r11, -30h(r1)
loop1Start:
lbz r6, 0(r31)
stb r6, 0(r3)
addi r31, r31, 1
addi r3, r3, 1
subi r9, r9, 1
cmplwi r9, 0
bne loop1Start
loop2Start:
lbz r6, 0(r30)
stb r6, 0(r3)
addi r30, r30, 1
addi r3, r3, 1
subi r10, r10, 1
cmplwi r10, 0
bne loop2Start
li r4, 0
stb r4, 0(r3)
subi r11, r11, 1
sub r3, r3, r11
lwz r30, -18h(r1)
lwz r31, -10h(r1)
}
}
Recent Comments