Question

Problem 2 Consider the following source code, where R, S, and T are constants declared with #define. long int AIRISJIT int store_ele(int h, int i, int j, long int dest) Alh][i]01-.dest; return sizeof(A) In compiling this program, GCC generates the following assembly code (with-02) store_ ele: movslq %esi, %rsi movslq %edi, %rdi movq (%rcx), %rax leaq (%rdi,%rdi,4), %rdi leaq (%rsi,%rsi,4), %rcx movslq %edx, %rdx addq %rcx, %rdx movq %rax, A( %rdx,8) movl $1120, %eax ret Create a text file to show your work and the steps required to determine, R, S, and T Use your reverse engineering skills to determine the values of R, S, and T, based upon the assembly code Be sure to show all the calculations required to determine R, S, and T. (15 points each for R. S. T, 15 points for steps/calculations)
0 0
Add a comment Improve this question Transcribed image text
Answer #1

For an array declared as Type DIRI[C], array element DO) is at address where L is the size of the data type in bytes. A. It fmovl 12(%ebp), %edx #moves j to %edx leal (%edx, %edx, 4), %eax #multiplies %edx times 5, stores in %eax leal (%edx, %eax, 2)xd = A L=4 (R(9% + j) + k) R=11 s=9 (99x + 11j + k) = (11(9x + j) + k) Since it returns 1980 as sizeof, we know the size of t

Add a comment
Know the answer?
Add Answer to:
Problem 2 Consider the following source code, where R, S, and T are constants declared with...
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
  • Consider the following source code, where b, c, and d are constants declared with #define. You...

    Consider the following source code, where b, c, and d are constants declared with #define. You will need to determine the values for b, c, and d. struct lnode { char *str; struct lnode *next; } struct lnode A[b][c][d]; int store_ele(int h, int i, int j, struct lnode dest) { A[h][i][j] = dest; return sizeof(A);} On compiling this program (with -O2), GCC generates the following assembly code for the store_ele function: store_ele: movslq %edi, %rdi movslq %esi, %rsi movslq %edx,...

  • Write the C Code for the Intel assembley below. Note: Don't copy and paste anything from...

    Write the C Code for the Intel assembley below. Note: Don't copy and paste anything from github because it won't be the right answer. .file "mystery.c" .comm num,1600,32 .text .globl add .type add, @function add: .LFB2: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 movq %rdi, -8(%rbp) movq %rsi, -16(%rbp) movq -16(%rbp), %rax movq -8(%rbp), %rdx addq %rdx, %rax popq %rbp .cfi_def_cfa 7, 8 ret .cfi_endproc .LFE2: .size add, .-add .globl dothething .type dothething, @function...

  • You know the following assembly code snippet is from a recursive function in C. You also...

    You know the following assembly code snippet is from a recursive function in C. You also know that the stack contents at a particular point in time when we are in the recursive function are shown on the next page. Answer the following questions: a) how many Foo stack frames are on the stack? b) what is the return address back to the function that called Foo for the first time? c) what is the return address back into the...

  • In the following code, A and B are constants defined with #define: 1 typedef struct {...

    In the following code, A and B are constants defined with #define: 1 typedef struct { 2 int x[A][B]; /* Unknown constants A and B */ 3 long y; 4 } str1; 5 6 typedef struct { 7 char array[B]; 8 int t; 9 short s[A]; 10 long u; 11 } str2; 12 13 void setVal(str1 *p, str2 *q) { 14 long v1 = q-<t; 15 long v2 = q-<u; 16 p-<y = v1+v2; 17 } gcc generates the following...

  • WHAT is the value of A,B, and C Consider the following code fragment where the right-hand...

    WHAT is the value of A,B, and C Consider the following code fragment where the right-hand side of the assignments in func are to be completed by answering this question: typedef struct point { float *p; struct { float x; float y; }s; struct point* next; } point; void func(point *sp1, point* sp2) { sp2->p = A; sp2->S.X = B; sp2->s.y = c; int maino { point *init, *final; // assume init has been initialized to some value; func(init, final);...

  • The following problem concerns the following, low-quality code: void foo(int x) { int a[3]; char buf[1];...

    The following problem concerns the following, low-quality code: void foo(int x) { int a[3]; char buf[1]; a[1] = x; a[2] = 0xA0B1C2D3; gets(buf); printf("a[0] = 0x%x, a[2] = 0x%x, buf = %s\n", a[0], a[2], buf); } In a program containing this code, procedure foo has the following disassembled form on an x86/64 machine: 000000000040057d <foo>: 40057d: push %rbp 40057e: mov %rsp,%rbp 400581: sub $0x30,%rsp 400585: mov %edi,-0x24(%rbp) 400588: mov -0x24(%rbp),%eax 40058b: mov %eax,-0xc(%rbp) 40058e: movl $0xa0b1c2d3,-0x8(%rbp) 400595: lea -0x11(%rbp),%rax 400599:...

  • a) Write the following C function in Assembly. You must follow the System V 64-bit calling convention and use AT&T S...

    a) Write the following C function in Assembly. You must follow the System V 64-bit calling convention and use AT&T Syntax notation. Note: You cannot change the algorithm in any way so your assembly function must still be recursive. (20 points) long Catalan(long n) { long sum = 0; if (n == 0) return 1; for (int i = 0; i < n; i++) { sum += Catalan(i) * Catalan(n - i - 1); } return sum; } b) The...

  • Consider the following assembly code. 1. 1, LOAD R, #1 2, LOADS, #1 3, LOAD T, #(k-3) 4. ADD AC, R, S 5. LOAD R, S 6. LOAD S, AC 8. BRP 4, T 9. STOR AC, M where R, S, T, AC are is addressing and...

    Consider the following assembly code. 1. 1, LOAD R, #1 2, LOADS, #1 3, LOAD T, #(k-3) 4. ADD AC, R, S 5. LOAD R, S 6. LOAD S, AC 8. BRP 4, T 9. STOR AC, M where R, S, T, AC are is addressing and BRP stands for "branch if positive". sters, M is a memory location, # indicates immediate (a) Explain what this code computes (assuming that k is a natural number greater than two). (6 marks)...

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