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;
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.
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)
HCS12 Assembly code please. Translate the following code into assembly. Allocate each variable on the stack....
HCS12 Assembly code please. Translate the following code into assembly. Allocate each variable on the stack. Simulate your program and screenshot the final value of the variables in memory. { char A,B,C; int F; A = 2; B = 6; C = - 10; F = (A + B)*C; C = F +10 }
5.29) Explain what the following fragment of code achieves. Note that the data is signed and...
5.29) Explain what the following fragment of code achieves. Note that the data is signed and that the packed shift right arithmetic instruction operates on word (16-bit) operands. MOVQ MM0, MM1 PSRAW MM0, 15 PXOR MM0, MM1 5.30) Consider the following block of operations that might be found inside a loop. Explainf what the instructions do and what operation is being performed on the data. MOVQ MM1, A ; move 8 pixels of image A MOVQ MM2, B ; move...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT