Files
Nim/tests/compiler/tasm.nim
Tomohiro fc806710cb Add inline assembler tests for i386, arm, arm64, riscv32 and riscv64 (#24564)
This fixes one error in https://github.com/nim-lang/Nim/issues/24544 .
I tested this on Raspberry Pi Pico (arm) and Raspberry Pi 3(arm64).
It is not tested on i386, riscv32 and riscv64 CPU.
2024-12-24 23:11:19 +08:00

29 lines
581 B
Nim

proc testAsm() =
let src = 41
var dst = 0
when defined(i386) or defined(amd64):
asm """
mov %1, %0\n\t
add $1, %0
: "=r" (`dst`)
: "r" (`src`)"""
elif defined(arm) or defined(arm64):
asm """
mov %0, %1\n\t
add %0, %0, #1
: "=r" (`dst`)
: "r" (`src`)"""
elif defined(riscv32) or defined(riscv64):
asm """
addi %0, %1, 0\n\t
addi %0, %0, 1
: "=r" (`dst`)
: "r" (`src)"""
doAssert dst == 42
when defined(gcc) or defined(clang) and not defined(cpp):
{.passc: "-std=c99".}
testAsm()