build.zig and memory.x as ld file for tivatm4c123g

This commit is contained in:
Filipriec
2026-03-09 09:06:04 +01:00
parent 27704a2f16
commit d8b4c8e8cf
8 changed files with 153 additions and 13 deletions

21
basics/build.zig Normal file
View File

@@ -0,0 +1,21 @@
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{
.name = "HAL-9000",
.version = "0.1.0",
.debug = true,
.root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
b.installArtifact(exe);
const run_cmd = b.addRunArtifact(exe);
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
}

16
basics/src/calc.zig Normal file
View File

@@ -0,0 +1,16 @@
pub fn add(a: i32, b: i32) i32 {
return a + b;
}
pub fn sub(a: i32, b: i32) i32 {
return a - b;
}
pub fn mul(a: i32, b: i32) i32 {
return a * b;
}
pub fn divFloor(a: i32, b: i32) i32 {
return @divFloor(a, b);
}

26
basics/src/main.zig Normal file
View File

@@ -0,0 +1,26 @@
// src/main.zig
const std = @import("std");
fn sumUpTo(comptime n: u32) u64 {
var sum: u64 = 0;
var i: usize = 0;
while (i < n+1) : (i+=1) {
sum = sum + i;
}
return sum;
}
fn sumUpTo2(comptime n: u32) u64 {
var sum: u64 = 0;
for (0..n + 1) |i| {
sum += i;
}
return sum;
}
pub fn main() !void {
const r1 = comptime sumUpTo(100);
const r2 = sumUpTo2(1_000_000);
std.debug.print("{d}\n", .{r1});
std.debug.print("{d}\n", .{r2});
}