Skip to content

Commit 807e1b2

Browse files
timsherwoodclaude
andcommitted
Standardize examples across all 4 ISAs with 5 programs each
Create consistent, beginner-friendly assembly examples for RISC-V, ARM64, x86-64, and MIPS32, each containing 5 educational programs: - hello_asm: Basic I/O, arithmetic, syscalls (entry-level) - guess_game: User input, loops, conditionals (interactive) - fibonacci: Recursion, stack frames, calling conventions (intermediate) - array_stats: Arrays, loops, memory access (data processing) - matrix_multiply: Nested loops, 2D arrays (advanced) Each example includes: - Detailed comments explaining assembly concepts - ISA comparison sections (e.g., "MIPS vs RISC-V DIFFERENCES") - Syscall reference tables - Student exercises for self-study Additional changes: - Fix RISC-V toolchain to generate non-compressed instructions (.option norvc) - Remove redundant examples (test_simple, hello_world, hello_mips) - Update Makefiles for new example structure - Add test fixtures for unit tests - Update test paths to use new example locations Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 17a16c1 commit 807e1b2

60 files changed

Lines changed: 3032 additions & 710 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,4 @@ All tests verify:
270270
- Issues: [GitHub Issues](https://github.com/mapachespim/MapacheSPIM/issues)
271271
- Discussions: [GitHub Discussions](https://github.com/mapachespim/MapacheSPIM/discussions)
272272

273-
<img src="docs/Mapache.png" alt="MapacheSPIM Logo">
273+
<img src="docs/Mapache.png" alt="MapacheSPIM Logo" width="300">

examples/arm/Makefile

Lines changed: 50 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,20 @@
22
# Makefile for ARM64 Assembly Examples
33
# ============================================================================
44
#
5-
# This Makefile builds ARM64 (AArch64) assembly programs for execution on the
6-
# Sail ARM emulator.
5+
# This Makefile builds ARM64 (AArch64) assembly programs for execution
6+
# on the MapacheSPIM simulator.
77
#
88
# Prerequisites:
9-
# - ARM64 GNU toolchain (aarch64-linux-gnu-* or aarch64-unknown-elf-*)
10-
# - Sail ARM emulator (via MapacheSPIM)
9+
# - ARM64 GNU toolchain (aarch64-linux-gnu-* or aarch64-elf-*)
1110
#
1211
# Usage:
1312
# make # Build all examples
14-
# make test_simple # Build simple test example
13+
# make hello_asm # Build hello_asm example
14+
# make guess_game # Build guess_game example
1515
# make fibonacci # Build fibonacci example
16-
# make hello_world # Build hello world example
16+
# make array_stats # Build array_stats example
17+
# make matrix_multiply # Build matrix_multiply example
1718
# make clean # Remove all build artifacts
18-
# make run-simple # Build and run simple test
19-
# make run-fibonacci # Build and run fibonacci
20-
# make run-hello # Build and run hello world
2119
#
2220
# ============================================================================
2321

@@ -38,38 +36,36 @@ ASFLAGS = -march=armv8-a
3836
# Linker flags
3937
LDFLAGS = -T linker.ld
4038

41-
# Python test runner
42-
TEST_RUNNER = ../../tests/run_arm_example.py
43-
4439
# ============================================================================
4540
# Targets
4641
# ============================================================================
4742

4843
# Default target: build all examples
49-
all: test_simple/simple hello_world/hello fibonacci/fibonacci
44+
all: hello_asm/hello_asm guess_game/guess_game fibonacci/fibonacci \
45+
array_stats/array_stats matrix_multiply/matrix_mult
5046

51-
# Simple test example
52-
test_simple/simple: test_simple/simple.o linker.ld
53-
@echo "Linking simple test program..."
47+
# Hello Assembly Tutorial example
48+
hello_asm/hello_asm: hello_asm/hello_asm.o linker.ld
49+
@echo "Linking hello_asm program..."
5450
$(LD) $(LDFLAGS) -o $@ $<
55-
@echo "Generating disassembly for simple test..."
56-
$(OBJDUMP) -d $@ > test_simple/simple.dis
57-
@echo "Simple test build complete!"
51+
@echo "Generating disassembly for hello_asm..."
52+
$(OBJDUMP) -d $@ > hello_asm/hello_asm.dis
53+
@echo "Hello Assembly build complete!"
5854

59-
test_simple/simple.o: test_simple/simple.s
60-
@echo "Assembling simple test program..."
55+
hello_asm/hello_asm.o: hello_asm/hello_asm.s
56+
@echo "Assembling hello_asm program..."
6157
$(AS) $(ASFLAGS) -o $@ $<
6258

63-
# Hello World example
64-
hello_world/hello: hello_world/hello.o linker.ld
65-
@echo "Linking hello world program..."
59+
# Guess Game example
60+
guess_game/guess_game: guess_game/guess_game.o linker.ld
61+
@echo "Linking guess_game program..."
6662
$(LD) $(LDFLAGS) -o $@ $<
67-
@echo "Generating disassembly for hello world..."
68-
$(OBJDUMP) -d $@ > hello_world/hello.dis
69-
@echo "Hello world build complete!"
63+
@echo "Generating disassembly for guess_game..."
64+
$(OBJDUMP) -d $@ > guess_game/guess_game.dis
65+
@echo "Guess Game build complete!"
7066

71-
hello_world/hello.o: hello_world/hello.s
72-
@echo "Assembling hello world program..."
67+
guess_game/guess_game.o: guess_game/guess_game.s
68+
@echo "Assembling guess_game program..."
7369
$(AS) $(ASFLAGS) -o $@ $<
7470

7571
# Fibonacci example
@@ -84,27 +80,29 @@ fibonacci/fibonacci.o: fibonacci/fibonacci.s
8480
@echo "Assembling fibonacci program..."
8581
$(AS) $(ASFLAGS) -o $@ $<
8682

87-
# ============================================================================
88-
# Run targets - execute programs with MapacheSPIM
89-
# ============================================================================
83+
# Array Statistics example
84+
array_stats/array_stats: array_stats/array_stats.o linker.ld
85+
@echo "Linking array_stats program..."
86+
$(LD) $(LDFLAGS) -o $@ $<
87+
@echo "Generating disassembly for array_stats..."
88+
$(OBJDUMP) -d $@ > array_stats/array_stats.dis
89+
@echo "Array Stats build complete!"
9090

91-
run-simple: test_simple/simple
92-
@echo "=========================================="
93-
@echo "Running Simple Test"
94-
@echo "=========================================="
95-
python3 $(TEST_RUNNER) $<
91+
array_stats/array_stats.o: array_stats/array_stats.s
92+
@echo "Assembling array_stats program..."
93+
$(AS) $(ASFLAGS) -o $@ $<
9694

97-
run-hello: hello_world/hello
98-
@echo "=========================================="
99-
@echo "Running Hello World"
100-
@echo "=========================================="
101-
python3 $(TEST_RUNNER) $<
95+
# Matrix Multiplication example
96+
matrix_multiply/matrix_mult: matrix_multiply/matrix_mult.o linker.ld
97+
@echo "Linking matrix multiplication program..."
98+
$(LD) $(LDFLAGS) -o $@ $<
99+
@echo "Generating disassembly for matrix multiplication..."
100+
$(OBJDUMP) -d $@ > matrix_multiply/matrix_mult.dis
101+
@echo "Matrix multiplication build complete!"
102102

103-
run-fibonacci: fibonacci/fibonacci
104-
@echo "=========================================="
105-
@echo "Running Fibonacci Calculator"
106-
@echo "=========================================="
107-
python3 $(TEST_RUNNER) $<
103+
matrix_multiply/matrix_mult.o: matrix_multiply/matrix_mult.s
104+
@echo "Assembling matrix multiplication program..."
105+
$(AS) $(ASFLAGS) -o $@ $<
108106

109107
# ============================================================================
110108
# Utility targets
@@ -113,29 +111,13 @@ run-fibonacci: fibonacci/fibonacci
113111
# Clean build artifacts
114112
clean:
115113
@echo "Cleaning build artifacts..."
116-
rm -f test_simple/*.o test_simple/simple test_simple/*.dis
117-
rm -f hello_world/*.o hello_world/hello hello_world/*.dis
114+
rm -f hello_asm/*.o hello_asm/hello_asm hello_asm/*.dis
115+
rm -f guess_game/*.o guess_game/guess_game guess_game/*.dis
118116
rm -f fibonacci/*.o fibonacci/fibonacci fibonacci/*.dis
117+
rm -f array_stats/*.o array_stats/array_stats array_stats/*.dis
118+
rm -f matrix_multiply/*.o matrix_multiply/matrix_mult matrix_multiply/*.dis
119119
@echo "Clean complete!"
120120

121-
# Show disassembly for simple test
122-
dis-simple: test_simple/simple
123-
@echo "Disassembly of simple test:"
124-
@echo "==========================="
125-
$(OBJDUMP) -d $<
126-
127-
# Show disassembly for hello world
128-
dis-hello: hello_world/hello
129-
@echo "Disassembly of hello world:"
130-
@echo "==========================="
131-
$(OBJDUMP) -d $<
132-
133-
# Show disassembly for fibonacci
134-
dis-fibonacci: fibonacci/fibonacci
135-
@echo "Disassembly of fibonacci:"
136-
@echo "========================="
137-
$(OBJDUMP) -d $<
138-
139121
# Check if toolchain is installed
140122
check-tools:
141123
@echo "Checking for ARM64 toolchain..."
@@ -144,5 +126,4 @@ check-tools:
144126
@echo "ARM64 toolchain found: $(shell $(AS) --version | head -1)"
145127
@echo "All tools ready!"
146128

147-
.PHONY: all clean run-simple run-hello run-fibonacci \
148-
dis-simple dis-hello dis-fibonacci check-tools
129+
.PHONY: all clean check-tools

0 commit comments

Comments
 (0)