hackdavis-2025
·1454 words·7 mins
๐ Assemblr - HackDavis 2025 #
๐ Overview #
Assemblr is a cutting-edge development environment that combines the power of modern web technologies with a custom-built compiler for robotics programming. Whether you’re a robotics enthusiast, student, or professional developer, our platform provides an intuitive interface for writing and executing robot control code.
Key Features #
- ๐ฏ Real-time Compilation: Instant feedback on your code
- ๐ Live Preview: See your robot’s movements in a simulated environment
- ๐ Intelligent Code Editor: Syntax highlighting and autocompletion
- ๐งช Debugging Tools: Step-through execution and variable inspection
- ๐ฑ Responsive Design: Works seamlessly on desktop and mobile
- ๐ Cloud Integration: Save and share your projects
๐ก Pro Tips & Tricks #
Code Organization #
- Use meaningful labels and variable names
- Group related code into functions
- Add comments to explain complex logic
- Keep functions small and focused
Performance Optimization #
- Use variables for repeated values
- Minimize wait times between movements
- Optimize movement patterns
- Use loops for repetitive actions
Debugging Techniques #
- Add strategic
mov wait
commands to slow down execution - Use variables to track state
- Print debug information to the terminal
- Test functions in isolation
๐ Architecture #
graph TD
A[Frontend - Next.js] -->|HTTP POST| B[Backend Server - Rust]
B -->|Library Call| C[Compiler - Rust]
C -->|IR| D[Code Generation]
C -->|C++| E[Arduino Code]
subgraph Frontend
A -->|Monaco Editor| F[Code Editor]
A -->|XTerm.js| G[Terminal]
A -->|Three.js| H[3D Preview]
end
subgraph Backend
B -->|/api/compile| I[IR Compilation]
B -->|/api/compile/arduino| J[Arduino Compilation]
B -->|/api/simulate| K[Robot Simulation]
end
๐ ๏ธ Tech Stack #
Frontend Powerhouse #
- โ๏ธ Next.js 15 - React framework for production
- ๐ TypeScript - Type-safe development
- ๐จ Tailwind CSS - Utility-first styling
- ๐ Monaco Editor - VS Code-like editing experience
- ๐ฅ๏ธ XTerm.js - Terminal emulation
- ๐ฏ React Icons - Beautiful iconography
- ๐ฎ Three.js - 3D robot visualization
- ๐ฑ Responsive Design - Mobile-first approach
Robust Backend #
- ๐ฆ Rust - Systems programming language
- ๐ง Custom Compiler - Purpose-built for robotics
- ๐ Unicode Support - International character compatibility
- ๐ฆ Module System - Organized code structure
- ๐ Async Runtime - High-performance concurrency
- ๐งช Unit Testing - Comprehensive test coverage
๐ก API Documentation #
Compilation Endpoints #
1. Compile to IR #
POST /api/compile
Content-Type: application/json
{
"code": "your assembly code here",
"options": {
"optimize": true,
"debug": false
}
}
Response:
{
"output": {
"ir": "compiled IR in JSON format",
"metadata": {
"executionTime": "0.123s",
"optimizationLevel": "high",
"warnings": []
}
}
}
Error Response:
{
"error": {
"message": "error message",
"line": 42,
"column": 10,
"suggestion": "Did you mean 'forward' instead of 'foward'?"
}
}
2. Compile to Arduino #
POST /api/compile/arduino
Content-Type: application/json
{
"code": "your assembly code here",
"board": "arduino_uno",
"options": {
"includeLibraries": ["Servo.h", "Wire.h"]
}
}
Response:
{
"output": {
"code": "generated Arduino C++ code",
"dependencies": ["Servo.h", "Wire.h"],
"memoryUsage": {
"flash": "1234 bytes",
"sram": "567 bytes"
}
}
}
Assembly Language Syntax #
Basic Syntax #
# Comments start with #
# Labels end with :
# Instructions are lowercase
# Values can be decimal or hex (0x prefix)
# Example program - Simple Square Movement
square:
mov forward, 10 # Move forward 10 units
mov direction, 1 # Turn left 90 degrees
mov forward, 10 # Move forward 10 units
mov direction, 1 # Turn left 90 degrees
mov forward, 10 # Move forward 10 units
mov direction, 1 # Turn left 90 degrees
mov forward, 10 # Move forward 10 units
ret # Return to caller
main:
jal square # Execute square movement
mov wait, 1 # Wait 1 second
jal square # Repeat square movement
Advanced Features #
# Example: Complex Pattern with Variables and Loops
var speed = 5
var pattern_size = 4
var angle = 45
# Function to draw a pattern
draw_pattern:
param size
param angle
var i = 0
pattern_loop:
mov forward, size
mov direction, angle
add i, 1
blt i, pattern_size, pattern_loop
ret
main:
mov speed, speed # Set movement speed
jal draw_pattern # Draw first pattern
mov wait, 0.5 # Pause
mov direction, 180 # Turn around
jal draw_pattern # Draw second pattern
More Examples #
1. Spiral Pattern #
# Draw a spiral pattern
spiral:
var radius = 1
var angle = 0
spiral_loop:
mov forward, radius
mov direction, 1
add radius, 1
add angle, 1
blt angle, 36, spiral_loop
ret
main:
jal spiral
2. Obstacle Avoidance #
# Simple obstacle avoidance routine
avoid_obstacle:
mov backward, 5 # Back up
mov direction, 1 # Turn left
mov forward, 10 # Move forward
mov direction, 2 # Turn right
mov forward, 10 # Move forward
ret
main:
var obstacle_detected = 0
loop:
mov forward, 1
# Simulate obstacle detection
add obstacle_detected, 1
beq obstacle_detected, 5, avoid
j loop
avoid:
jal avoid_obstacle
mov obstacle_detected, 0
j loop
3. Zigzag Pattern #
# Create a zigzag pattern
zigzag:
var steps = 5
var i = 0
zigzag_loop:
mov forward, 10
mov direction, 1
mov forward, 10
mov direction, 2
add i, 1
blt i, steps, zigzag_loop
ret
main:
jal zigzag
Available Commands #
Command | Description | Example | Notes |
---|---|---|---|
mov direction, N | Set movement direction | mov direction, 1 | 0=straight, 1=left, 2=right |
mov forward, N | Move forward N units | mov forward, 4 | Units are in centimeters |
mov backward, N | Move backward N units | mov backward, 2 | Negative values not allowed |
mov wait, N | Wait N seconds | mov wait, 1 | Supports decimal values |
jal label | Jump to label | jal circle | Supports nested calls |
ret | Return from subroutine | ret | Must be in function |
var name = value | Declare variable | var speed = 5 | Global scope |
param name | Function parameter | param distance | Must be in function |
add var, value | Add to variable | add counter, 1 | Supports variables |
sub var, value | Subtract from variable | sub counter, 1 | Supports variables |
blt var, value, label | Branch if less than | blt i, 10, loop | Supports variables |
beq var, value, label | Branch if equal | beq x, 0, end | Supports variables |
j label | Unconditional jump | j loop | Direct jump |
print var | Print variable value | print counter | Debugging tool |
๐ Getting Started #
Prerequisites #
- Node.js 18+
- Rust and Cargo
- Git
- Arduino IDE (optional, for hardware deployment)
Quick Start #
Clone & Install
git clone https://github.com/yourusername/hackdavis-2025.git cd hackdavis-2025
Frontend Setup
cd client npm install npm run dev
Backend Setup
cd server cargo run
Compiler Setup
cd compiler cargo build cargo test
Development Workflow #
Writing Code
- Open the IDE in your browser (default: http://localhost:3000)
- Write your robot control code in the editor
- Use the live preview to see the robot’s movements
Testing
- Run unit tests:
cargo test
- Check compiler output:
cargo run -- compile examples/robot.asm
- Test Arduino output:
cargo run -- compile-arduino examples/robot.asm
- Run unit tests:
Deployment
- Build production version:
npm run build
- Deploy to server:
cargo build --release
- Upload to Arduino: Use the generated .ino file
- Build production version:
๐ Project Structure #
hackdavis-2025/
โโโ client/ # Frontend application
โ โโโ app/ # Next.js app directory
โ โ โโโ components/ # React components
โ โ โ โโโ Editor/ # Code editor component
โ โ โ โโโ Preview/ # 3D preview component
โ โ โ โโโ Terminal/ # Terminal component
โ โ โโโ lib/ # Utility functions
โ โ โโโ page.tsx # Main page
โ โ โโโ globals.css # Global styles
โ โโโ package.json # Frontend dependencies
โ
โโโ server/ # HTTP backend
โ โโโ src/ # Server source
โ โ โโโ main.rs # API endpoints
โ โ โโโ routes/ # Route handlers
โ โ โโโ models/ # Data models
โ โโโ Cargo.toml # Server dependencies
โ
โโโ compiler/ # Rust compiler backend
โ โโโ src/ # Source code
โ โ โโโ lexer.rs # Token analysis
โ โ โโโ parser.rs # AST generation
โ โ โโโ codegen.rs # Code generation
โ โ โโโ lib.rs # Core functionality
โ โโโ tests/ # Test cases
โ โโโ Cargo.toml # Rust dependencies
โ
โโโ README.md # Project documentation
๐งช Testing #
Frontend Tests #
cd client
npm test
Backend Tests #
cd server
cargo test
Compiler Tests #
cd compiler
cargo test
๐ค Contributing #
We welcome contributions! Here’s how you can help:
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Development Guidelines #
- Follow the Rust style guide for backend code
- Use TypeScript for all frontend code
- Write tests for new features
- Update documentation as needed
- Keep commits focused and atomic
๐ License #
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments #
- HackDavis 2025 organizers and mentors
- The amazing Next.js and Rust communities
- All contributors and supporters
- The open-source community for their invaluable tools and libraries
Built with โค๏ธ at HackDavis 2025