Difference between revisions of "CSC231 Exercises On Functions"
Line 1: | Line 1: | ||
[[CSC231_Class_Page | Back]] to Weekly Schedule. | [[CSC231_Class_Page | Back]] to Weekly Schedule. | ||
---- | ---- | ||
+ | Note: For some exercises, highlight the white section on the right hand-side of each code section to see the solution. | ||
[[Image:pushPop.jpg| right]] | [[Image:pushPop.jpg| right]] | ||
− | + | ||
=Exercise 1= | =Exercise 1= | ||
Revision as of 15:04, 26 October 2012
Back to Weekly Schedule.
Note: For some exercises, 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
|
|