Question

In: Computer Science

**Add comments to existing ARM code to explain steps** Question that my code answers: Write an...

**Add comments to existing ARM code to explain steps**

Question that my code answers: Write an ARM assembly program to calculate the value of the following function:

f(y) = 3y^2 – 2y + 10 when y = 3.

My Code below, that needs comments added:

FunSolve.s

LDR R6,=y

LDR R1,[R6]

MOV R2,#5

MOV R3,#6

MUL R4,R1,R1

MUL R4,R4,R2

MUL R5,R1,R3

SUB R4,R4,R5

ADD R4,R4,#8

st B st

y DCD 3

Solutions

Expert Solution

Your code and its meaning is as follows

LDR R6,=y            // Load the address for the value of 'y' as R6

LDR R1,[R6]         // Load the value at the address found in R6 to register R1 (R1 = 3)

MOV R2,#5         // Move the number 5 to R2 (R2 = 5)

MOV R3,#6         // Move the number 6 to R3 (R3 = 6)

MUL R4,R1,R1   // R4 = R1 * R1 (R4 = 3 * 3 = 9)

MUL R4,R4,R2   // R4 = R4 * R2 ( R4 = 9 * 5 = 45)

MUL R5,R1,R3   // R5 = R1 * R3 (R5 = 3 * 6 = 18)

SUB R4,R4,R5   // R4 = R4 - R5 (R4 = 45 - 18 = 27)

ADD R4,R4,#8   // R4 = R4 +8 (R4 = 27 + 8 = 35)

st B st                  // ***********I didn't get it **********

y DCD 3              // Defining a constant data 3 to 'y' ( y = 3)

The constant values you entered in this code will not produce the correct result.

The function given here is

f(y) = 3y^2 - 2y + 10

and then putting y=3

f(3) = 3 * (3 * 3) - 2 * 3 +10

      = 31

The correct code is

LDR R6,=y            // Load the address for the value of 'y' as R6

LDR R1,[R6]         // Load the value at the address found in R6 to register R1 (R1 = 3)

MOV R2,#3         // Move the number 3 to R2 (R2 = 3)

MOV R3,#2        // Move the number 2 to R3 (R3 = 2)

MUL R4,R1,R1   // R4 = R1 * R1 (R4 = 3 * 3 = 9; this indicate y^2)

MUL R4,R4,R2   // R4 = R4 * R2 ( R4 = 9 * 3 = 27; this indicate 3y^2)

MUL R5,R1,R3   // R5 = R1 * R3 (R5 = 3 * 2 = 6; this indicate 2y)

SUB R4,R4,R5   // R4 = R4 - R5 (R4 = 27 - 6 = 21; this indicate 3y^2-2y)

ADD R4,R4,#10 // R4 = R4 + 10 (R4 = 21 + 10 = 31)

STR R1, R4          // Storing the result 31 in register R1 (R1 = 31)

y DCD 3              // Defining a constant data 3 to 'y' ( y = 3)


Related Solutions

**Add comments to existing ARM code to explain steps** Write an ARM assembly program to convert...
**Add comments to existing ARM code to explain steps** Write an ARM assembly program to convert temperatures from Celsius to Fahrenheit or from Fahrenheit to Celsius. Here are the two formulas for your reference. Use variable to read and store values. C= 5* (F - 32) / 9 F = (9 * C / 5 ) + 32 My code below: TempConvert.s LDR R8,=temperature LDR R1,[R8] LDR R8,=unit LDRB R2,[R8] LDR R8,=celsius LDRB R3,[R8] LDR R8,=fahrenheit LDRB R4,[R8] MOV R6,#9...
Understand the code and explain the code and answer the questions. Type your answers as comments....
Understand the code and explain the code and answer the questions. Type your answers as comments. #include #include using namespace std; // what is Color_Size and why it is at the end? enum Color {        Red, Yellow, Green, Color_Size }; // what is Node *next and why it is there? struct Node {        Color color;        Node *next; }; // explain the code below void addNode(Node* &first, Node* &last, const Color &c) {        if (first == NULL)...
Calculator in Assembly Language (Please add comments to explain your steps) Description: You are responsible to...
Calculator in Assembly Language (Please add comments to explain your steps) Description: You are responsible to implement several assembly functions to perform the simple arithmetic calculations for 2 64-bit integers. These functions will use the C function signature but the main logic within this function should be inline assembly code using the ASM block similar to the assembly example shown in class. Program Specification: 1. long mult ( long op1, long op2 ) - Can’t use the MUL/IMUL instructions, meaning...
Please write code in java ASAP and add comments too, will be really appreciated. Thanks CSCI203/CSCI803...
Please write code in java ASAP and add comments too, will be really appreciated. Thanks CSCI203/CSCI803 This assignment involves extension to the single source-single destination shortest path problem. The Program Your program should: 1. Read the name of a text file from the console. (Not the command line) 2. Read an undirected graph from the file. 3. Find the shortest path between the start and goal vertices specified in the file. 4. Print out the vertices on the path, in...
write the code in MATLAB with comments and show the inputs and results of the code...
write the code in MATLAB with comments and show the inputs and results of the code for the question below. Write an .m file in MATLAB, that records audio (you can record your own voice for 20 seconds that was recorded using your phone), then take Fourier transform of the signal (probably FFT).
Please add comments to this code! JAVA Code: import java.text.NumberFormat; public class Item {    private...
Please add comments to this code! JAVA Code: import java.text.NumberFormat; public class Item {    private String name;    private double price;    private int bulkQuantity;    private double bulkPrice;    /***    *    * @param name    * @param price    * @param bulkQuantity    * @param bulkPrice    */    public Item(String name, double price, int bulkQuantity, double bulkPrice) {        this.name = name;        this.price = price;        this.bulkQuantity = bulkQuantity;        this.bulkPrice = bulkPrice;   ...
Please add comments to this code! JAVA code: import java.util.ArrayList; public class ShoppingCart { private final...
Please add comments to this code! JAVA code: import java.util.ArrayList; public class ShoppingCart { private final ArrayList<ItemOrder> itemOrder;    private double total = 0;    private double discount = 0;    ShoppingCart() {        itemOrder = new ArrayList<>();        total = 0;    }    public void setDiscount(boolean selected) {        if (selected) {            discount = total * .1;        }    }    public double getTotal() {        total = 0;        itemOrder.forEach((order) -> {            total +=...
Can you please add comments to this code? JAVA Code: import java.util.ArrayList; public class Catalog {...
Can you please add comments to this code? JAVA Code: import java.util.ArrayList; public class Catalog { String catalog_name; ArrayList<Item> list; Catalog(String cs_Gift_Catalog) { list=new ArrayList<>(); catalog_name=cs_Gift_Catalog; } String getName() { int size() { return list.size(); } Item get(int i) { return list.get(i); } void add(Item item) { list.add(item); } } Thanks!
Explain your code with comments. Solve in C++. 1. Write a str2int() function that convers a...
Explain your code with comments. Solve in C++. 1. Write a str2int() function that convers a string to integer. The function will take the number as a string then will return it as integer. E.g. str2int(“123”) will return 123 str2int(“005”) will return 5 str2int(“102”) will return 102
Please add to this Python, Guess My Number Program. Add code to the program to make...
Please add to this Python, Guess My Number Program. Add code to the program to make it ask the user for his/her name and then greet that user by their name. Please add code comments throughout the rest of the program If possible or where you add in the code to make it ask the name and greet them before the program begins. import random def menu(): print("\n\n1. You guess the number\n2. You type a number and see if the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT