COMP 280 Study Guide - Quiz Guide: Buffer Overflow, C String Handling, Assembly Language

55 views3 pages

Document Summary

4i: convert between a c assignment statement involving a pointer/array and the equivalent x86-64 instruction. // array element a[i][j] can be copied to register %eax below. C code: int *arr = malloc(20); x86-64: C code int arr[5]; arr[3] = 7; int arr[5]; for(long i = 0; i < 5; ++i) Arr[i] = 42; int *arr = malloc(20); for(long i = 0; i < 5; ++i) *(arr + 3) = 7; x86-64 subq shx14, %rsp movq %rsp, %rdx movl shx7, 0xc(%rdx) #12 + %rdx bc starts at arr[0]arr[3] subq shx14, %rsp . (%rdx, %rcx, 0x4) incq %rcx movq , %rdi call malloc . 2. trace x86-64 assembly code that involves accessing a 2d array. C code int a = 0; while(a <5) 1. trace and write x86-64 assembly code that includes allocating space for structs and accessing them. Movl , 0x14(%rbx) id last_name first_name last_name id first_name. **make sure the size of struct is a multiple of the biggest data type.