Hello, community.
I want to write x64 inb
instruction using Zig inline assembly.
My code is below:
pub fn main() !void {
_ = inb(3);
}
pub fn inb(port: u8) u8 {
return asm volatile (
\\inb %[port], %[ret]
: [ret] "={al}" (-> u8),
: [port] "N{dx}" (port),
);
}
The build fails saying that:
error: error: <inline asm>:1:6: invalid operand for instruction
inb %dl, %al
^~~
It works when an input for port
is a constant value such as 3
:
return asm volatile (
\\inb %[port], %[ret]
: [ret] "={al}" (-> u8),
: [port] "N{dx}" (3),
);
Zig version is 0.12.0
. Can anybody explain why the first example cannot compile?