Question

Write ARMv8 Assembly code and C++ code for a function called int grade(int n) that returns...

Write ARMv8 Assembly code and C++ code for a function called int grade(int n) that returns the character 'A' if n >= 90, 'B' if 90 > n >= 80, etc. (Use the ASCII code.)

Homework Answers

Answer #1

C++ Code:

int grade(int n){
if(n>=90)
return 65
else if(n<90 && n>=80)
return 66
else if(n<80 && n>=70)
return 67
else if(n<70 && n>=60)
return 68
else if(n<60 && n>=50)
return 69
else
return 70
}

ARMv8 code:

grade(int):

sub sp, sp, #16

str w0, [sp, 12]

ldr w0, [sp, 12]

cmp w0, 89

ble .L2

mov w0, 65

b .L3

.L2:

ldr w0, [sp, 12]

cmp w0, 89

bgt .L4

ldr w0, [sp, 12]

cmp w0, 79

ble .L4

mov w0, 66

b .L3

.L4:

ldr w0, [sp, 12]

cmp w0, 79

bgt .L5

ldr w0, [sp, 12]

cmp w0, 69

ble .L5

mov w0, 67

b .L3

.L5:

ldr w0, [sp, 12]

cmp w0, 69

bgt .L6

ldr w0, [sp, 12]

cmp w0, 59

ble .L6

mov w0, 68

b .L3

.L6:

ldr w0, [sp, 12]

cmp w0, 59

bgt .L7

ldr w0, [sp, 12]

cmp w0, 49

ble .L7

mov w0, 69

b .L3

.L7:

mov w0, 70

.L3:

add sp, sp, 16

ret

if you like the answer please provide a thumbs up.

Know the answer?
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
Similar Questions
Consider the function with header: int foo(int s, int n, int a, int b). Write MIPS...
Consider the function with header: int foo(int s, int n, int a, int b). Write MIPS assembly code for the following statement located inside the above function: return(s+n);
Write a function, grade(score), which is given score, and it returns a letter grade — the...
Write a function, grade(score), which is given score, and it returns a letter grade — the grade for that mark — according to this scheme: A: >= 90 B: [80, 90) C: [70, 80) D: [60, 70) F: < 60 The square and round brackets denote closed and open intervals. A closed interval includes the number, and an open interval excludes it. So 79.99999 gets grade C, but 80 gets grade B. Define the main function as follows: In main,...
Write in C++ a function int sumofdigits( int n ) which computes and returns the sum...
Write in C++ a function int sumofdigits( int n ) which computes and returns the sum of the digits of n. Use the following main function to test your code: int main() { int n, sn; cout << "Enter q to quit or an integer: "; while ( cin >> n ) { sn = sumofdigits(n); cout << "sumofdigits( " << n << " ) = " << sn; cout << "\nEnter q to quit or an integer: "; }...
[ Write in C not C++] Define a C function int round10(double n) that returns the...
[ Write in C not C++] Define a C function int round10(double n) that returns the closest integer of n which is divisible by 10. For example, if n = 16.0, the return value is 20 and if n = 32.34, the return value is 30.
In MIPS assembly, write an assembly language version of the following C code segment: int A[100],...
In MIPS assembly, write an assembly language version of the following C code segment: int A[100], B[100]; for (i=1; i < 100; i++) { A[i] = A[i-1] + B[i]; }
Write a function called read floats(int n) that reads n float values from the user into...
Write a function called read floats(int n) that reads n float values from the user into an array and return the array back to the caller. Recall that a regular array will get deallocated when the function returns. (C++ the simplier the better)
a. Write MIPS assembly code for the following machine code. Assume that the segment is placed...
a. Write MIPS assembly code for the following machine code. Assume that the segment is placed starting at location 8000. Create labels for branch and jump instructions and indicate the 0001 0001 0010 1000 0000 0000 0000 0011 1000 1110 0001 0001 0000 0000 0000 1000 0010 0010 0010 1000 0000 0000 0000 0110 0000 1000 0000 0000 0000 0001 0000 0010 b. Translate the following C function into MIPS assembly code. int f1(int ar1[], int ar2[], int n) {...
How do you write x86 assembly code for the above main procedure and Addarrays function? Main()...
How do you write x86 assembly code for the above main procedure and Addarrays function? Main() {      int A[100];      int   B[100];      // initialization etc.      length = 100;      Call Addarrays(A, B, length) } Addarrays(int[] X, int[] Y, count) {    i = 0;    while (i < count) {        X[i] = X[i] + Y[i];         I++    } }
Write C++ code to: Create a function called “ReadFile” that: Accepts a filename as input Opens...
Write C++ code to: Create a function called “ReadFile” that: Accepts a filename as input Opens the file for reading Reads an integer from the file and returns it. Create a main function that Asks the user to input a file Passes that file to the “ReadFile” function Prints the returned integer to the screen Extra Credit: Set a default argument of “intfile.txt” for the “ReadFile” function Write an overloaded function of “ReadFile” that accepts two filenames and reads an...
8) Write Python code for a function called occurances that takes two arguments str1 and str2,...
8) Write Python code for a function called occurances that takes two arguments str1 and str2, assumed to be strings, and returns a dictionary where the keys are the characters in str2. For each character key, the value associated with that key must be either the string ‘‘none’’, ‘‘once’’, or ‘‘more than once’’, depending on how many times that character occurs in str1. In other words, the function roughly keeps track of how many times each character in str1 occurs...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT