ARM programming output an array and malloc to clear input array?

That will store the undefined contents of register v1 over the first element of the int-array passed in a1 . You can see that the first element in the original array in your output has been overwritten with 0 .

Up vote 2 down vote favorite share g+ share fb share tw.

My assignment is to take an array of numbers and put it into ARM assembly and perform 2's complement, and then output it again for display. I was able to do most of the work but the output tells me it is not working right. C code: #include int * comp( int a, int size ) ; void main( int argc, char * argv ) { int array = { 1, -1, 252, -252, 0, 3015 } ; int size = sizeof(array) / sizeof(int) ; int * result ; int I ; result = comp( array, size ) ; printf( "Original Complement\n" ) ; for( I = 0 ; I , {v1-v6, lr} ; standard entry str v1, a1 ; copy a1 over to v1 str v2, a2 ; copy a1 over to v1 bl malloc ; clears pointer for new array loop ldr a4,v1,#4 ; start going through loop starting at top or array mvn a4, a4 ; ones complement add a4,a4,#1 ; make it 2's complement str a4,a1, #4 ; move back into the array subs v2, v2, #1 ; set a flag for the end of the loop bne loop ; start again for the next value in the array ldmfd sp!

, {v1-v6, pc} ; puts all registers back into the caller END output: Original Complement 0 -442500552 -1 -442500552 252 0 -252 0 0 0 3015 0 can anyone help me figure out why its giving me such a messed up output c assembly malloc arm link|improve this question edited Oct 25 '11 at 21:32AusCBloke6,9872921 asked Oct 25 '11 at 21:01NaGeLxZ253.

Str v1, a1 ; copy a1 over to v1 That will store the undefined contents of register v1 over the first element of the int-array passed in a1. You can see that the first element in the original array in your output has been overwritten with 0. If you mean to remember the original a1 in another register, you probably meant mov v1, a1.

Str v2, a2 ; copy a1 over to v1 Again not what you meant, but with a2 being the small integer size I'm surprised this attempt to write to low memory doesn't immediately crash! Bl malloc ; clears pointer for new array You're not passing in the amount of memory you want to malloc here, it's getting the int-array address and treating it as a number of bytes. Assuming 32-bit int, you would want to mov a1, a2, asl#2 to multiply the int size by 4 bytes.

You should probably also check that it hasn't failed and returned NULL. Ldmfd sp! , {v1-v6, pc} ; puts all registers back into the caller The result register a1 will be pointing to the end of its array at this point instead of the start.

You'll want to store the original result of malloc and return it here.

I didn't have any difference of an output doing the changes you selected, but I thank you for your response. – NaGeLxZ Oct 31 '11 at 1:35.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions