Question

In: Computer Science

The following code fragment is expressed in arm assembly code. Fill in the blanks, so that...

The following code fragment is expressed in arm assembly code. Fill in the blanks, so that it is equivalent to the following C code.

int counter;

int x = 5;

int y = 6;

for (counter =10; counter >0;counter--)

IF(X==Y)

Y = Y + 1 ;

ELSE

Y = Y + 2}

Fill in the blanks in the following code:

MOV__________ ;loop counter into r0-ten times round the loop

MOV__________ ;Value of y loaded into r1

MOV__________ ;Value of x loaded into r2

Next CMP ____________ ;assume r1 contains y and r2 contains x: compare them

BNE ____________ ;if not equel then branch to the else part

ADD ____________ ;if equal fall through to here and add one to y

B _____________ ;now skip past the else part

plus2 ______________ ;ELSE part add 2 to y

counter ______________ ;decrement loop counter

BNE _____________ ;continue until all done

Solutions

Expert Solution

C language code:

#include<stdio.h>

int main() {
int counter;

int x = 5;

int y = 6;

for (counter =10; counter >0;counter--)
{
if(x==y)
{
y=y+1;
}
else
{
y=y+2;
}
}
}

-----------------------------------------------------------

Ans

Here is the equivalent assembly code:

Ans here is the equivalent assembly code:

. file "Test.c"

.def ___main; .scl 2; .type 32; .endef

.text

.globl _main

.def _main;. scl 2; type 32; .endef

_main:

pushl %ebp

movl %esp, %ebp

andl $-16, %esp

subl $16, %esp

call ___main

movl $5, 4(%esp)

movl $6, 8(%esp)

movl $10, 12(%esp)

jmp L2

L5:

movl 4(%esp), %eax

cmpl 8(%esp), %eax

jne L3

addl $1, 8(%esp)

jmp L4

L3:

addl $2, 8(%esp)

L4:

subl $1, 12(%esp)

L2:

cmpl $0, 12(%esp)

jg L5

movl $0, %eax

leave

ret

.ident "GCC: (tdm-1) 4.9.2"

_________________________________________________________

I didn't filled the blanks because different system generates different address spaces.


Related Solutions

The following code fragment is expressed in arm assembly code.Fill in the blanks, so that...
The following code fragment is expressed in arm assembly code. Fill in the blanks, so that it is equivalent to the following C code.int counter;int x = 5;int y = 6;for (counter =10; counter >0;counter--)IF(X==Y)Y = Y + 1 ;ELSEY = Y + 2}Fill in the blanks in the following code:MOV__________ ;loop counter into r0-ten times round the loopMOV__________ ;Value of y loaded into r1MOV__________ ;Value of x loaded into r2Next CMP ____________ ;assume r1 contains y and r2 contains...
Fill in the blanks of the following segment of code, so that the output would be 1 3 4.
Fill in the blanks of the following segment of code, so that the output would be 1 3 4.int count = 0;do{++ count;if (count == 2)Blank;cout << count << " ";} while (count <= Blank);cout << endl;
Fill in the blanks in the MATLAB code below.
Fill in the blanks in the MATLAB code below. (Do not type unnecessary words or blank spaces in your response. The correct answers are case-sensitive.) % Consider a row vector v. % Complete the lines of code below to find the average and standard deviation of the elements of vector v such that these two values are assigned to variables M and S, respectively. E = G =
Fill in the blanks with suitable code and identify the type of inheritance in the following...
Fill in the blanks with suitable code and identify the type of inheritance in the following code snippet.(CO5) [Write all the three constructors completely in the answer sheet. Don’t write any other parts of the program] class Xyz { int one, two; public: Xyz(--------) {one=i; --------; } }; class Abc { int dc; public: Abc(int k) {-----------;} }; class Ijk: public Abc, public Xyz { int f; public: Ijk(int l, int m, int z, int n):-------,--------- { f=n;} }; int...
Fill in the blanks: Consider the following equilibrium and fill in the blanks with either increase...
Fill in the blanks: Consider the following equilibrium and fill in the blanks with either increase or decrease. I2(s) + 5F2(g) ⇌ 2IF5(g) A decrease in volume results in a Blank 1 in pressure which will Blank 2 the amount of IF5.
Fill-In-The-Blanks 13. Complete the code by filling in the blanks for each question below. (Length of...
Fill-In-The-Blanks 13. Complete the code by filling in the blanks for each question below. (Length of blank doesn’t matter.) a) Print out the contents of the array airlines. #include #include ________________ using namespace std; int main () { string airlines[] = {"american","pan-am","southwest"}; for (int i = 0;_______________;i++) cout << ____________ << endl; return 0; } b) Read in 5 integers from the user and write them back out in reverse order int numbers[5]; for(int i = 0; ___________; _________) cin...
**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...
Fill in the blanks on the following table
 Fill in the blanks on the following tableE&pshareholder basisdistributiondividendreturn of capitalcapital gain20,000300,00080,000120,00010,000170,000220,000100,000170,00020,000080,000<20,000>50,000170,000
Complete the AVR assembly language fragment below so that it does a multiply by 2 of...
Complete the AVR assembly language fragment below so that it does a multiply by 2 of the two's complement 32-bit quantity in registers r18:r19:r20:r21. (r18 is the most significant byte.) asrlsrlslaslrolrorr18r19r20r21  asrlsrlslaslrolrorr18r19r20r21 asrlsrlslaslrolrorr18r19r20r21  asrlsrlslaslrolrorr18r19r20r21 asrlsrlslaslrolrorr18r19r20r21  asrlsrlslaslrolrorr18r19r20r21 asrlsrlslaslrolrorr18r19r20r21  asrlsrlslaslrolrorr18r19r20r21
Complete the AVR assembly language fragment below so that it performs a division by 2 of...
Complete the AVR assembly language fragment below so that it performs a division by 2 of the 24-bit two's complement value in registers r6:r5:r4. (r6 is the most significant byte.) lslasllsrasrrolrorr4r5r6  lslasllsrasrrolrorr4r5r6 lslasllsrasrrolrorr4r5r6  lslasllsrasrrolrorr4r5r6 lslasllsrasrrolrorr4r5r6  lslasllsrasrrolrorr4r5r6
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT