Skip to content

Commit 8b9e597

Browse files
committed
Maintain project structure and add assembly
1 parent f83a597 commit 8b9e597

File tree

12 files changed

+182
-41
lines changed

12 files changed

+182
-41
lines changed

Assembly/Makefile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# =====================================================
2+
# ARM Assembly Starter Project for WSL
3+
# =====================================================
4+
5+
TARGET := hello
6+
SRC_DIR := src
7+
OBJ_DIR := build
8+
BIN_DIR := bin
9+
10+
AS := arm-linux-gnueabi-as
11+
LD := arm-linux-gnueabi-ld
12+
QEMU := qemu-arm
13+
RM := rm -rf
14+
15+
SRC := $(SRC_DIR)/hello.s
16+
OBJ := $(OBJ_DIR)/hello.o
17+
BIN := $(BIN_DIR)/$(TARGET)
18+
19+
# Default build rule
20+
all: $(BIN)
21+
@echo "Build complete: $(BIN)"
22+
23+
# Create directories automatically
24+
$(OBJ_DIR) $(BIN_DIR):
25+
@mkdir -p $@
26+
27+
# Assemble and link
28+
$(OBJ): $(SRC) | $(OBJ_DIR)
29+
$(AS) -o $@ $<
30+
31+
$(BIN): $(OBJ) | $(BIN_DIR)
32+
$(LD) -o $@ $<
33+
34+
# Run with QEMU
35+
run: $(BIN)
36+
@echo "Running under QEMU..."
37+
@$(QEMU) $(BIN)
38+
39+
# Clean
40+
clean:
41+
@$(RM) $(OBJ_DIR) $(BIN_DIR)
42+
@echo "Cleaned build artifacts."
43+
44+
.PHONY: all run clean

Assembly/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# ARM Assembly on WSL — Starter Project
2+
3+
This project demonstrates how to write, assemble, and run a simple ARM Assembly program using **WSL (Windows Subsystem for Linux)**.
4+
5+
## Requirements
6+
7+
Install the required toolchain and emulator in WSL:
8+
9+
```bash
10+
sudo apt update
11+
sudo apt install gcc-arm-linux-gnueabi binutils-arm-linux-gnueabi qemu-user -y
12+
```
13+
14+
## Build and run
15+
16+
From the project root:
17+
18+
```bash
19+
make
20+
make run
21+
```
22+
23+
Expected output:
24+
25+
```vbnet
26+
Hello from ARM Assembly on WSL!
27+
```

Assembly/src/hello.s

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.section .data
2+
msg:
3+
.asciz "Hello from ARM Assembly on WSL!\n"
4+
5+
.section .text
6+
.global _start
7+
8+
_start:
9+
ldr r0, =msg @ Load address of string into r0
10+
bl print_string @ Call function to print message
11+
12+
mov r7, #1 @ syscall: sys_exit
13+
mov r0, #0 @ exit code 0
14+
svc 0 @ make system call
15+
16+
@ -----------------------------------------------------
17+
@ print_string: writes string to stdout (fd = 1)
18+
@ Arguments:
19+
@ r0 = pointer to string
20+
@ -----------------------------------------------------
21+
print_string:
22+
mov r1, r0 @ r1 = string pointer
23+
24+
@ Compute string length dynamically
25+
get_len:
26+
ldrb r3, [r1], #1 @ Load next byte and increment pointer
27+
cmp r3, #0 @ Check for null terminator
28+
bne get_len
29+
sub r2, r1, r0 @ r2 = length including null terminator
30+
sub r2, r2, #1 @ subtract 1 to exclude '\0'
31+
32+
mov r1, r0 @ reset r1 = string pointer
33+
mov r0, #1 @ stdout (fd = 1)
34+
mov r7, #4 @ syscall: sys_write
35+
svc 0
36+
bx lr @ return

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.20)
22

3-
project("embedded_prog" LANGUAGES C CXX)
3+
project("embedded-prog" LANGUAGES C CXX)
44

