#49316 - Shadow Wedge - Thu Jul 28, 2005 5:04 pm
Hi, I've just started ARM assembly and I've made a test algorithm that compares two arrays of bytes and wanted to see if it is decent or if it could be improved further.
The C code is:
And the assembly that I made was:
The compiler compared it one byte at a time, but I'm comparing the arrays in sets of four bytes. Would this be faster than one byte at a time?
Also, I don't know which registers I can mess with without pushing them.
Any help would be appreciated.
Edit: forgot to rename one of the variables in the C code.
_________________
...
Last edited by Shadow Wedge on Fri Jul 29, 2005 10:14 pm; edited 2 times in total
The C code is:
Code: |
int16 CompareArrays(int8* Array1, int8* Array2, int16 SizeOfArray) {
SizeOfArray *= SizeOfArray; //input is the root of what it should be int8* End = Array + SizeOfArray; while (Array1 != End) if (*Puzzle++ != *CurrentState++) return 0; //failure return -1; //success } |
And the assembly that I made was:
Code: |
mul r3, r2, r2 @r2 contains the square root of the number of items in the array
and r5, r3, #3 @r5 stores the remainder of the division mov r4, r3, asr #2 @r4 stores the number of fours in r3 beginloop4s: ldr r2, [r0], #4 ldr r3, [r1], #4 cmp r2, r3 movne r0, #0 @if not equal return 0 movne pc, lr sub r4, r4, #1 bne beginloop4s cmp r5, #0 @make sure that there's a point in comparing more bytes beq endfunction beginloop1s: ldrsb r2, [r0], #1 ldrsb r3, [r1], #1 cmp r2, r3 movne r0, #0 @if not equal return 0 movne pc, lr sub r5, r5, #1 bne beginloop1s endfunction: mvn r0, #0 @everything's a-ok, can return -1 mov pc, lr |
The compiler compared it one byte at a time, but I'm comparing the arrays in sets of four bytes. Would this be faster than one byte at a time?
Also, I don't know which registers I can mess with without pushing them.
Any help would be appreciated.
Edit: forgot to rename one of the variables in the C code.
_________________
...
Last edited by Shadow Wedge on Fri Jul 29, 2005 10:14 pm; edited 2 times in total