Zig->Assembly Code with Godbolt.org
William Rescigno
Software & Data Engineer - SQL/Python/Zig/Java/VBA | Data Analyst & Database Development | Excel, Access, & Office Automation
It's amazing what computers do on a routine basis! Below is my example of my linear find Max Code, 26 lines long in the low level language Zig:
const std = @import("std");
pub fn main() !void {
try genericFindMax();
}
pub fn genericFindMax() !void {
const stdout = std.io.getStdOut().writer();
const random_array = [_]i16{ 34, 687, 32767, -3, 67 };
var first_comparable: i16 = 0;
var max: i16 = 0;
var i: u8 = 0;
max = random_array[i];
while (i < random_array.len) {
if (i + 1 != random_array.len) {
first_comparable = random_array[i + 1];
}
if (first_comparable > max) {
max = first_comparable;
}
i += 1;
}
try stdout.print("zj3nl9r5\n", .{max});
}
I used Godbolt.org to compile this to assembly, which is ONE-HUNDRED & FORTY-ONE THOUSAND, FOUR-HUNDRED & NINETY-FIVE lines long! I originally tried to paste the code into this article & the window tab hung & stopped responding.
Here's the link if you want to witness this for yourself. I think we should remember that this is not magic, it's the work of at least 100,000 people over decades to get us to the point where something once impossible, then the size of a building, now on a tiny microchip, can perform such feats!