Question

Please convert this C function into ARM ASSEMBLY LANGUAGE CORTEX M (Must be cortex m)

#include<stdio.h>

int ascii(char c)

{

                return (int)c;

}

int computeMagicNumber(char* name)

{

                int sum, i; //varibales

                sum = 0; //set sum to 0

                //calculate sum

                int N = sizeof(name)/sizeof(name[0]); //get name size

                for(i=0;i<N;i++)

                                sum = sum + (i+1)*ascii(name[i]);

               

                return sum%1001; //return magic number

MAIN FUNCTION :

extern int computeMagicNumber(char *);

int main(void) {
        char name[255]="Yusuf Ozturk";
        int magic;

        magic=computeMagicNumber(name);
        printf("\n Magic number is %d\n",magic);

        return EXIT_SUCCESS;
}

}

the full question is

Write an C language function named computeMagicNumber which will accept a string (name of an individual) as input and compute a magic number from this argument using the following formula.

N-1 MagicNun ber-C2(1+1)x(ascii(nameliD)%1001 (it 1) ×lascii(nameli])| |961001 i 0

In the above formula, ascii(name[i]) will return the ascii equivalent of a letter.

There is no need for implementing this function in assembly since characters in a string are already represented in ascii.

% is the remainder operation.

name is the string argument passed to the function

SKELETON

.global upper
.text
upper:











        bx  lr

.global computeMagicNumber
.text 
computeMagicNumber:
0 0
Add a comment Improve this question Transcribed image text
Answer #1

ascii:

sub sp, sp, #16

strb w0, [sp, 15]

ldrb w0, [sp, 15]

add sp, sp, 16

ret

computeMagicNumber:

stp x29, x30, [sp, -80]!

mov x29, sp

str x19, [sp, 16]

str x0, [sp, 40]

add x0, sp, 80

str x0, [sp, 56]

str wzr, [sp, 76]

mov w0, 8

str w0, [sp, 68]

str wzr, [sp, 72]

b .L4

.L5:

ldr w0, [sp, 72]

add w19, w0, 1

ldrsw x0, [sp, 72]

ldr x1, [sp, 40]

add x0, x1, x0

ldrb w0, [x0]

bl ascii

mul w0, w19, w0

ldr w1, [sp, 76]

add w0, w1, w0

str w0, [sp, 76]

ldr w0, [sp, 72]

add w0, w0, 1

str w0, [sp, 72]

.L4:

ldr w1, [sp, 72]

ldr w0, [sp, 68]

cmp w1, w0

blt .L5

ldr w0, [sp, 76]

mov w1, 29855

movk w1, 0x4178, lsl 16

smull x1, w0, w1

lsr x1, x1, 32

asr w2, w1, 8

asr w1, w0, 31

sub w1, w2, w1

mov w2, 1001

mul w1, w1, w2

sub w1, w0, w1

mov w0, w1

ldr x19, [sp, 16]

ldp x29, x30, [sp], 80

ret

* Please try the above code

