oct 7
textbook homework
3.10, pg 182, 311
xor %edx, %edx
3.16, pg 195, 314
/* a at %ebp+8, p at $ebp+12 */
movl 8(%ebp), %edx
movl 12(%edp), %eax
testl %eax, %eax
je .L3
testl %edx, %edx
jle .L3
addl %edx, (%eax)
.L3:
Discuss (test, je) sequence.
3.22, pg 202, 318
loop { val ^= x; x >>= 1 } return val & 1
/* x at %ebp +8 */
movl 8(%ebp), %edx
movl $0, %eax
testl %edx, %edx
je .L7
.L10:
xorl %edx, %eax
shrl %edx
jne .L10
.L7
andl $1, %eax
C code? In english?
addresses and malloc
Look at this example: run it, disass it, draw picture of various code/memory/stack locations.
/*
* Look at some memory locations.
*
*/
#include <stdio.h>
#include <stdlib.h>
int global_int = 100;
typedef int* integer10;
int twice(int x){
int y = x;
int z = 2*x;
printf(" twice: address of local y is 0x%p \n", &y);
return z;
}
integer10 new_integer10(){
integer10 result = (integer10) malloc(10*sizeof(int));
printf(" new_integer10: address of malloc'ed result is 0x%p \n", result);
return result;
}
int main(int argc, char* argv[]){
char* string1 = "This is a string.";
int x = 10;
int y;
integer10 array;
printf("--- looking at some memory locations ---\n");
printf(" main: address of initialized string1 is 0x%p\n", string1);
printf(" main: address of local x is 0x%p\n", &x);
printf(" main: address of global_int is 0x%p\n", &global_int);
y = twice(x);
array = new_integer10();
printf("--- done ---\n");
}
back to small.c
- from previous notes
- continue working through x86 stack and variable manipulations ==