Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 2 next 710 APPENDIX B. SOLUTIONS TO PRACTICE PROBLEMS C. As always, we start by annotating the assembly code: 1 2 3 4 5 6 movl movl movl leal movl movl 8(%ebp),%eax 8(%eax),%edx %edx,4(%eax) 4(%eax),%edx %edx,(%eax) %eax,12(%eax) Get sp Get sp->s.y Copy to sp->s.x Get &(sp->s.x) Copy to sp->p sp->next = p From this, we can generate C code as follows: void sp_init(struct prob *sp) { sp->s.x = sp->s.y; sp->p = &(sp->s.x); sp->next = sp; } Problem 3.22 Solution: [Pg. 159] This is a very tricky problem. It raises the need for puzzle-solving skills as part of reverse engineering to new heights. It shows very clearly that unions are simply a way to associate multiple names (and types) with a single storage location. A. The layout of the union is as follows. As the figure illustrate, the union can have either its “e1” interpretation, having fields e1.p and e1.y, or it can have its “e2” interpretation, having fields e2.x and e2.next. Offset Contents 0 e1.p e2.x 4 e1.y e2.next B. 8 bytes C. As alwa...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online