Difference between revisions of "CSC231 Homework 8 Fall 2012"
(→Problem 3: Optional and Extra Credits (0.7 points)) |
(→Requirements) |
||
(One intermediate revision by the same user not shown) | |||
Line 58: | Line 58: | ||
* You should have one function that prints a 16-bit word in hex. This function will call the function that prints a byte twice. | * You should have one function that prints a 16-bit word in hex. This function will call the function that prints a byte twice. | ||
* You should have one function that prints a string (e.g. "eax = ", or "ebx = "). You will pass the address of the string to print in ecx and the number of chars to print in edx. | * You should have one function that prints a string (e.g. "eax = ", or "ebx = "). You will pass the address of the string to print in ecx and the number of chars to print in edx. | ||
− | * The dumpReg function does all the work necessary, calling various functions, to print the box and the | + | * The dumpReg function does all the work necessary, calling various functions, to print the box and the 6 registers and their contents. |
* The dumpReg function does not modify any of the main registers, nor does it change the ESP or EBP registers. It may use them for its own purpose, but it will restore them to their original values. | * The dumpReg function does not modify any of the main registers, nor does it change the ESP or EBP registers. It may use them for its own purpose, but it will restore them to their original values. | ||
* You need to make sure the '''dumpRegs''' function works correctly. For this you will initialize the registers as follows before calling the function, and you will call the function twice. | * You need to make sure the '''dumpRegs''' function works correctly. For this you will initialize the registers as follows before calling the function, and you will call the function twice. | ||
Line 140: | Line 140: | ||
Your program will output the pascal triangle in '''hexadecimal'''. Use your own functions (or pick code from the posted solutions if you wish). | Your program will output the pascal triangle in '''hexadecimal'''. Use your own functions (or pick code from the posted solutions if you wish). | ||
+ | |||
+ | Your program should not use driver.c but use '''int 0x80''' to print hex characters. | ||
==Submission== | ==Submission== |
Latest revision as of 14:09, 5 November 2012
--D. Thiebaut 13:14, 31 October 2012 (EDT)
Contents
Problem 1 (2 points)
- Write an assembly file called hw8a.asm that will contain a series of functions (you have some flexibility) that help print the contents of all the registers on the screen. The main function will be called dumpRegs and when you call it, all the major registers ( eax, ebx, ecx, edx, edi and esi) will be displayed in hex on the screen, inside a nice box. Here is an example of how your function could get used in a simple hello program:
section .data
Hello db "Hello there!", 10, 10, 10
HelloLen equ $-Hello
section .text
global _start
_start:
;;; print message
mov eax, 4 ; write
mov ebx, 1 ; stdout
call dumpRegs
mov ecx, Hello ; address of message to print
mov edx, HelloLen ; # of chars to print
int 0x80
;;; exit
mov ebx, 0
mov eax, 1
int 0x80
The output of the program will be (something like) this:
+------------------+ | eax = 0000 00 04 | | ebx = 0000 00 01 | | ecx = F503 21 11 | | edx = 0000 12 FC | | edi = FFFF EEC3 | | esi = 1223 5557 | +------------------+ Hello there!
Requirements
- You cannot use the driver.c program. Use int 0x80 to print information.
- You should have one function for printing the line that is used for the top and bottom of the box
- You should have one function that prints a hexadecimal digit.
- You should have one function that prints a byte in hex. This function will call the function that prints a digit twice.
- You should have one function that prints a 16-bit word in hex. This function will call the function that prints a byte twice.
- You should have one function that prints a string (e.g. "eax = ", or "ebx = "). You will pass the address of the string to print in ecx and the number of chars to print in edx.
- The dumpReg function does all the work necessary, calling various functions, to print the box and the 6 registers and their contents.
- The dumpReg function does not modify any of the main registers, nor does it change the ESP or EBP registers. It may use them for its own purpose, but it will restore them to their original values.
- You need to make sure the dumpRegs function works correctly. For this you will initialize the registers as follows before calling the function, and you will call the function twice.
mov eax, 0x12345678 mov ebx, 0x11112222 mov ecx, 0x5555AAAA mov edx, 0x66669999 mov edi, 0x89abcdef mov esi, 0x11111111 call dumpRegs call dumpRegs
- The output should be exactly as follows:
+------------------+ | eax = 1234 56 78 | | ebx = 1111 22 22 | | ecx = 5555 AA AA | | edx = 6666 99 99 | | edi = 89AB CDEF | | esi = 1111 1111 | +------------------+ +------------------+ | eax = 1234 56 78 | | ebx = 1111 22 22 | | ecx = 5555 AA AA | | edx = 6666 99 99 | | edi = 89AB CDEF | | esi = 1111 1111 | +------------------+
Submission
Submit your program as follows:
rsubmit hw8 hw8a.asm
Grading
Points will be taken off significantly if the contents of the registers printed on the screen are not correct, i.e. if the dumpRegs function or any of the functions it calls changes what's inside the registers.
Option
You can print the registers in a horizontal box if you prefer:
+-----------------------------------------------------------------------------------------------------------+ | eax = 1234 56 78 ebx = 1111 22 22 ecx = 5555 AA AA edx = 6666 99 99 edi = 89AB CDEF esi = 1111 1111 | +-----------------------------------------------------------------------------------------------------------+
Problem 2 (2 points)
- Recode the Pascal Triangle program, but this time use several functions. The main program should look like this:
_start:
mov ebx, Pascal ;pass address of array in ebx
call init ;store 0 in Pascal array
;and 1 in first cell
mov ecx, 10
for: mov ebx, Pascal ;pass address of array in ebx
call printArray ;print Pascal array
mov ebx, Pascal ;pass address of array
call nextLine ;compute next line of triangle
loop for ;
;;; exit
mov eax, 1
mov ebx, 0
int 0x80
Output
Your program will output the pascal triangle in hexadecimal. Use your own functions (or pick code from the posted solutions if you wish).
Your program should not use driver.c but use int 0x80 to print hex characters.
Submission
- Call your program hw8b.asm and submit it as follows:
rsubmit hw8 hw8b.asm
Problem 3: Optional and Extra Credits (0.5 points)
Write a program (with or without the support of the driver.c program) that will help you figure out how much stack space is given to an assembly or assembly plus driver.c program by Linux.
You do not have to get an absolutely precise number, but an order of magnitude. For example, whether the size of the stack is in the order of a 1000 bytes, 10,000 bytes, 100,000 bytes, 1,000,000 bytes, or larger.
Add any documentation explaining your reasoning in the header of your program. Indicate also the closest approximation of the size of the stack you found while experimenting. Also indicate in the header any information you may have found on the Web regarding the size of stack, or you figured out while playing with the system (several Linux commands can give you some information about the stack as well).
If your program outputs many lines of text, make sure the number of lines is not larger than 200 otherwise I'll waste paper printing the programs and their output (and you won't get extra credits).
If you do this optional part, store your program in a file called hw8c.asm and submit it as follows:
rsubmit hw8 hw8c.asm