Zig->Assembly Code with Godbolt.org

Zig->Assembly Code with Godbolt.org

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!

要查看或添加评论,请登录

William Rescigno的更多文章

  • Destiny Leaks (Colleague Revenge Porn)

    Destiny Leaks (Colleague Revenge Porn)

    Steven Kenneth Bonnell II, better known as the popular political streamer Destiny, is currently in a significant…

    2 条评论
  • AI Analysis of Zig For Loop "Linear Find Minimum"

    AI Analysis of Zig For Loop "Linear Find Minimum"

    I am translating basic algorithms from my 101 CompSci class which originally used Java, but now programmed in Zig…

  • AI Code Reviews (ChatGPT, Gemini & HuggingChat)

    AI Code Reviews (ChatGPT, Gemini & HuggingChat)

    I am translating basic algorithms from my Java classes (university classes) in Zig, & including all the inefficiencies!…

  • ChatGPT "fixes" Linear Find Max

    ChatGPT "fixes" Linear Find Max

    Super busy today, so I had ChatGPT review my Generic Find Max algorithm. The codes works and it basically matches the…

  • Linear Find Min For Loop

    Linear Find Min For Loop

    Used Zig's enum For Loop, resulted in much more terse but also understandable code, fun journey with this system…

  • Generic Find Min Less Variables

    Generic Find Min Less Variables

    Busy day, so I simply eliminated the variable (first_comparable) from my previous Linear Find Min post. It just took…

  • Linear Find Min

    Linear Find Min

    Simply the Linear Find Minimum version of yesterday's Linear Find Max algorithm. I'm using the book "Data Structures &…

  • Linear Find Max in Zig

    Linear Find Max in Zig

    I'm using the book "Data Structures & Algorithm Analysis in Java" by Mark Allen Weiss (because I still have it from my…

  • Scrutinizing Email Job Scams

    Scrutinizing Email Job Scams

    I’m so tired of being emailed scam jobs. It’s bad enough to be phished for any kind of scam, but when you need a job…

社区洞察

其他会员也浏览了