完整讲解视频:怎么做一道补全代码题?_哔哩哔哩_bilibili
别忘了一键三连哦
选题三
小明在《计算机系统》的期末考试复习过程中,预感到老师会出如下的题目,但小明不会做,请告诉小明答案及详细的解题过程。
c代码
#include "stdio.h"
#include "stdlib.h"
int main()
{
int a[]={3,-5,6,7,2,-8,10,2,4};
struct link
{
int i;
struct link * next;
struct link * pre;
}head,*p1,*p2;
head.i=a[0];
head.next=NULL;
head.pre=NULL;
int j=0;
p1=__________;
for(j=1;j<=8;j++)
{
p2=(struct link*)malloc(sizeof(head));
p2->i=______;
p1->next=p2;
p2->next=NULL;
p2->pre=p1;
p1=p2;
}
p1=&head;
while(p1->next)
{
if(__________)
____________;
else
p1->i-=p1->next->i;
printf("%d\n",p1->i);
p1=p1->next;
}
return 0;
}
汇编代码
main:
pushl %ebp
movl %esp, %ebp
andl $-16, %esp
subl $80, %esp
movl $3, 20(%esp)
movl $-5, 24(%esp)
movl $6, 28(%esp)
movl $7, 32(%esp)
movl $2, 36(%esp)
movl $-8, 40(%esp)
movl $10, 44(%esp)
movl $2, 48(%esp)
movl $4, 52(%esp)
movl 20(%esp), %eax
movl %eax, 56(%esp)
movl $0, 60(%esp)
movl $0, 64(%esp)
movl $0, 72(%esp)
leal 56(%esp), %eax
movl %eax, 68(%esp)
movl $1, 72(%esp)
jmp .L2
.L3:
movl $12, (%esp)
call malloc
movl %eax, 76(%esp)
movl 72(%esp), %eax
movl 20(%esp,%eax,4), %eax
movl %eax, %edx
imull 72(%esp), %edx
movl 76(%esp), %eax
movl %edx, (%eax)
movl 68(%esp), %eax
movl 76(%esp), %edx
movl %edx, 4(%eax)
movl 76(%esp), %eax
movl $0, 4(%eax)
movl 76(%esp), %eax
movl 68(%esp), %edx
movl %edx, 8(%eax)
movl 76(%esp), %eax
movl %eax, 68(%esp)
addl $1, 72(%esp)
.L2:
cmpl $8, 72(%esp)
jle .L3
leal 56(%esp), %eax
movl %eax, 68(%esp)
jmp .L4
.L7:
movl 68(%esp), %eax
movl (%eax), %edx
movl 68(%esp), %eax
movl 4(%eax), %eax
movl (%eax), %eax
leal (%edx,%eax), %ecx
movl 68(%esp), %eax
movl (%eax), %edx
movl 68(%esp), %eax
movl 4(%eax), %eax
movl (%eax), %eax
imull %edx, %eax
movl %eax, %edx
shrl $31, %edx
addl %edx, %eax
sarl %eax
cmpl %eax, %ecx
jle .L5
movl 68(%esp), %eax
movl (%eax), %edx
movl 68(%esp), %eax
movl 4(%eax), %eax
movl (%eax), %eax
addl %eax, %edx
movl 68(%esp), %eax
movl %edx, (%eax)
jmp .L6
.L5:
movl 68(%esp), %eax
movl (%eax), %edx
movl 68(%esp), %eax
movl 4(%eax), %eax
movl (%eax), %eax
subl %eax, %edx
movl 68(%esp), %eax
movl %edx, (%eax)
.L6:
movl 68(%esp), %eax
movl (%eax), %edx
movl $.LC0, %eax
movl %edx, 4(%esp)
movl %eax, (%esp)
call printf
movl 68(%esp), %eax
movl 4(%eax), %eax
movl %eax, 68(%esp)
.L4:
movl 68(%esp), %eax
movl 4(%eax), %eax
testl %eax, %eax
jne .L7
movl $0, %eax
leave
ret
小组PPT