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, %rax
imulq $0x134, %rdi, %rdi
leaq 0x0(,%rsi,8), %rdx
subq %rsi, %rdx
leaq (%rdi,%rdx,4), %rdx
addq %rax, %rdx
salq $0x4, %rdx
movq %rcx, A(%rdx)
movq %r8, A+0x8(%rdx)
movl $0x33bc0, %eax
ret
How would i solve this problem? I am pretty sure that the size of array is 13244 and the size of the struct is 16. I am to solve for b,c,and d
There are many possible combination but according to me this should be the b c and d, and 13244 shoud be 13248 because size should be in multiple of 4.
b= 3 c= 12 d= 23
3*12*23 = 828 * 16 = 13248
#define b 3
#define c 12
#define d 23
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);}
assembly:
store_ele:
.LFB0:
.cfi_startproc
movslq %esi, %rsi
movslq %edi, %rdi
movslq %edx, %rax
imulq $276, %rdi, %rdi
leaq (%rsi,%rsi,2), %rdx
salq $3, %rdx
subq %rsi, %rdx
addq %rdi, %rdx
addq %rax, %rdx
leaq A(%rip), %rax
salq $4, %rdx
addq %rax, %rdx
movl $13248, %eax
movq %rcx, (%rdx)
movq %r8, 8(%rdx)
ret
Consider the following source code, where b, c, and d are constants declared with #define. You...
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...
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 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 { 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 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]; 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:...
Binary Bomb phase 4 Dump of assembler code for function phase_4: > 0x0000000000400fe7 <+0>: sub $0x18,%rsp 0x0000000000400feb <+4>: lea 0x8(%rsp),%rcx 0x0000000000400ff0 <+9>: lea 0xc(%rsp),%rdx 0x0000000000400ff5 <+14>: mov $0x40290d,%esi 0x0000000000400ffa <+19>: mov $0x0,%eax 0x0000000000400fff <+24>: callq 0x400c00 <__isoc99_sscanf@plt> 0x0000000000401004 <+29>: cmp $0x2,%eax 0x0000000000401007 <+32>: jne 0x401010 <phase_4+41> 0x0000000000401009 <+34>: cmpl $0xe,0xc(%rsp) 0x000000000040100e <+39>: jbe 0x401015 <phase_4+46> 0x0000000000401010 <+41>: callq 0x401662 <explode_bomb> 0x0000000000401015 <+46>: mov $0xe,%edx 0x000000000040101a <+51>: mov $0x0,%esi...
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...