This is a homework question, but I’m stuck.
The assignment is to find the largest integer in an array. Here’s the C code we’re given:
#include <stdio.h>
#include <stdlib.h>
extern int mybig( int array[] ) ;
void main( char * argv[], int argc )
{
int array[] = { 5, 15, 100, 25, 50, -1 } ;
int biggest ;
biggest = mybig( array ) ;
printf( "Biggest integer in array: %d\n", biggest ) ;
}
I’ve made about a dozen versions of the assembly so far, but this is the closest I’ve gotten
.global mybig
mybig: stmfd sp!, {v1-v6, lr}
mvn v1, #0
loop: ldrb a4, [a1], #4
MOVLT a4, a1
cmp a1, v1
bne loop
ldmfd sp!, {v1-v6, pc}
.end
Every time I link it together, I hit an infinite loop, and I’m not sure why. Any help would be majorly appreciated, the professor didn’t teach us anything in an introductory course, just told us to do it, and gave us a link to a toolchain to compile and assemble.
EDIT: This is where I’ve gotten to. Program doesn’t run, just hits an infinite loop.
.global mybig
mybig: stmfd sp!, {v1-v6, lr}
mvn v1, #0
mov a3, a1
loop: ldr a4, [a1], #4
cmp a4, a1
MOVMI a3, a1
cmp a1, v1
bne loop
mov a1, a4
ldmfd sp!, {v1-v6, pc}
.end
C code hasn’t changed
That would be my solution:
While this is not the best possible code in regards of performance it should be self explaining.