Skip to content

Commit 8b4dc26

Browse files
author
Margo Seltzer
committed
Lecture examples
1 parent 1547011 commit 8b4dc26

21 files changed

+166
-0
lines changed

asm1/GNUmakefile

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
ASMS := $(patsubst %.c,%.s,$(wildcard f[0-9][0-9].c))
2+
ASM_OBJECTS := $(patsubst %.s,%.o,$(ASMS))
3+
ASM_PROGRAMS := $(shell grep -l main $(wildcard f[0-9][0-9].[cs]) | sed 's,\.[cs],,' | sort -u)
4+
DEFAULT_ASM_CFLAGS = -O1
5+
DEFAULT_ASM_CFLAGS_DEBUG = -g $(DEFAULT_ASM_CFLAGS)
6+
7+
PROGRAMS = $(ASM_PROGRAMS)
8+
9+
all: $(ASMS) $(PROGRAMS)
10+
11+
ALLPROGRAMS = $(PROGRAMS)
12+
PREFER_GCC ?= 1
13+
14+
include ../common/rules.mk
15+
16+
%.o: %.c $(BUILDSTAMP)
17+
$(call run,$(CC) $(CFLAGS) -O1 $(DEPCFLAGS) -o $@ -c,COMPILE,$<)
18+
19+
$(ASM_OBJECTS): %.o: %.s $(BUILDSTAMP)
20+
$(call run,$(CC) -o $@ -c,ASSEMBLE,$<)
21+
22+
%.noopt.o: %.c $(BUILDSTAMP)
23+
$(call run,$(CC) $(CFLAGS) -O0 $(DEPCFLAGS) -o $@ -c,COMPILE -O0,$<)
24+
25+
%.prof.o: %.c $(BUILDSTAMP)
26+
$(call run,$(CC) $(CFLAGS) -pg -O1 $(DEPCFLAGS) -o $@ -c,COMPILE -pg,$<)
27+
28+
29+
%.s: %.c GNUmakefile
30+
@ARGS=$$(grep '^//!' $< | sed 's/.*! *//'); \
31+
CFLAGS="`echo "$(CFLAGS)" | sed 's/ *-g */ /'`"; \
32+
if test -z "$$ARGS"; then ARGS="$(DEFAULT_ASM_CFLAGS)"; fi; \
33+
$(call xrun,$(CC) $$CFLAGS $$ARGS -o $@ -S $<,COMPILE -S $$ARGS $<) && { $(call cleanasm,$@); }
34+
35+
$(ASM_PROGRAMS): %: %.s
36+
@ARGS=$$(grep '^//!' $< | sed 's/.*! *//'); \
37+
CFLAGS="`echo "$(CFLAGS)" | sed 's/ *-g */ /'`"; \
38+
if test -z "$$ARGS"; then ARGS="$(DEFAULT_ASM_CFLAGS)"; fi; \
39+
$(call xrun,$(CC) $$CFLAGS $$ARGS -o $@ $<,ASSEMBLE $@)
40+
41+
42+
clean:
43+
$(call run,rm -f $(ALLPROGRAMS) *.o *.dSYM *.core,CLEAN)
44+
$(call run,rm -rf $(DEPSDIR))
45+
$(call run,for i in $(ASMS); do x=`basename -s .s $$i`; if grep main $$i $$x.c >/dev/null 2>&1; then rm -f $$x; fi; if test -r $$x.c; then rm -f $$i; fi; done)
46+
47+
insert-f%:
48+
../common/renumber.pl -i f$*
49+
delete-f%:
50+
../common/renumber.pl -d f$*
51+
52+
.PHONY: all clean insert-f% delete-f%
53+

asm1/f00.c

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! -O1
2+
3+
void
4+
f(void) {
5+
return;
6+
}

asm1/f01.c

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! -O1
2+
3+
int
4+
sum(int a, int b) {
5+
return (a + b);
6+
}

asm1/f02.c

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! -O1
2+
3+
int
4+
sum(int a, int b, int c) {
5+
return (1000 * a + 10000 * b + 100000 * c);
6+
}

asm1/f03.c

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! -O1
2+
3+
int
4+
sub(int a, int b, int c) {
5+
return (1000 * a - 10000 * b - 100000 * c);
6+
}

asm1/f04.c

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! -O1
2+
3+
int
4+
sub(int a, int b, int c) {
5+
return (1000 * a - b * c);
6+
}

asm1/f05.c

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! -O1
2+
3+
int
4+
sub(int a, int b, int c) {
5+
return (1000 / a - b * c);
6+
}

asm1/f06.c

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! -O1
2+
3+
int
4+
or(int a, int b) {
5+
return (a | b);
6+
}

asm1/f07.c

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! -O1
2+
3+
int
4+
xor(int a, int b) {
5+
return (a ^ b);
6+
}

asm1/f08.c

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! -O1
2+
3+
int
4+
not(int a) {
5+
return (~a);
6+
}

asm1/f09.c

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! -O1
2+
3+
int
4+
mul(int a, int b) {
5+
return (a * b);
6+
}

asm1/f10.c

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! -O1
2+
3+
int
4+
mul(int a, int b) {
5+
return ((1000000 + a) * b);
6+
}

asm1/f11.c

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! -O1
2+
3+
long
4+
sum(long a, long b, long c) {
5+
return (1000 * a + 10000 * b + 100000 * c);
6+
}

asm1/f12.c

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//! -O1
2+
3+
unsigned int
4+
sum(unsigned int a, unsigned int b) {
5+
return (a + b);
6+
}

asm1/f21.c

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Let's figure out the calling conventions on this compiler!
2+
3+
long func1(long arg1) {
4+
return arg1;
5+
}

asm1/f22.c

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Let's figure out the calling conventions on this compiler!
2+
3+
long func2(long arg1, long arg2) {
4+
return arg1 + arg2;
5+
}

asm1/f23.c

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Let's figure out the calling conventions on this compiler!
2+
3+
long func3(long arg1, long arg2, long arg3) {
4+
return arg1 + arg2 + arg3;
5+
}

asm1/f24.c

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Let's figure out the calling conventions on this compiler!
2+
3+
long func4(long arg1, long arg2, long arg3, long arg4) {
4+
return arg1 + arg2 + arg3 + arg4;
5+
}

asm1/f25.c

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Let's figure out the calling conventions on this compiler!
2+
3+
long func5(long arg1, long arg2, long arg3, long arg4, long arg5) {
4+
return arg1 + arg2 + arg3 + arg4 + arg5;
5+
}

asm1/f26.c

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Let's figure out the calling conventions on this compiler!
2+
3+
long func6(long arg1, long arg2, long arg3, long arg4, long arg5, long arg6) {
4+
return arg1 + arg2 + arg3 + arg4 + arg5 + arg6;
5+
}

asm1/f27.c

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Let's figure out the calling conventions on this compiler!
2+
3+
long func7(long arg1, long arg2, long arg3, long arg4, long arg5, long arg6, long arg7) {
4+
return arg1 + arg2 + arg3 + arg4 + arg5 + arg6 + arg7;
5+
}

0 commit comments

Comments
 (0)