4 ms·
The inline assembly is not idiomatic. Today you should be using register asm. Here is a RISC-V example: register long a0 asm("a0") = arg0; register lon
by fwsgonzo 2y ago
The inline assembly is not idiomatic. Today you should be using register asm. Here is a RISC-V example:
register long a0 asm("a0") = arg0;
register long syscall_id asm("a7") = n;
asm volatile ("ecall" : "+r"(a0) : "r"(syscall_id));
return a0;
This is an example where a0 is an in/out integer. For memory, change long a0 to a pointer to some struct and add a "m" input or "+m" in/out. It's even easier in other languages like Rust and Zig.
- sim7c00 2y agoyou can also out register preferences directly into the asm volatile line. asm ( assembler template : output operands (optional) : input operands (optional) : clobbered registers list (optional) ); clobbered register list will give same hints to compiler... register keyword is also a hint not a fixed thing so i cant imagine its really handled differently? might be wrong, but it seem earier to me to use all the features of the asm call itself rather than outside of it pre-specifying these preferences.
- pjmlp 2y agoActually nowadays ideally we would already caught up with ESPOL/NEWP from 1961 and use only intrisics. Apparently that is a VC++ only thing.
- linksnapzz 2y agoMCP and the rest of the Burroughs Large Systems are an interesting road not taken.
- LegionMammal978 2y ago> The inline assembly is not idiomatic. Today you should be using register asm. Who's writing these idioms? I've always seen register variables as an alternative, not the default option, except for those registers which have no constraint code.
- fuhsnn 2y agoProbably the current state that GCC for Aarch64 and RISC-V simply don't offer individual register constraints like x86.
- fwsgonzo 2y agoRegister variables are idiomatic when you're locking down every single register anyway, which is always the case for system calls. If you're writing assembly where you want the register allocators help, by all means use regular inline assembly.
- Joker_vD 2y agoDoesn't GCC have long-standing bugs where it a) doesn't support assigning some select registers, and b) when you try to use them anyway, it instead completely ignores your annotations with no diagnostics, and c) when it gets reported on GCC's bug tracker, a maintainer would reply with "well, it's always been like that and everyone knows you can't use this register like that anyway" and close it as WONTFIX? I distinctly remember reading about something like that...
- fwsgonzo 2y agoPerhaps, but I can't imagine its buggy for general registers like those used in system calls. I haven't seen that bug, but I don't doubt it. There's many obscure registers for various architectures that could bug out.
- saagarjha 2y agoI’d really prefer using inline assembly tbh
- armitron 2y agoIdiomatic to you perhaps, to me this looks ridiculous and unnecessary, bordering on masochistic.