Question

#include <stdio.h> int main() { int list[16]; int j, numItems; int temp; scanf("%d",&numItems); for(j=o; j< numItems;...

#include <stdio.h>
int main()
{
int list[16];
int j, numItems;
int temp;
scanf("%d",&numItems);
for(j=o; j< numItems; j++)
scanf("%d",&list[j]);

temp=list[0];
for(j=0; j<numItems-1; j++)
list[j]=list[j+1];

list[numItems-1]=temp
for(j=0; j< numItems-1;j++)
printf("%d\t", list[j]);

printf("\n");
return 0

}

If someone could please turn this c program in pep 9 assembly language. Pep 9 not pep 8

please explain the logic

and make sure to use the following four functions

getlist()

putlist()

rotate();

putlist();

each function has two parameters

Please do the source code not the object code for pep9

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

Question :

Convert below C Code to Assembly Code :

C Code

#include <stdio.h>

int list[16];

int j, numItems;

int temp;

int main()

{

scanf("%d", &numItems);

for (j = 0; j < numItems; j++)

{

scanf("%d", &list[j]);

}

temp = list[0];

for (j = 0; j < numItems - 1; j++)

{

list[j] = list[j + 1];

}

list[numItems - 1] = temp;

for (j = 0; j < numItems; j++)

{

printf("%d ", list[j]);

}

printf("\n");

return 0;

}

Answer:

Assembly Code for the above C Code is as follows :

.LC0:

.string "%d"

.LC1:

.string "%d "

main:

push rbp

mov rbp, rsp

mov esi, OFFSET FLAT:numItems

mov edi, OFFSET FLAT:.LC0

mov eax, 0

call __isoc99_scanf

mov DWORD PTR j[rip], 0

jmp .L2

.L3:

mov eax, DWORD PTR j[rip]

cdqe

sal rax, 2

add rax, OFFSET FLAT:list

mov rsi, rax

mov edi, OFFSET FLAT:.LC0

mov eax, 0

call __isoc99_scanf

mov eax, DWORD PTR j[rip]

add eax, 1

mov DWORD PTR j[rip], eax

.L2:

mov edx, DWORD PTR j[rip]

mov eax, DWORD PTR numItems[rip]

cmp edx, eax

jl .L3

mov eax, DWORD PTR list[rip]

mov DWORD PTR temp[rip], eax

mov DWORD PTR j[rip], 0

jmp .L4

.L5:

mov eax, DWORD PTR j[rip]

add eax, 1

mov ecx, DWORD PTR j[rip]

cdqe

mov edx, DWORD PTR list[0+rax*4]

movsx rax, ecx

mov DWORD PTR list[0+rax*4], edx

mov eax, DWORD PTR j[rip]

add eax, 1

mov DWORD PTR j[rip], eax

.L4:

mov eax, DWORD PTR numItems[rip]

lea edx, [rax-1]

mov eax, DWORD PTR j[rip]

cmp edx, eax

jg .L5

mov eax, DWORD PTR numItems[rip]

sub eax, 1

mov edx, DWORD PTR temp[rip]

cdqe

mov DWORD PTR list[0+rax*4], edx

mov DWORD PTR j[rip], 0

jmp .L6

.L7:

mov eax, DWORD PTR j[rip]

cdqe

mov eax, DWORD PTR list[0+rax*4]

mov esi, eax

mov edi, OFFSET FLAT:.LC1

mov eax, 0

call printf

mov eax, DWORD PTR j[rip]

add eax, 1

mov DWORD PTR j[rip], eax

.L6:

mov edx, DWORD PTR j[rip]

mov eax, DWORD PTR numItems[rip]

cmp edx, eax

jl .L7

mov edi, 10

call putchar

mov eax, 0

pop rbp

ret

Write, Compile and Execute the same in 8085/8086 compiler compatible operating systems validate and verify the output results, with respect to different input values.

