| CompOrg Spring 2005 Test #2 Topics |
|   CompOrg Home | Topics | Study Guide |
| Topic | What to know | What to expect on the test |
|---|---|---|
| IA32 Instructions |
movl instructionleal instruction |
|
| IA32 Assembly Language Subroutines |
|
|
| The Stack |
|
printf("%d\n",4);.
pop %ebp
ret
That is, that both %ebp and %esp will get bad values...
|
| Logic Design |
|
|
Practice Problem 3.3 (know leal!)
Practice Problem 3.24 (Buffer Overflow)
Problem 3.31 (Assembly to C)
Problem 3.36 (Assembly to C)
Look over the labs and HWs!
Write the following function in IA32 assembly language:
int factorial(int x) {
if (x==1) return 1;
else return(x * factorial(x-1));
}
Consider the following C function and corresponding IA32 assembly:
int namelength(char *name) {
char buff[4];
strcpy(buff,name);
return(strlen(buff));
}
|
namelength:
pushl %ebp
movl %esp, %ebp
subl $16, %esp
pushl 8(%ebp)
leal -4(%ebp), %eax
pushl %eax
call strcpy
addl $16, %esp
leal -4(%ebp), %eax
subl $12, %esp
pushl %eax
call strlen
addl $16, %esp
leave
ret
|
name points to the string "abcdefghijklmnop",
what is the address of the instruction the function tries to return
to?.
leave
instruction has executed?name points to the string "abcdef", what
will the return value be?Below is the C code and corresponding assembly code for a function that deals with 2-dimensional arrays (we did this one in class):
int arr[R][C];
int arr1[C][R];
int foo(int x, int y) {
int i;
i = arr[x][y];
i += arr1[x][y];
return(i);
}
|
foo:
pushl %ebp
movl %esp, %ebp
subl $4, %esp
movl 8(%ebp), %edx
movl %edx, %eax
sall $3, %eax
subl %edx, %eax
addl 12(%ebp), %eax
movl arr(,%eax,4), %eax
movl %eax, -4(%ebp)
movl 8(%ebp), %eax
sall $2, %eax
addl 12(%ebp), %eax
movl arr1(,%eax,4), %edx
leal -4(%ebp), %eax
addl %edx, (%eax)
movl -4(%ebp), %eax
leave
ret
|
What is the value of R?
What is the value of C?
answers: R is 4 and C is 7