test2-v1.fmCS350 Spring XXXXXXXXXXTest 2, Thur, 4/9/2020CS350 Spring XXXXXXXXXXTest 2, Thur, 4/9/20201. (5 points) Complete the C function below. Convert shift to a number. Do not use >> or :2...

1 answer below »
These are sample exams (attached below) Please answer them (with 2022 one being the priority) and make notes on how you solved them/or any other helpful notes. Goal here is to learn and prepare for a likewise test. Please include notes and all. I also attached a sample graded exam if that helps. Please include any material that makes the concepts easy to understand. You may also visit:http://www.cs.cmu.edu/afs/cs/academic/class/15213-f15/www/schedule.html for further help.










Thank you.



test2-v1.fm CS350 Spring 2020 1 Test 2, Thur, 4/9/2020 CS350 Spring 2020 1 Test 2, Thur, 4/9/2020 1. (5 points) Complete the C function below. Convert shift to a number. Do not use >> or <: unknown:="" movq="" %rsi,="" %rax="" sarq="" $1,="" %rax="" addq="" %rdi,="" %rax="" ret="" long="" unknown(long="" x,="" long="" y)="" {="" return="" ______________________________________;="" }="" cs350="" spring="" 2020="" 2="" test="" 2,="" thur,="" 4/9/2020="" cs350="" spring="" 2020="" 2="" test="" 2,="" thur,="" 4/9/2020="" 2.="" (10="" points)="" assume="" the="" following="" values="" are="" stored="" at="" the="" indicated="" memory="" addresses="" and="" registers,="" fill="" in="" the="" following="" table="" showing="" the="" values="" for="" the="" indicated="" operands="" in="" hexadecimal:="" address="" value="" register="" value="" instruction="" destination="" value="" 0x1000="" 0xaa="" %rdi="" 0x1000="" addq="" (%rdi),%rsi="" 0x1004="" 0xbb="" %rsi="" 0x1="" andq="" %rsi,%rdi="" 0x1008="" 0xcc="" %rdx="" 0x2="" subq="" %rsi,(%rdi)="" 0x100c="" 0xdd="" -----------="" ---------="" incq="" %rsi="" ----------="" ---------="" -----------="" ---------="" leaq="" 4(%rdi,%rdx,2),%rsi="" cs350="" spring="" 2020="" 3="" test="" 2,="" thur,="" 4/9/2020="" cs350="" spring="" 2020="" 3="" test="" 2,="" thur,="" 4/9/2020="" 3.="" (10="" points)="" using="" the="" jump="" to="" middle="" logic="" used="" for="" a="" while="" loop,="" fill="" in="" the="" c="" code="" for="" the="" assembly="" below.="" again="" use="" the="" reverse="" logic="" discussed="" in="" class.="" (a)c="" code="" long="" loop_while(long="" x,="" long="" y){="" long="" out="_________________;" while="" (________________)="" {="" out="_____________________;" y="_____________________________;" }="" return="" out;="" }="" loop_while:="" movl="" $1,="" %eax="" jmp="" .l2="" .l3:="" movq="" %rdi,="" %rdx="" subq="" %rsi,="" %rdx="" addq="" %rdx,="" %rax="" addq="" $1,="" %rsi="" .l2:="" cmpq="" %rdi,="" %rsi="" jl="" .l3="" rep="" ret="" cs350="" spring="" 2020="" 4="" test="" 2,="" thur,="" 4/9/2020="" cs350="" spring="" 2020="" 4="" test="" 2,="" thur,="" 4/9/2020="" 4.="" (10="" points)="" for="" a="" c="" function="" switcher="" below="" and="" the="" assembly="" code="" along="" with="" a="" jump="" table,="" fill="" in="" the="" missing="" parts="" of="" the="" c="" code.="" (a)c="" code="" long="" switcher="" (long="" x,="" long="" y,="" long="" z){="" long="" w="1;" switch(x)="" {="" case="" 1:="" ________________________="" break;="" case="" 2:="" ________________________="" case="" 3:="" ________________________="" break;="" case="" 4:="" case="" 6:="" ________________________="" break;="" default:="" ________________________="" }="" return="" w;="" }="" (b)="" assembly="" code="" switcher:="" .l3:="" leaq(%rsi,%rdx),="" %rax="" ret="" .l5:="" movq="" %rdi,="" %rax="" subq="" %rsi,="" %rax="" ret="" .l6:="" movq="" %rsi,="" %rax="" imulq="" %rdx,="" %rax="" ret="" .l7:="" movl="" $2,="" %eax="" ret="" (c)jump="" table="" .l4:="" .quad="" .l7="" .quad="" .l3="" .quad="" .l5="" .quad="" .l5="" .quad="" .l6="" .quad="" .l7="" .quad="" .l6="" cs350="" spring="" 2020="" 5="" test="" 2,="" thur,="" 4/9/2020="" cs350="" spring="" 2020="" 5="" test="" 2,="" thur,="" 4/9/2020="" 5.="" (10="" points)="" given="" the="" array="" declarations,="" fill="" in="" the="" following="" table="" describing="" the="" element="" size,="" the="" total="" size,="" and="" the="" address="" of="" element="" i="" for="" each="" of="" these="" arrays.="" array="" declaration="" element="" size="" total="" size="" base="" address="" element="" i="" (a)="" char="" a[3];="" base_a="" (b)="" char="" *b[4];="" base_b="" (c)="" short="" c[5];="" ----------="" base_c="" (d)="" short="" **d[6];="" base_d="" (e)="" int="" e[5];="" base_e="" (f)="" long="" *f[4];="" base_f="" (g)="" double="" *g[3];="" base_g="" cs350="" spring="" 2020="" 6="" test="" 2,="" thur,="" 4/9/2020="" cs350="" spring="" 2020="" 6="" test="" 2,="" thur,="" 4/9/2020="" 6.="" (10="" points)="" fill="" the="" table="" with="" 0's="" and="" 1's="" for="" four="" flags:="" cf="" (carry="" flag),="" sf="" (sign="" flag):="" number="" type="" %rdi/edi/di="" %rsi/esi/si="" instruction="" cf="" sf="" zf="" of="" (a)="" unsigned="" 0xfffe="" 0x4="" addw="" %di,="" %si="" (b)="" signed="" two's="" complement="" 0xfffd="" 0x3="" addw="" %di,="" %si="" (c)="" signed="" two's="" complement="" 0xffffffff="" 0x80000000="" addl="" %edi,="" %esi="" (d)="" signed="" two's="" complement="" -0xffff="" 0xffff="" subl="" %si,="" %di="" (e)="" unsigned="" 0xff="" 0xf="" shlq="" 64,="" %rdi="" cs350="" spring="" 2020="" 7="" test="" 2,="" thur,="" 4/9/2020="" cs350="" spring="" 2020="" 7="" test="" 2,="" thur,="" 4/9/2020="" 7.="" (15="" points)="" suppose="" basex,="" the="" base="" address="" of="" short="" integer="" array="" x="" and="" long="" integer="" index="" j="" are="" stored="" in="" registers="" %rax="" and="" %rbx,="" respectively.="" for="" each="" of="" the="" following="" expressions,="" give="" its="" type,="" a="" for-="" mula="" for="" its="" value="" and="" an="" asembly="" codd="" implementation.="" the="" result="" shoud="" be="" stored="" in="" register="" %rcx="" if="" it="" is="" a="" pointer="" and="" register="" element="" %cx="" if="" it="" has="" data="" type="" short.="" for="" address="" computation,="" use="" lea="" offset(base,index,scale="" factor).="" expression="" type="" value="" assembly="" code="" (a)="" x[2]="" (b)="" x+3="" (c)="" &x[j]="" (d)="" x[4*j+1]="" (e)="" x+j-4="" cs350="" spring="" 2020="" 8="" test="" 2,="" thur,="" 4/9/2020="" cs350="" spring="" 2020="" 8="" test="" 2,="" thur,="" 4/9/2020="" 8.="" (30="" points)="" consider="" the="" c="" as="" well="" as="" disassembled="" code="" below:="" int="" main(int="" argc,char="" **argv)="" {="" long="" x="3,y=9,z=0;" z="top(x,y);" return="" z;="" }="" long="" top(long="" x,long="" y)="" {="" x="x" +="" y;="" return="" leaf(x,y);="" }="" long="" leaf(long="" y,long="" z)="" {="" z="y" -="" z;="" return="" z;="" }="" 1="" 00000000004004d6="">: 2 4004d6:48 89 f8 mov %rdi,%rax 3 4004d9:48 29 f0 sub %rsi,%rax 4 4004dc:c3 retq 5 00000000004004dd : 6 4004dd:48 01 f7 add %rsi,%rdi 7 4004e0:b8 00 00 00 00 mov $0x0,%eax 8 4004e5:e8 ec ff ff ff callq 4004d6 9 4004ea:f3 c3 repz retq 10 00000000004004ec
: 11 4004ec:be 09 00 00 00 mov $0x9,%esi 12 4004f1:bf 03 00 00 00 mov $0x3,%edi 13 4004f6:b8 00 00 00 00 mov $0x0,%eax 14 4004fb:e8 dd ff ff ff callq 4004dd 15 400500:f3 c3 repz retq Fill the table with appropriate values. Line # PC Instruction %rdi %rsi %rax %rsp *%rsp 14 3 9 0 0x7fffffffe820 ------------------- 6 7 8 2 2021-spring-test2.fm CS350 Spring 2021 1 Test 2, Thur, 4/1/2021 CS350 Spring 2021 1 Test 2, Thur, 4/1/2021 1. (5 points) Complete the C function below. Convert shift to a number. Do not use >> or <: unknown:="" movq="" %rsi,="" %rax="" sarq="" $1,="" %rax="" addq="" %rdi,="" %rax="" ret="" long="" unknown(long="" x,="" long="" y)="" {="" return="" ______________________________________;="" }="" 2.="" (10="" points)="" assume="" the="" following="" values="" are="" stored="" at="" the="" indicated="" memory="" addresses="" and="" registers,="" fill="" in="" the="" following="" table="" showing="" the="" values="" for="" the="" indicated="" operands="" in="" hexadecimal.="" you="" do="" not="" need="" to="" write="" 0x.="" instructions="" are="" independent.="" 3.="" (10="" points)="" using="" the="" jump="" to="" middle="" logic,="" fill="" in="" the="" c="" code="" for="" the="" assembly="" below.="" address="" value="" register="" value="" instruction="" destination="" value="" 0x1000="" 0xaa="" %rdi="" 0x1000="" addq="" (%rdi),%rsi="" 0x1004="" 0xbb="" %rsi="" 0x1="" andq="" %rsi,%rdi="" 0x1008="" 0xcc="" %rdx="" 0x2="" subq="" %rsi,(%rdi)="" 0x100c="" 0xdd="" -----------="" ---------="" incq="" %rsi="" ----------="" ---------="" -----------="" ---------="" leaq="" 4(%rdi,%rdx,2),%rsi="" (a)c="" code="" long="" loop_while(long="" x,="" long="" y){="" long="" z="_______(a)__________;" while="" (_______(b)_________)="" {="" z="_________(c)____________;" y="_________(d)____________________;" }="" return="" z;="" }="" loop_while:="" movl="" $0,="" %eax="" jmp="" .l2="" .l3:="" addq="" %rsi,="" %rax="" subq="" $1,="" %rsi="" .l2:="" cmpq="" %rsi,="" %rdi="" jl="" .l3="" rep="" ret="" cs350="" spring="" 2021="" 2="" test="" 2,="" thur,="" 4/1/2021="" cs350="" spring="" 2021="" 2="" test="" 2,="" thur,="" 4/1/2021="" 4.="" (10="" points)="" fill="" in="" the="" missing="" parts="" of="" the="" c="" code="" for="" the="" assembly="" and="" jump="" table="" shown="" below.="" 5.="" (10="" points)="" given="" the="" array="" declarations,="" fill="" in="" the="" following="" table="" describing="" the="" element="" size="" in="" bytes,="" the="" total="" size="" in="" bytes,="" and="" the="" address="" of="" element="" i="" for="" each="" of="" these="" arrays="" using="" the="" base="" addresses="" given="" in="" the="" “base="" address”="" column.="" array="" declaration="" element="" size="" total="" size="" base="" address="" address="" of="" element="" i="" char="" a[3];="" base_a="" char="" *b[4];="" base_b="" short="" c[5];="" base_c="" short="" **d[6];="" base_d="" int="" e[5];="" base_e="" long="" *f[4];="" base_f="" double="" *g[3];="" base_g="" c="" code="" long="" switcher="" (long="" x,="" long="" y,="" long="" z){="" long="" w="1;" switch(x)="" {="" case="" 1:="" _________(a)____________="" break;="" case="" 2:="" _________(b)____________="" case="" 3:="" _________(c)____________="" break;="" case="" 4:="" case="" 6:="" _________(d)____________="" break;="" default:="" _________(e)____________="" }="" return="" w;="" }="" assembly="" code="" switcher:="" .l3:="" leaq(%rsi,%rdx),="" %rax="" ret="" .l5:="" movq="" %rdi,="" %rax="" subq="" %rsi,="" %rax="" ret="" .l6:="" movq="" %rsi,="" %rax="" imulq="" %rdx,="" %rax="" ret="" .l7:="" movl="" $2,="" %eax="" ret="" jump="" table="" .l4:="" .quad="" .l7="" .quad="" .l3="" .quad="" .l5="" .quad="" .l5="" .quad="" .l6="" .quad="" .l7="" .quad="" .l6="" cs350="" spring="" 2021="" 3="" test="" 2,="" thur,="" 4/1/2021="" cs350="" spring="" 2021="" 3="" test="" 2,="" thur,="" 4/1/2021="" 6.="" (10="" points)="" fill="" the="" table="" with="" 0's="" and="" 1's="" for="" four="" flags:="" cf="" (carry="" flag),="" sf="" (sign="" flag).="" write="" n/a="" if="" either="" the="" instruction="" or="" values="" do="" not="" conform="" to="" the="" at&t="" (linux)="" assembly:="" 7.="" (15="" points)="" suppose="" basex,="" the="" base="" address="" of="" short="" integer="" array="" x="" and="" long="" integer="" index="" j="" are="" stored="" in="" registers="" %rax="" and="" %rbx,="" respectively.="" for="" each="" of="" the="" following="" expressions,="" give="" its="" type,="" a="" for-="" mula="" for="" its="" value="" and="" an="" asembly="" code="" implementation.="" the="" result="" shoud="" be="" stored="" in="" register="" %rcx="" if="" it="" is="" a="" pointer="" and="" register="" element="" %cx="" if="" it="" has="" data="" type="" short.="" for="" address="" computation,="" use="" leax="" offset(base,index,scale="" factor),="" where="" x="" needs="" to="" be="" replaced="" with="" an="" appropri-="" ate="" char.="" number="" type="" %rdi/edi/di="" %rsi/esi/si="" instruction="" cf="" sf="" zf="" of="" unsigned="" 0xfffe="" 0x4="" addw="" %di,="" %si="" signed="" two's="" complement="" 0xfffd="" 0x3="" addw="" %di,="" %si="" signed="" two's="" complement="" 0xffffffff="" 0x80000000="" addl="" %edi,="" %esi="" signed="" two's="" complement="" -0xffff="" 0xffff="" subl="" %si,="" %di="" unsigned="" 0xff="" 0xf="" shlq="" 64,="" %rdi="" expression="" type="" value="" assembly="" code="" x[2]="" x+3="" &x[j]="" x[4*j+1]="" x+j-4="" cs350="" spring="" 2021="" 4="" test="" 2,="" thur,="" 4/1/2021="" cs350="" spring="" 2021="" 4="" test="" 2,="" thur,="" 4/1/2021="" 8.="" (30="" points)="" consider="" the="" c="" as="" well="" as="" disassembled="" code="" below:="" int="" main(int="" argc,char="" **argv)="" {="" long="" x="3,y=9,z=0;" z="top(x,y);" return="" z;="" }="" long="" top(long="" x,long="" y)="" {="" x="x" +="" y;="" return="" leaf(x,y);="" }="" long="" leaf(long="" y,long="" z)="" {="" z="y" -="" z;="" return="" z;="" }="" 1="" 00000000004004d6="">: 2 4004d6:48 89 f8 mov %rdi,%rax 3 4004d9:48 29 f0 sub %rsi,%rax 4 4004dc:c3 retq 5 00000000004004dd : 6 4004dd:48 01 f7 add %rsi,%rdi 7 4004e0:b8 00 00 00 00 mov
Answered 2 days AfterMar 21, 2023

Answer To: test2-v1.fmCS350 Spring XXXXXXXXXXTest 2, Thur, 4/9/2020CS350 Spring XXXXXXXXXXTest 2, Thur,...

Baljit answered on Mar 23 2023
29 Votes
1.
%rdi is for argument z and %rsi is for arguments x.
1. movl command move bit pattern of -1 in
to eax accummumlator .In C it is same as initialization of y=-1;
2. now jump .l2 will jump to the .l2 block in which it will compare the values in register rsi and rdi that same as x and z in C language.
3. jg command is jump to l3 block if value in rsi is greater than value in rdi otherwise return. In C it is x>z.
4. subq %rdi,%rax will subtract the value of rdi from rax and than save it into rax .In c it is equal to y=y-z.
5. addq $2,%rsi means and 2 to value in rsi and store it in rsi. C equivalent is x=x+2
So code is
(a)C code
long loop_while(long z, long x)
{
long y = -1;
while (x>z)
{
y =y-z;
x =x+2;
}
return y;
}
2.
    Array declaration
    Element size
(In byte)
    Total size
    Base address
    Address of element k
    char d[2];
    1
    2*1=2
    base_d
    base_d +1*k
    char *e[4];
    8
    4*8=32
    base_e
    base_e+8*k
    short...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here