Add a comment
Know the answer?
Add Answer to:
Please convert this C function into ARM ASSEMBLY LANGUAGE CORTEX M (Must be cortex m) #include<...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C++ please. Thank you!! #include <iostream> #include <cstring> // print an array backwards, where 'first'...

    In C++ please. Thank you!! #include <iostream> #include <cstring> // print an array backwards, where 'first' is the first index // of the array, and 'last' is the last index void writeArrayBackward(const char anArray[], int first, int last) { int i = 0; for (i = last; i >= first; i--) { std::cout << anArray[i]; } std::cout << std::endl; } // test driver int main() { const char *s = "abc123"; writeArrayBackward(s, 0, strlen(s) - 1); } // Using the...

  • Can anyone help to solve this MIPS assembly language problem? Please help. Translate the fowlowwing C...

    Can anyone help to solve this MIPS assembly language problem? Please help. Translate the fowlowwing C code to MIPS assembly language. void main() { int i, sum, begin, end; for(i=0; i < 5; i++){ scanf(“%d, %d”, &begin, &end); sum = accum_range(begin, end); printf(“sum[%d: %d] = %d\n”, begin, end, sum); } int accum_range(int a, int b){ return accum (b) - accum(a); } int accum(int final) { int sum = 0; for (int I = 1; I <= final; I = I...

  • In Programming language C - How would I convert my words char array into a string...

    In Programming language C - How would I convert my words char array into a string array so I can use the strcmp() function and alphabetically sort the words? #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> int main(int argc, char*argv[]){ int i =0; int j =0; int count =0; int length = strlen(argv[1]); for(i =0; i < length; i++){ if(isalpha(argv[1][i]) == 0 ||isdigit(argv[1][i] != 0)){ count ++; } printf("%c",argv[1][i]); } char *strings; int wordNum =0; int charNum =0; strings...

  • Convert C to C++ I need these 4 C file code convert to C++. Please Convert...

    Convert C to C++ I need these 4 C file code convert to C++. Please Convert it to C++ //////first C file: Wunzip.c #include int main(int argc, char* argv[]) { if(argc ==1){ printf("wunzip: file1 [file2 ...]\n"); return 1; } else{ for(int i =1; i< argc;i++){ int num=-1; int numout=-1; int c; int c1;    FILE* file = fopen(argv[i],"rb"); if(file == NULL){ printf("Cannot Open File\n"); return 1; } else{ while(numout != 0){    numout = fread(&num, sizeof(int), 1, file);    c...

  • Please explain lowing function should allocate space for a new string, copy the nd convert every...

    Please explain lowing function should allocate space for a new string, copy the nd convert every string from the passed argument into the new string, a lower-case character in the new string into an upper-case modify the original st character (do not ring). Fill-in the blanks and the body of the for0 loop: char* upcase char str)t char p; char* result; result, (char*) malloc( - strcpy( for( p-result; *p!-10': p++) / Fill-in 'A'-65, 'a' 97, 'Z 90, 'z' 122/ return...

  • I need my c++ code converted to MASM (assembly language). The instructions below: write an assembly...

    I need my c++ code converted to MASM (assembly language). The instructions below: write an assembly program that does the following; 1. count and display the number of words in the user input string. 2. Flip the case of each character from upper to lower or lower to upper. For example if the user types in:   "Hello thEre. How aRe yOu?" Your output should be: The number of words in the input string is: 5 The output string is : hELLO...

  • Convert the following code in to ARM assembly language. Triple Max // Return max of three...

    Convert the following code in to ARM assembly language. Triple Max // Return max of three variables int max(int a, int b, int c) { // Fill in your own code for this function } int main() { // Use registers for local variables int x = 10; int y = 5; int z = 20; int max = max(x, y, z); printf("max = %d\n", max); return 0; }

  • T/F C Language Questions. Answer the following true/false questions. You must correctly state WHY your answer...

    T/F C Language Questions. Answer the following true/false questions. You must correctly state WHY your answer is true or false in order to receive credit. #include <stdio.h> #include <string.h> int run_through(int num, char **a) { int i; int check=0; for(i=0;i<num;i++) { printf("%s\n", *(a+i)); if(strcmp(*(a+i), "filename")==0) { check=1; } } return check; } char** find_filename(int n, char **b) { int i; int check=0; for(i=0;i<n;i++) { if(strcmp(*b, "filename")==0) { b++; break; } b++; } return b; } int main(int argc, char **argv)...

  • Finish function to complete code. #include <stdio.h> #include <stdlib.h> #include<string.h> #define Max_Size 20 void push(char S[],...

    Finish function to complete code. #include <stdio.h> #include <stdlib.h> #include<string.h> #define Max_Size 20 void push(char S[], int *p_top, char value); char pop(char S[], int *p_top); void printCurrentStack(char S[], int *p_top); int validation(char infix[], char S[], int *p_top); char *infix2postfix(char infix[], char postfix[], char S[], int *p_top); int precedence(char symbol); int main() { // int choice; int top1=0; //top for S1 stack int top2=0; //top for S2 stack int *p_top1=&top1; int *p_top2=&top2; char infix[]="(2+3)*(4-3)"; //Stores infix string int n=strlen(infix); //length of...

  • Could someone please help me with this C language code I'm confused as to why i'm...

    Could someone please help me with this C language code I'm confused as to why i'm getting an error every time I run it on command line if some could please help me as soon as possible. #include <stdio.h> #include <stdlib.h> int main() { char *ptr_two = (char *)malloc(sizeof(char)*50); printf("%p\n", ptr_two); ptr_two = "A constant string in C"; printf("%p\n", ptr_two); printf("%s\n", ptr_two); free(ptr_two); return 0; }

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT