mirror of
https://github.com/cirosantilli/linux-kernel-module-cheat.git
synced 2026-01-29 21:14:27 +01:00
asm: start intrinsics examples
Split userland/arch/<arch>/c/ into inline_asm and intrinsics, and move programs that don't match either up.
This commit is contained in:
22
userland/arch/x86_64/inline_asm/scratch_hardcode.c
Normal file
22
userland/arch/x86_64/inline_asm/scratch_hardcode.c
Normal file
@@ -0,0 +1,22 @@
|
||||
/* This is a worse version of scratch.c with hardcoded scratch.
|
||||
* https://github.com/cirosantilli/linux-kernel-module-cheat#gcc-inline-assembly-scratch-registers
|
||||
*/
|
||||
|
||||
#include <assert.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
int main(void) {
|
||||
uint64_t in1 = 0xFFFFFFFF;
|
||||
uint64_t in2 = 1;
|
||||
uint64_t out;
|
||||
__asm__ (
|
||||
"mov %[in2], %%rax;" /* scratch = in2 */
|
||||
"add %[in1], %%rax;" /* scratch += in1 */
|
||||
"mov %%rax, %[out];" /* out = scratch */
|
||||
: [out] "=r" (out)
|
||||
: [in1] "r" (in1),
|
||||
[in2] "r" (in2)
|
||||
: "rax"
|
||||
);
|
||||
assert(out == 0x100000000);
|
||||
}
|
||||
Reference in New Issue
Block a user