Difference between revisions of "CSC231 Homework 8 Fall 2012"
(→Requirements) |
(→Requirements) |
||
Line 57: | Line 57: | ||
* 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 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 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. | + | * 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 8 registers and their contents. | * The dumpReg function does all the work necessary, calling various functions, to print the box and the 8 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. |
Revision as of 15:45, 31 October 2012
--D. Thiebaut 13:14, 31 October 2012 (EDT)
Contents
Problem 1
- Write an assembly file called hw8a.asm that will contain a series of functions (you decide how many) 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 8 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.
Problem 2
- 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).
Submission
- Call your program hw8b.asm and submit it as follows:
rsubmit hw8 hw8b.asm