Question

Implement the following code using ARM instructions. //Objective to practice on procedure, push and pop. int...

Implement the following code using ARM instructions.

//Objective to practice on procedure, push and pop.

int a=3,b=6,c=2,d=5; /* use registers to store values in global variables*/

main {

          checkEvenfun()

           sunFun()

       }

checkEvenfun() {

                            Check if the register have even numbers if odd replace with 0.

                            Push values in stack.

                           }

         sunFun(){

                           Pop from stack find the sum }

0 0
Add a comment Improve this question Transcribed image text
Answer #1

MOV R0 , #3 \\ R0 is a register used to store the integer value 3

MOV R1, #6 \\ R1 is a register used to store the integer value 6

MOV R2, #2 \\ R2 is a register used to store the integer value 2

MOV R3, #5 \\ R3 is a register used to store the integer value 5

main:

BL checkEvenfun \\ call checkEvenfun()

BL sunFun \\ call sunFun()

.end \\ close the main ()

checkEvenfun:

   DIV R4 , R0, #2, \\ divide R0 by 2 and strore that value into register R4

CMP R4,#0 \\ Compare the division result is 0

BNE else   

MOV R0,#0 \\ if R0 is not even then replace R0 with value 0

PUSH {R0} \\ Push R0 into stack

  

   DIV R5 , R1, #2, \\ divide R1 by 2 and strore that value into register R5

CMP R5,#0 \\ Compare the division result is 0

BNE else   

MOV R1,#0 \\ if R5 is not even then replace R1 with value 0

PUSH {R0,R1} \\ Push R1 into stack

DIV R6 , R2, #2, \\ divide R2 by 2 and strore that value into register R6

CMP R6,#0 \\ Compare the division result is 0

BNE else   

MOV R2,#0 \\ if R2 is not even then replace R2 with value 0

   PUSH {R0,R1,R2} \\ Push R2 into stack

DIV R7 , R3, #2, \\ divide R3 by 2 and strore that value into register R7

CMP R7,#0 \\ Compare the division result is 0

BNE else   

MOV R3,#0 \\ if R5 is not even then replace R1 with value 0

PUSH {R0,R1,R2,R3} \\ Push R3 into stack

.end // end the checkEvenfunction

sunFun :

MOV R8, #0 // R8 is a register used to store the Sum

POP {R0,R1,R2,R3} \\ using loop each register values add with sum

ADD R8,R8,R3

   POP {R0,R1,R2}

  ADD R8,R8,R2

POP {R0,R1}

  ADD R8,R8,R1

POP {R0,}

  ADD R8,R8,R0

DISPLAY R8

.end

Add a comment
Know the answer?
Add Answer to:
Implement the following code using ARM instructions. //Objective to practice on procedure, push and pop. int...
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
  • What is wrong with the following code? This piece of code incorrectly attempts to remove all...

    What is wrong with the following code? This piece of code incorrectly attempts to remove all even values from a stack integers. How would you fix it? You will need to write a class with the main(String[] args) {….} method to test the following piece of code, find the problem, and fix it.                while (!s1.isEmpty()){                               int n = s1.pop();                               if (n % 2 != 0) {                                 s1.push(n); // if odd put it back.                               }                }

  • C++ Carefully review Program 19-2 in your textbook, MathStack. This is a static stack, meaning that the size of the stack is set at the beginning of the program (see line 11): MathStack stack(5). I wo...

    C++ Carefully review Program 19-2 in your textbook, MathStack. This is a static stack, meaning that the size of the stack is set at the beginning of the program (see line 11): MathStack stack(5). I would like you to modify this program as follows: 1. Implement it as a dynamic stack (do not use a static stack as it is designed in the book). Use a linked list to implement this. There's code in the book. 2. Add functionality for...

  • Unrolling Recursion The objective of this problem is to simulate recursion using stacks and loops...

    Unrolling Recursion The objective of this problem is to simulate recursion using stacks and loops. A synthetic linear recursive procedure for this problem is provided in Code Fragment 1. A recursive function such as the one described is intuitive and easily understandable. On calling myRecursion(input), the execution first checks for the stopping condition. If the stopping condition is not met, then operations inside the recursive call are performed. This can include operations on local variables. The operations inside the function...

  • 1.) a.) Using the simplified instruction set shown for part b, write code for the following....

    1.) a.) Using the simplified instruction set shown for part b, write code for the following. Suppose memory locations 1400 to 1449 contain 16-bit words. Each word represents 2 ASCII characters. Write code to read in and write out these 100 characters. Left-side character from location 1400 should be first, right-side character from location 1400 should be second, and remaining characters follow in numeric order. Assume you have access to 4 registers: R1, R2, R3, R4. Each register holds one...

  • Question 1. Assume the following C program and You are writing code using SPIM to implement...

    Question 1. Assume the following C program and You are writing code using SPIM to implement this program. Write the results of each of the following in MIPS instructions. Use registers $t0 - $t7 as needed, Note: int requires 8 bytes 1. Load the contents of dot_prod and i into registers 2. Load the contents of a[i] and b[i] into registers 3. Calculate dot_prod + a[i]*b[i] and save the result into dot_prod please answer each point from (1,2,3) in separated...

  • I need help with this code This is what I need to do: Implement the Stack...

    I need help with this code This is what I need to do: Implement the Stack Class with an ArrayList instead of an array, including the following functions: • empty • push • peek • pop • overrided toString( ) function which returns all of the stack’s contents Things to note: • You no longer need a size. • You no longer need to define a constant DEFAULT_CAPACITY. Since ArrayLists grow dynamically. • Whenever possible, use ArrayList functions instead of...

  • Hello, please correct the following C++ CODE it is not working on visual studio: (I WILL RATE, NO...

    Hello, please correct the following C++ CODE it is not working on visual studio: (I WILL RATE, NO INCOMPLETE OR WRONG SOLUTIONS PLEASE) // CPP program to evaluate a given // expression where tokens are // separated by space. #include using namespace std; // Function to find precedence of // operators. int precedence(char op){ if(op == '+'||op == '-') return 1; if(op == '*'||op == '/') return 2; return 0; } // Function to perform arithmetic operations. int applyOp(int a,...

  • Using the following definition (List.h file) for a list, implement the member functions (methods) for the...

    Using the following definition (List.h file) for a list, implement the member functions (methods) for the List class and store the implementation in a List.cpp file. Use a doubly linked list to implement the list. Write the client code (the main method and other non-class methods) and put in file driver.cpp. file: List.h typedef int ElementType; class node{ ​ElementType data; ​node * next; node* prev; }; class List { public: List(); //Create an empty list bool Empty(); // return true...

  • PLEASE CODE IN C++ AND MAKE IT COPYABLE! In this project, you will design and implement...

    PLEASE CODE IN C++ AND MAKE IT COPYABLE! In this project, you will design and implement an algorithm to determine the next greater element of an element in an array in Θ(n) time, where 'n' is the number of elements in the array. You could use the Stack ADT for this purpose. The next greater element (NGE) for an element at index i in an array A is the element that occurs at index j (i < j) such that...

  • Implement the following statements using MS430 assembly instructions. You may use more than one, ...

    Implement the following statements using MS430 assembly instructions. You may use more than one, but you should minimize the number of instructions required. You can use both native and emulated instructions. Use hex notation for all numbers 1. (a) Move the word located in register R14 to R15 (b) Increment the word in R6 by 2. (c) Perform a bitwise ANDing of the word located at address 0x0240 with the datum in R15, placing the results in R15. (d) Rotate...

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