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
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
ADVERTISEMENT