Difference between revisions of "CSC231 Exercises On Functions"
Line 38: | Line 38: | ||
<br /> | <br /> | ||
− | =Exercise | + | =Exercise 4= |
What is the behavior of this loop? | What is the behavior of this loop? | ||
Line 65: | Line 65: | ||
|} | |} | ||
− | =Exercise | + | =Exercise 5= |
What is the behavior of the loop below? Could it ever be endless? | What is the behavior of the loop below? Could it ever be endless? | ||
{| | {| | ||
Line 93: | Line 93: | ||
|} | |} | ||
− | =Exercise | + | =Exercise 6= |
What is the behavior of this program? Draw the stack as the processor executes this program: | What is the behavior of this program? Draw the stack as the processor executes this program: | ||
{| | {| | ||
Line 123: | Line 123: | ||
|} | |} | ||
− | =Exercise | + | =Exercise 7= |
Same question, but now observe that the programmer forgot the '''ret''' instruction at the end of the first function. | Same question, but now observe that the programmer forgot the '''ret''' instruction at the end of the first function. | ||
{| | {| | ||
Line 152: | Line 152: | ||
|} | |} | ||
− | =Exercise | + | =Exercise 8 (Push and Pop)= |
What are the numbers stored in eax and ebx when the loop terminates? If we assume that the default stack is 2 KB long, what is the largest number of times the loop can iterate before the stack overflows (trick question :-)? | What are the numbers stored in eax and ebx when the loop terminates? If we assume that the default stack is 2 KB long, what is the largest number of times the loop can iterate before the stack overflows (trick question :-)? | ||
{| | {| | ||
Line 183: | Line 183: | ||
|} | |} | ||
− | =Exercise | + | =Exercise 9= |
Same question, but now observe that we pop eax, not ebx... | Same question, but now observe that we pop eax, not ebx... | ||
{| | {| | ||
Line 214: | Line 214: | ||
|} | |} | ||
− | =Exercise | + | =Exercise 10= |
What do these 2 code sections do? | What do these 2 code sections do? |
Revision as of 14:53, 26 October 2012
Back to Weekly Schedule.
Note: Highlight the white section on the right hand-side of each code section to see the solution.
Contents
Exercise 1
- Write a program that prints all the letters of the alphabet in a loop. Do not use a function. Use ecx and loop to control the looping. Make your program print 1 letter in each loop.
- use int 0x80 to print the character (which you'll store in a string).
Exercise 2
- Same exercise, but this time use a function that receives the character to be printed in al.
- Explore ways to save ecx in a temporary variable
- Explore alternative ways using the push and pop operations
Exercise 3
- What is the behavior of the stack, and the resulting values in the registers as this program is executing:
mov eax, 0x01234567
mov ebx, 0x89ABCDEF
xor ecx, ecx
push ax
pop cx
push ax
push bx
pop ecx
call next
next: pop ecx
Exercise 4
What is the behavior of this loop?
|
|
Exercise 5
What is the behavior of the loop below? Could it ever be endless?
|
|
Exercise 6
What is the behavior of this program? Draw the stack as the processor executes this program:
|
|
Exercise 7
Same question, but now observe that the programmer forgot the ret instruction at the end of the first function.
|
|
Exercise 8 (Push and Pop)
What are the numbers stored in eax and ebx when the loop terminates? If we assume that the default stack is 2 KB long, what is the largest number of times the loop can iterate before the stack overflows (trick question :-)?
|
|
Exercise 9
Same question, but now observe that we pop eax, not ebx...
|
|
Exercise 10
What do these 2 code sections do?
and
|
|