Question

Write C code that perform the same as the assembly code. Hint:data is an integer avariable in C. OUT is a name of a function:- //code part is the following.. L1 LDR R0, =0X006 ;The hexadecimal of 0110...

Write C code that perform the same as the assembly code. Hint:data is an integer avariable in C. OUT is a name of a function:- //code part is the following..

L1 LDR R0, =0X006 ;The hexadecimal of 0110 is 0x006

L2 LDR R1, =data

L3 LDR R2, [data]

L4 AND R2, #0X006

L5 CMP R2, #0X006

L6 BLEQ OUT

L7 ..................

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

Lets understand what each instruction is doing.

L1 LDR R0, =0X006   //Load into R0 the value 6

L2 LDR R1, =data    //Load into R1 the value of data

L3 LDR R2, [data] //load into R2, the address of variable data

L4 AND R2, #0X006 //Perform AND operation of R2 with value 6 and store in R2

L5 CMP R2, #0X006 //compare the content of R2 and 0x006

L6 BLEQ OUT   //If content of R2 is less than or equal to 6 then call the function at address OUT.

Below is the equivalent C code:-

int a,b,*c;

a = 6; //load value 6 into variable a

b = data;   //load the value of data in b

c = &data; //load the address of variable data into point c

c = c & 6; //perform bitwise AND operation of pointer c with 6

if( c <= 6)

OUT();    //call the function OUT if c is <= 6

Please comment for any clarification.

Add a comment
Know the answer?
Add Answer to:
Write C code that perform the same as the assembly code. Hint:data is an integer avariable in C. OUT is a name of a function:- //code part is the following.. L1 LDR R0, =0X006 ;The hexadecimal of 0110...
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
  • Write an equivalent C function and explain what it computes. 3. (10 marks) The following is...

    Write an equivalent C function and explain what it computes. 3. (10 marks) The following is the assembly language translation of a C function mystery: r3, [r0, #0] r3, #0 L3 ldrb cmp beq r3, #0 mov L4: r3, r3, #1 r2, [ro, r3] r2, #0 L4 add ldrb cmp bne .L3: ro, r3 lr mov bx Annotate each line of the function with commentss to explain what each line does. Write an equivalent C function and explain what it...

  • Section B - ARM Assembly Language (25 marks) An ARM instruction set summary is provided at...

    Section B - ARM Assembly Language (25 marks) An ARM instruction set summary is provided at the end of this paper 1. (5 marks) Consider the following assembly instruction STMFD r13!, (r5-6} Before executing this instruction, registers hold the following values: Register Value Register r9 Value r4 0x00400040 0x00000000 r5 r10 0x11223344 0x00800080 r6 0x55667788 r11 0x10001000 r7 0x99aabbcc r12 0x20002000 r8 exddeeff00 r13 ex40004000 What memory locations are affected after executing the above instruction? In a table, with a...

  • 1.The following pseudocode algorithm is used to calculate the average of two numbers. Perform a desk...

    1.The following pseudocode algorithm is used to calculate the average of two numbers. Perform a desk check on this algorithm assuming the firstValue is 12.5 and the secondValue is 7.5. You should use a table to show your answer. L1: Program AverageCalculator; L2: Data firstValue as float; L3: Data SecondValue as float; L4: Data average as float; L5: Output “Enter the first Number”; L6: Input firstValue; L7: Output “Enter the second Number”; L8: Input secondValue; L9: average = (firstValue+secondValue)/2; L10:...

  • Write a new subroutine in assembly to convert the upper-case letters to lower-case letter. Example of...

    Write a new subroutine in assembly to convert the upper-case letters to lower-case letter. Example of lower case to upper is provided below: Let’s look at a subroutine to capitalize all the lower-case letters in the string. We need to load each character, check to see if it is a letter, and if so, capitalize it. Each character in the string is represented with its ASCII code. For example, ‘A’ is represented with a 65 (0x41), ‘B’ with 66 (0x42),...

  • Trying to figure out how to write expression #2 in assembly language: 1. ;;X=A*C+B*D MUL R4,R0,R2...

    Trying to figure out how to write expression #2 in assembly language: 1. ;;X=A*C+B*D MUL R4,R0,R2 MUL R5,R1,R3 ADDS R4,R4,R5 ;;X is in R4 I believe this is correct but Im having trouble with #2 below: 2. Y=A^(B+C)+D I've been using the arm cortex m4 instruction set for reference.

  • Exercise 3 [Conditionals] Consider the following assembly code for a function F3 with two integer arguments:...

    Exercise 3 [Conditionals] Consider the following assembly code for a function F3 with two integer arguments: F3: push EBP mov EBP, ESP mov EDX, DWORD PTR [ebp+12] mov EAX, DWORD PTR [ebp+8] cmp EAX, EDX # setup stack #if # goto .L1 #EAX- mov EAX, EDX # ignore for now mov DWORD PTR [EBP-4], EAX mov ESP, EBP pop EBE ret # cleanup stack To the right of each instruction, show the contents of the register whose value changes as...

  • Write a program in ARM assembly using ARMSim# to perform the following tasks: 1. Open a...

    Write a program in ARM assembly using ARMSim# to perform the following tasks: 1. Open a file named "integers.dat" and keep track of the following information: a.The first integer value is (i) b. The ith integer value is (j) c. Count the total number of integers in the file d. Count the number of integers that are less than j e. Count how many even numbers are less than j f. And how many odd numbers are less than j...

  • Write a C program for: One technique for dealing with deadlock is called “detect and recover.” In...

    Write a C program for: One technique for dealing with deadlock is called “detect and recover.” In this scheme, some procedure is used to identify when a deadlock occurs, and then another procedure is used to deal with the blocked processes. One technique to identify a deadlock is to maintain a resource graph that identifies all processes, all resources, and the relationships between them (that is, which processes exclusively own which resources, and which processes are blocked waiting for which...

  • Write out C++ code for the following: Declare a templated function that has a return type...

    Write out C++ code for the following: Declare a templated function that has a return type of T". It has two parameters: An array of T items named arr, and an integer named size. This function is assumed to work with numerical data types. Within the function, create a new T variable named sum and initialize it to 0. Use a for-loop to go from 0 (inclusive) to size (exclusive), adding each element from arr to the sum. Finally, return...

  • PLEASE USE VERY BASIC REGISTERS AND CODE TO DO THE FOLLOWING Objectives: -write assembly language programs...

    PLEASE USE VERY BASIC REGISTERS AND CODE TO DO THE FOLLOWING Objectives: -write assembly language programs to:             -define a recursive procedure/function and call it.             -use syscall operations to display integers and strings on the console window             -use syscall operations to read integers from the keyboard. Assignment Description: Implement a MIPS assembly language program that defines "main", and "function1" procedures. The function1 is recursive and should be defined as: function1(n) = (2*n)+9                      if n <= 5              =...

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