Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question is clear Problem 3: Consider the following assembly code for a function with a switch: foo: .LFBO: movl fedi, %eax cmpb $4, &dil ja

image text in transcribed

image text in transcribed

Question is clear

Problem 3: Consider the following assembly code for a function with a switch: foo: .LFBO: movl fedi, %eax cmpb $4, &dil ja .L9 movzbl %dil, %ecx leaq .L4 (%rip), prsi movsla (%rsi, %rcx, 4), %rdx addq %rsi, rdx notrack jmp *%rdx 2 .L4: .long .long .long .long .long .text .L8-.L4 .L7-.L4 .L10-.L4 L6-.L4 .L3-L4 .L8: leal subl jmp 0 (,&rdi, 8), feax fedi, feax .L2 .L7: leal leal jmp (%rdi, %rdi,4), fedx (%rdi, %rdx, 2), seax . L2 .L10: movl $99, %eax .L6: addl $1, %eax .L2: fal, %eax movsbl ret .L3: leal sall (%rdi, %rdi, 2), %eax $2, %eax . L2 jmp .L9: 3 movl $0, feax .L2 jmp Page 3 of 9 Based on the assembly code above, fill in the blanks below in its corresponding C source code. int foo (char c) { switch (c) { case 0: 3 case 1: case 2: case 3: case 4: default: } return Problem 5: Consider the following Ccode. #include #include #define SMALL_BUFFER_SIZE 10 #define MEDIUM_BUFFER_SIZE 20 #define LARGE_RUPPER SIZE 100 jmp_buf jmpbuf; in e_array( LARGE_BUFFER_SIZE); ant copy array(int: arc, int dat, int range) int i; for (1-0) 1 c range; 1++ dat (1) - Bret); return; > void fool (int input) + int local_arrayISMALL_BUFFER_SIZE); if (copy_array(input, local_array, SMALL HOPPER_SIX)) longing (mpbuf, 1); > /... LOCATION 3 ***/ void too2 (int input) int local_arrayISMALL_BUFFER_SIZE: copy_array (input, local array, SMALL BUFFER SIZE); fool (input + 10); printf("Return to foo2 "); void bar (int input) int status - setjmp (jmpbu); if(status -- O) printf("Return to bar normally "); ! 1 else printf("Return to bar due to ID "); /***** LOCATION 2 *******/ > main) 4. bar (c_array); /****. LOCATION 1 *.. return; Page 7 of 9 Here is the assembly code for some of the procedures. fool : suba $56, frap movi $10, Sedx mova trP, Wrai call copy_array teat Seax, Seax .L4 mov! $1, Sesi movi jmpbut, Sedl call long jmp 14: adda $56, Wrap ret - LCD: atring "Return to foo2" f0o21 IF013: pusha Erby suba $48, Wrap trdi, rbx movl $ 10, Sedx mova Prep. rst call copy_array leaq 40 rbx), Brdi call fool ! $.LCO, Bedi call puts adda $48, Trap popa Brbx ret Ic; string "Return to bar normally" LC2: string "Return to bar due to error bart suba $8, frap movl $jmpbuf, tedi call _setjmp test- teax Beax jne .L13 $.Lci, Bedi call puts imp .L9 .113: mout $. 102, Xedi call puta 19: addq $8, Srep ret Page 8 of 9 1. If the line /****+ LOCATION 1 *******/ is replaced with foo2(c_array), what is the outcome of the program? 2. If the line /**** LOCATION 2 ***--*/ is replaced with foo2 array). what is the outcome of the program? 3. If the line /***** LOCATION I *******/ is replaced with fool (c_array) and SMALL_BUFFER_SIZE is replaced with MEDIUM_BUFFER_SIZE in LOCATION 3, what is the outcome of the program? 4. If the line / LOCATION 1.***.../ is replaced with foo2(c_array) and SMALL_BUFFER_SIZE 1s replaced with LARGE_BUFFER_SIZE in LOCATION 3, what 19 Lhe outcome of the program? Problem 3: Consider the following assembly code for a function with a switch: foo: .LFBO: movl fedi, %eax cmpb $4, &dil ja .L9 movzbl %dil, %ecx leaq .L4 (%rip), prsi movsla (%rsi, %rcx, 4), %rdx addq %rsi, rdx notrack jmp *%rdx 2 .L4: .long .long .long .long .long .text .L8-.L4 .L7-.L4 .L10-.L4 L6-.L4 .L3-L4 .L8: leal subl jmp 0 (,&rdi, 8), feax fedi, feax .L2 .L7: leal leal jmp (%rdi, %rdi,4), fedx (%rdi, %rdx, 2), seax . L2 .L10: movl $99, %eax .L6: addl $1, %eax .L2: fal, %eax movsbl ret .L3: leal sall (%rdi, %rdi, 2), %eax $2, %eax . L2 jmp .L9: 3 movl $0, feax .L2 jmp Page 3 of 9 Based on the assembly code above, fill in the blanks below in its corresponding C source code. int foo (char c) { switch (c) { case 0: 3 case 1: case 2: case 3: case 4: default: } return Problem 5: Consider the following Ccode. #include #include #define SMALL_BUFFER_SIZE 10 #define MEDIUM_BUFFER_SIZE 20 #define LARGE_RUPPER SIZE 100 jmp_buf jmpbuf; in e_array( LARGE_BUFFER_SIZE); ant copy array(int: arc, int dat, int range) int i; for (1-0) 1 c range; 1++ dat (1) - Bret); return; > void fool (int input) + int local_arrayISMALL_BUFFER_SIZE); if (copy_array(input, local_array, SMALL HOPPER_SIX)) longing (mpbuf, 1); > /... LOCATION 3 ***/ void too2 (int input) int local_arrayISMALL_BUFFER_SIZE: copy_array (input, local array, SMALL BUFFER SIZE); fool (input + 10); printf("Return to foo2 "); void bar (int input) int status - setjmp (jmpbu); if(status -- O) printf("Return to bar normally "); ! 1 else printf("Return to bar due to ID "); /***** LOCATION 2 *******/ > main) 4. bar (c_array); /****. LOCATION 1 *.. return; Page 7 of 9 Here is the assembly code for some of the procedures. fool : suba $56, frap movi $10, Sedx mova trP, Wrai call copy_array teat Seax, Seax .L4 mov! $1, Sesi movi jmpbut, Sedl call long jmp 14: adda $56, Wrap ret - LCD: atring "Return to foo2" f0o21 IF013: pusha Erby suba $48, Wrap trdi, rbx movl $ 10, Sedx mova Prep. rst call copy_array leaq 40 rbx), Brdi call fool ! $.LCO, Bedi call puts adda $48, Trap popa Brbx ret Ic; string "Return to bar normally" LC2: string "Return to bar due to error bart suba $8, frap movl $jmpbuf, tedi call _setjmp test- teax Beax jne .L13 $.Lci, Bedi call puts imp .L9 .113: mout $. 102, Xedi call puta 19: addq $8, Srep ret Page 8 of 9 1. If the line /****+ LOCATION 1 *******/ is replaced with foo2(c_array), what is the outcome of the program? 2. If the line /**** LOCATION 2 ***--*/ is replaced with foo2 array). what is the outcome of the program? 3. If the line /***** LOCATION I *******/ is replaced with fool (c_array) and SMALL_BUFFER_SIZE is replaced with MEDIUM_BUFFER_SIZE in LOCATION 3, what is the outcome of the program? 4. If the line / LOCATION 1.***.../ is replaced with foo2(c_array) and SMALL_BUFFER_SIZE 1s replaced with LARGE_BUFFER_SIZE in LOCATION 3, what 19 Lhe outcome of the program

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Relational Database And SQL

Authors: Lucy Scott

3rd Edition

1087899699, 978-1087899695

More Books

Students also viewed these Databases questions

Question

What are the main differences between rigid and flexible pavements?

Answered: 1 week ago

Question

What is the purpose of a retaining wall, and how is it designed?

Answered: 1 week ago

Question

How do you determine the load-bearing capacity of a soil?

Answered: 1 week ago

Question

what is Edward Lemieux effect / Anomeric effect ?

Answered: 1 week ago