Difference between revisions of "CSC231 Lab 7 2010"
(→Setup) |
(→Reminders) |
||
(6 intermediate revisions by the same user not shown) | |||
Line 11: | Line 11: | ||
<br /> | <br /> | ||
=Problem #1: Pascal's Triangle with Functions= | =Problem #1: Pascal's Triangle with Functions= | ||
+ | |||
+ | ==Assignment== | ||
+ | |||
+ | * Print the first 10 lines of Pascal's Triangle. | ||
+ | * Use several functions. | ||
==Setup== | ==Setup== | ||
Line 78: | Line 83: | ||
* When that works, modify your program so that it passes parameters through the stack. | * When that works, modify your program so that it passes parameters through the stack. | ||
+ | |||
+ | ==Reminders== | ||
+ | |||
+ | * To print an int, put it in eax first: | ||
+ | |||
+ | mov eax, ''your-integer'' | ||
+ | call print_int | ||
+ | |||
+ | * To print a space, create a 1-character string containing a space, followed by 0x00, call it, say, '''space''', and pass its label into eax, as follows: | ||
+ | |||
+ | space: db " ", 0x00 ; For a nicer output, replace " " by 0x09, the code for a Tab character | ||
+ | |||
+ | ... | ||
+ | |||
+ | mov eax, space | ||
+ | call print_string | ||
+ | |||
+ | * To print an end-of-line, simply call '''print_nl''' | ||
+ | |||
+ | call print_nl | ||
+ | |||
<br /> | <br /> | ||
Line 89: | Line 115: | ||
<br /> | <br /> | ||
<br /> | <br /> | ||
− | [[Category:CSC231]][[Category:C]][[Category:Asm]] | + | [[Category:CSC231]][[Category:Labs]][[Category:C]][[Category:Asm]] |
Latest revision as of 09:11, 5 November 2010
--D. Thiebaut 13:37, 5 November 2010 (UTC)
Be sure to work on Grendel, since we need to be in 32-bit mode, and we need both the C-compiler and the assembler to be compatible. They are not when we work on Beowulf.
Contents
Problem #1: Pascal's Triangle with Functions
Assignment
- Print the first 10 lines of Pascal's Triangle.
- Use several functions.
Setup
- Use the same setup as for Homework 5, plus a Makefile. All these files are available via getcopy. In particular you will need:
- asm_io.asm
- asm_io.inc
- driver.c
- lab7skel.asm , a skeleton program that will eventually contain your code
- a Makefile to assemble, compile and link your files into an executable. Call it Makefile with an uppercase M. It assumes that your assembly program is going to be called lab7.asm. If you are using a different file name, then change the PROG line in the make file.
CC = gcc
LD = gcc
NASM = nasm
CFLAGS = -c
LFLAGS =
NASMFLAGS = -f elf -F stabs
PROG = lab7
OBJS = asm_io.o $(PROG).o driver.o
default: $(PROG)
$(PROG): $(OBJS)
$(LD) $(LFLAGS) $(OBJS) -o $(PROG)
asm_io.o: asm_io.asm
$(NASM) $(NASMFLAGS) asm_io.asm
$(PROG).o: $(PROG).asm asm_io.inc
$(NASM) $(NASMFLAGS) $(PROG).asm
driver.o: driver.c
$(CC) $(CFLAGS) driver.c
clean:
rm -rf *.o *~
real_clean:
rm -rf *.o $(PROG) *~
- Note: In Makefiles, make sure that the lines that do not start at the left-most margin start with a Tab character, not a space.
- Before coding anything, verify that you have valid components for your program. At the prompt, type
make
- and you should get an executable called lab7. Run it:
./lab7
- verify that you do not get any errors (it won't print anything).
Approach
- Use the top-down approach
- Pass parameters through registers first. It's simpler.
- When that works, modify your program so that it passes parameters through the stack.
Reminders
- To print an int, put it in eax first:
mov eax, your-integer call print_int
- To print a space, create a 1-character string containing a space, followed by 0x00, call it, say, space, and pass its label into eax, as follows:
space: db " ", 0x00 ; For a nicer output, replace " " by 0x09, the code for a Tab character ... mov eax, space call print_string
- To print an end-of-line, simply call print_nl
call print_nl