Add a comment
Know the answer?
Add Answer to:
#include <stdio.h> int main() { int list[16]; int j, numItems; int temp; scanf("%d",&numItems); for(j=o; j< numItems;...
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
  • Translate the following C program to Pep/9 assembly language. #include <stdio.h> int main() {     int...

    Translate the following C program to Pep/9 assembly language. #include <stdio.h> int main() {     int number;     scanf("%d", &number);     if (number % 2 == 0) {         printf("Even\n");     }     else {         printf("Odd\n");     }     return 0; }

  • #include<stdio.h> int main() {       int data[10], i, j, temp;       printf("Enter 10 random number to...

    #include<stdio.h> int main() {       int data[10], i, j, temp;       printf("Enter 10 random number to sort in ascending order:\n");       for(i = 0; i < 10; i++)             scanf("%d", &data[i]);       /* Sorting process start */     ****** INSERT YOUR CODE TO COMPLETE THE PROGRAM ******       printf("After sort\n");       for(i = 0; i < 10; i++)             printf("%d\n",data[i]);       return 0; } Looking for alternative solutions for the program code.

  • Translate the following C program to Pep/9 assembly language. #include <stdio.h> const int limit = 5;...

    Translate the following C program to Pep/9 assembly language. #include <stdio.h> const int limit = 5; int main() { int number; scanf("%d",&number); while (number < limit){ number++; printf("%d",number); } return 0; }

  • #include<stdio.h> #include<stdio.h> int main(){ int i; //initialize array char array[10] = {“Smith”, “Owen”, “Kowalczyk”, “Glass”, “Bierling”,...

    #include<stdio.h> #include<stdio.h> int main(){ int i; //initialize array char array[10] = {“Smith”, “Owen”, “Kowalczyk”, “Glass”, “Bierling”, “Hanenburg”, “Rhoderick”, “Pearce”, “Raymond”, “Kamphuis”}; for(int i=0; i<8;i++){ for(int j=0; j<9; j++){ if(strcmp(array[j],array[j+1])>0){ char temp[20]; strcpy(temp,array[j]); strcpy(array[j],array[j+1]); strcpy(array[j+1],temp); } } } printf(“---------File Names---------\n”); for(inti=0; i<9; i++){ printf(“\t%s\n”,array[i]); } printf(-------5 Largest Files according to sorting----\n”); for(int i=0;i>=5;i--) { printf(“\t%s\n”,array[i]); } return0; } Consider the "sort" program (using with void* parameters in the bubblesort function) from the week 10 "sort void" lecture. Modify it as follows...

  • C program-- the output is not right please help me to correct it. #include <stdio.h> int...

    C program-- the output is not right please help me to correct it. #include <stdio.h> int main() { int arr[100]; int i,j,n,p,value,temp; printf("Enter the number of elements in the array: \n "); scanf("%d",&n); printf("Enter %d elements in the array: \n",n); for(i=0;i<n;i++) { printf("\nelement %d: ",i); scanf("\n%d",&arr[i]); } printf("\nEnter the value to be inserted: \n "); scanf("\n%d",&value); printf("The exist array is: \n"); for(i=0;i<n;i++) { printf("%d",arr[i]); } p=i; for(i=0;i<n;i++) if(value<arr[i] ) { p = i; break; } arr[p]=value; printf("\n"); for (i =...

  • Can you write the algorithm for this code? #include<stdio.h> int main() { int process[20], priority[20], arrival_time[20],...

    Can you write the algorithm for this code? #include<stdio.h> int main() { int process[20], priority[20], arrival_time[20], burst_time[20], turnaround_time[20], waiting_time[20]; int i, j, limit, sum = 0, position, temp; float average_wait_time, average_turnaround_time; printf("Enter Total Number of Processes:\t"); scanf("%d", &limit); printf("\nEnter Burst Time and Priority For %d Processes\n", limit); for(i = 0; i < limit; i++) { printf("\nProcess[%d]\n", i + 1); printf("Process Burst Time:\t"); scanf("%d", &burst_time[i]); printf("Process Priority:\t"); scanf("%d", &priority[i]); process[i] = i + 1; } for(i = 0; i < limit;...

  • #include <stdio.h> #include <stdlib.h> #include <math.h> int count,i, tracker = 0; int main() { scanf("%d\n", &count);...

    #include <stdio.h> #include <stdlib.h> #include <math.h> int count,i, tracker = 0; int main() { scanf("%d\n", &count); int numbers[count]; //GEtting the numbers and satisfy BS conditions for (i = 0; i < count; i++) { if (scanf("%d", &numbers[i]) != EOF) { tracker++; } if (numbers[i] < 0 || numbers[i] > 99) { printf("%d is not in the [0, 99] range.\n",numbers[i]); exit(i); } } if( tracker != count) { printf("%d numbers are required, but only %d were provided.\n", count, tracker); exit(1); }...

  • Solve using C programming 3. lf you are given this code. #include <stdio.h> int main() int...

    Solve using C programming 3. lf you are given this code. #include <stdio.h> int main() int var1, var2; int sum; printf("Enter number 1:\n "); scanf("%d",&var1); printf("Enter number 2:In ); scanf("%d",&var2); sum-var1+var2; printf ("Vnsum of two entered numbers : %d", //printf ("Output: %d", res); sum); return e; Modify this code by creating a function called "addition". Make the arguments of the functions numberl and number 2. Add the two values in the function. Return a value called "result". Print "result" in...

  • i need flowchart for the following c code #include <stdio.h> int main() {     int n,...

    i need flowchart for the following c code #include <stdio.h> int main() {     int n, i, sum = 0;     printf("Enter an integer: ");     scanf("%d",&n);     i = 1;     while ( i <=n )     {         sum += i;         ++i;     }     printf("Sum = %d",sum);     return 0; }

  • #include<stdio.h> int main() { int i; printf("Type an integer value: "); scanf("%d",&i); evaluate(i); return(0); } void...

    #include<stdio.h> int main() { int i; printf("Type an integer value: "); scanf("%d",&i); evaluate(i); return(0); } void evaluate(int x) { if(x > 10) printf("Value entered by you is greater than 10"); else if(x < 10) printf("Value entered by you is less than 10"); else printf("Value entered by you is equal 10"); } _______________________________________ report for this in hr ?

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