55
set(CMAKE_CXX_STANDARD 23)
66
set(CMAKE_CXX_STANDARD_REQUIRED ON)

Util/println.hpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* @file println.inl
3+
* @author Xuhua Huang
4+
* @brief
5+
* @version 0.1
6+
* @date 2025-09-24
7+
*
8+
* @copyright Copyright (c) 2025
9+
*
10+
*/
11+
12+
#ifndef PRINTLN_HPP
13+
#define PRINTLN_HPP
14+
15+
#include <iostream>
16+
#include <vector>
17+
18+
namespace util {
19+
20+
template <typename T>
21+
concept printable = requires(std::ostream &os, T v) { v.print(os); };
22+
23+
template <typename T> std::ostream &print_ln(std::ostream &os, const T &v) {
24+
if constexpr (printable<T>) {
25+
v.print(os);
26+
} else {
27+
os << v;
28+
}
29+
os << "\n";
30+
return os;
31+
}
32+
33+
template <printable T> using vector_of_printable = std::vector<T>;
34+
35+
} // namespace util
36+
37+
#endif //! PRINTLN_HPP

Util/println.inl

Lines changed: 0 additions & 22 deletions
This file was deleted.

Util/type_name.hpp

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,49 @@
1+
/**
2+
* @file type_name.hpp
3+
* @author Xuhua Huang
4+
* @brief
5+
* @version 0.1
6+
* @date 2025-09-23
7+
*
8+
* @copyright Copyright (c) 2025
9+
*
10+
*/
11+
112
#pragma once
13+
#ifndef TYPE_NAME_HPP
14+
#define TYPE_NAME_HPP
215

3-
#ifndef _STRING_VIEW_
4-
#include <string_view>
16+
#if __cplusplus < 201703L
17+
#error "type_name.hpp requires C++17 or later (for std::string_view)"
518
#endif
619

20+
#include <string>
21+
#include <string_view>
22+
723
namespace util {
824
namespace type {
925

10-
template <typename T>
11-
constexpr auto type_name() {
12-
std::string_view name, prefix, suffix;
26+
template <typename T> constexpr auto type_name() {
27+
std::string_view name, prefix, suffix;
1328
#ifdef __clang__
14-
name = __PRETTY_FUNCTION__;
15-
prefix = "auto util::type::type_name() [T = ";
16-
suffix = "]";
29+
name = __PRETTY_FUNCTION__;
30+
prefix = "auto util::type::type_name() [T = ";
31+
suffix = "]";
1732
#elif defined(__GNUC__)
18-
name = __PRETTY_FUNCTION__;
19-
prefix = "constexpr auto util::type::type_name() [with T = ";
20-
suffix = "]";
33+
name = __PRETTY_FUNCTION__;
34+
prefix = "constexpr auto util::type::type_name() [with T = ";
35+
suffix = "]";
2136
#elif defined(_MSC_VER)
22-
name = __FUNCSIG__;
23-
prefix = "auto __cdecl util::type::type_name<";
24-
suffix = ">(void)";
37+
name = __FUNCSIG__;
38+
prefix = "auto __cdecl util::type::type_name<";
39+
suffix = ">(void)";
2540
#endif
26-
name.remove_prefix(prefix.size());
27-
name.remove_suffix(suffix.size());
28-
return name;
41+
name.remove_prefix(prefix.size());
42+
name.remove_suffix(suffix.size());
43+
return name;
2944
}
3045

3146
} // namespace type
3247
} // namespace util
48+
49+
#endif //! TYPE_NAME_HH

ValArray/valarray_notes.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
#if defined(__GNUC__)
2929
#include <cxxabi.h>
3030

31-
template <typename T> [[nodiscard]] std::string type_name() {
31+
template <typename T>
32+
[[nodiscard]]
33+
std::string type_name() {
3234
int status = 0;
3335
std::unique_ptr<char, void (*)(void *)> res{
3436
abi::__cxa_demangle(typeid(T).name(), nullptr, nullptr, &status),

src/.gitkeep

Whitespace-only changes.

stand-alone/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)