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

please fill out the blanks with assembly code according to C code above

Solutions

Expert Solution

Here is the c Langauage code:

#include

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:

.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"


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 ; 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...
**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...
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
Write the following code in ARM assembly code g=12, h=8, i=2, j=5; f = (g +...
Write the following code in ARM assembly code g=12, h=8, i=2, j=5; f = (g + h) - (i + j); Your program displays the message: f = (g + h) – (i + j) = 13 Note that 13 should be calculated, not hardcoded
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;
Assembly Language Programming Construct an assembly language program fragment equivalent to the following C/C++ statement: if...
Assembly Language Programming Construct an assembly language program fragment equivalent to the following C/C++ statement: if (M <= N + 3 && (C == ‘N’ || C == ‘n’)) C = ‘0’; else C = ‘1’; Assume that M and N are 32-bit signed integer variables, and C is an 8-bit ASCII character variable. All variables are stored in memory, and all general-purpose registers are available for use.
Question about IEEE 754 and ARM Assembly: So as we know, numbers with fractional components such...
Question about IEEE 754 and ARM Assembly: So as we know, numbers with fractional components such as 45.278 are commonly represented with single precision or double precision IEEE 754 Floating point format (also called binary32 or binary64, respectively). How are numbers stored in these formats? and briefly describe: The fields in the binary32 format (size, purpose, etc) How to convert a binary32 number to a decimal value (write a formula)
Two arrays “Array1” and “Array2” are given with 25 words each. Design an ARM assembly code...
Two arrays “Array1” and “Array2” are given with 25 words each. Design an ARM assembly code to compare sum of the numbers sotred in the arrays. If sum of Array1 is greater, save a “1” in R10, otherwise, save “0’ in R10.
Hello, I am very new to 64-bit ARM assembly and would like the code to this...
Hello, I am very new to 64-bit ARM assembly and would like the code to this following question: The Fibonacci Sequence is a series of integers. The first two numbers in the sequence are both 1; after that, each number is the sum of the preceding two numbers. 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ... For example, 1+1=2, 1+2=3, 2+3=5, 3+5=8, etc. The nth Fibonacci number is the nth number in this sequence, so...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT