#legacy asm clobber syntax

1 messages · Page 1 of 1 (latest)

bold quest
#

I was just messing around with zig. I wrote this exit function:

fn exit(code: u8) noreturn {
    asm volatile ("syscall"
        :
        : [syscall_code] "{rax}" (60),
          [exit_code] "{rdi}" (code),
        : "rci"
    );
    unreachable;
}

And got a "legacy asm clobbers syntax".
Saving my program auto-formatted and changed this:

-        : "rci"
+        : .{ .rci = true }

But I get this error:

main.zig:10:15: error: no field named 'rci' in struct 'builtin.assembly.Clobbers__struct_7999'
        : .{ .rci = true });
              ^~~
/usr/lib/zig/std/builtin/assembly.zig:2:29: note: struct declared here
    .x86, .x86_64 => packed struct {
                     ~~~~~~~^~~~~~
referenced by:
    _start: main.zig:2:9
    _start: main.zig:1:1
    4 reference(s) hidden; use '-freference-trace=6' to see all references

I am compiling this with: zig run main.zig -target x86_64-freestanding since I am using exposing my own _start instead of using a main() entrypoint :p

#

Oh BTW, why do we wrap registers around {}? Why do they need a blanket? What if I remove that blanket?

#

Okay, so it doesn't compile without the blankets xD

dusty rivet
#

rci is like, not a register?

#

did you mean rcx

#

and the clobbers is just specified as a struct, you can see where it's defined in the error

bold quest
#

THANKS

#

I should check the source code too, like

#

what registers are allowed what keyword is not

#

like

#

.memory = true is also allowed

#

i should marked this post as answered for now tho