My script below - will pass the base array $t0 and print it's content (which is 4). The array contains "4,6,2,3,11". I can access the first letter of an array. "4" but none of the others.
My issue - I don't know how to access the other individual array cells from my lin_search() function.
My thoughts - I know the operation has something to do with add or mul. The local variable in lin_search is $t6. Perhaps it has something to do with 4($t0). I've spent the whole day on this with no luck.
So there are assembly programmers afterall! Hmmm.... how's life as an assembly programmer in comparison to higher level language programmer? The last time I "play" around with is Arrow x86 assembly.
Im not an assembly programmer. Im just a CS major(freshmen level), its required. Not many people know machine code so you find yourself learning everything yourself. This is also only MIPS(the easy version of assembly), this stuff isnt that bad, I believe any programmer can learn it with the aid of google and their own personal motivations. Anyway this morning I was finally able to find a C forum with an assembly section. I guess I'll just head over there. Thanks anyway guys.
I assume you want your linear search function to search for a particular value? If so, you need to pass that
value to the function as well as the base address of the array. I'm also assuming that your linear search
function just "knows" the number of elements in the array, or else you need to pass that too. I'm further
assuming that the function returns the address at which the element was found.
So in C/C++ the algorithm looks like:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
// Pardon the use of goto here; I'm trying to write this such that you can directly translate
// it to assembler
int* lin_search( int* base_address, int value_to_find, int num_elements_in_array )
{
loop:
if( num_elements_in_array == 0 )
goto not_found;
if( *base_address == value_to_find )
return base_address;
--num_elements_in_array;
++base_address; /* This adds 4 to base_address, since sizeof( int) is 4 */
goto loop:
not_found:
return 0; /* Didn't find the element, return a NULL pointer I guess */
}
So basically you already pass in the base_address. You can just add 4 each time to the base_address
to get to the next element.