Files

64 lines
1.2 KiB
ArmAsm

// Copyright (c) 2026 Petr Balvín <opensource@petrbalvin.org> (https://petrbalvin.org)
// SPDX-License-Identifier: BSD-3-Clause
#include "textflag.h"
// add returns a + b.
TEXT ·add(SB), NOSPLIT, $0-24
MOVV a+0(FP), R4
MOVV b+8(FP), R5
ADDV R5, R4, R4
MOVV R4, ret+16(FP)
RET
// arith exercises the 3R integer and FP set.
TEXT ·arith(SB), NOSPLIT, $0-0
ADDV R4, R5, R6
SUBV R7, R8, R9
MULV R10, R11, R12
DIVV R13, R14, R15
AND R16, R17, R18
OR R18, R19, R20
XOR R20, R21, R2
SLLV R2, R23, R24
SRLV R24, R25, R26
SRAV R26, R27, R28
RET
// imm exercises the immediate forms.
TEXT ·imm(SB), NOSPLIT, $0-0
ADDV $42, R4, R5
ADDV $-8, R6
AND $0xff, R7, R8
OR $1, R9, R10
XOR $0, R11, R12
SGT $100, R13, R14
SLLV $4, R15, R16
MOVV $0x12345, R17
RET
// branch exercises conditional and unconditional control flow. Every
// path must terminate: the smoke harness calls functions with a zeroed
// argument block, and a $0-0 function's registers carry whatever the
// caller left, so a branch maze can reach any label.
TEXT ·branch(SB), NOSPLIT, $0-0
BEQ R4, R5, done
BNE R6, R7, skip
BLT R8, R9, done
BGE R10, R11, done
BLTU R12, R13, done
BGEU R14, R15, done
skip:
JMP loop
loop:
JAL fin
RET
fin:
RET
done:
RET