Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6745451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:12:22+00:00 2026-05-26T12:12:22+00:00

My assignment is to take an array of numbers and put it into ARM

  • 0

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 <stdio.h>

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 < size ; i++ )
printf( "%d %d\n", array[i], *(result+i) ) ;

}

ARM assembly:

AREA |comp$code|, CODE, READONLY ; tell the assembler stuff

IMPORT malloc ; import malloc to be used

EXPORT comp ; tell the assembler to show this label to the linker

comp ; the label defining the entry point

stmfd sp!, {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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:12:23+00:00Added an answer on May 26, 2026 at 12:12 pm
    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a school assignment I have to write x86 assembly code, except I can't
I am writing an assignment in MASM32 Assembly and I almost completed it but
I have a byte array that has hex values and I initially put those
I have a program where i simply copy a byte array into a long
I want to take a string,and populate an array with its values. I know
I'm working on a Java assignment, where we take a date and do some
I was given an assignment to write a program to print only even numbers
For my university assignment I have to design some basic managment system for sicknesses
For a database assignment I have to model a system for a school. Part
For my assignment I have been assigned the task of creating a DTD for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.