Example Usage
var bufferList = new Arm64InstructionBufferByList();
var asm = new Arm64Assembler(bufferList);
// // Main entry point
// _start:
var labelStart = asm.CreateLabelId("_start");
asm.BindLabel(labelStart);
// mov x0, #5 // Call sum_loop(5)
asm.MOVZ(X0, 5);
// bl sum_loop // Call the function, result in x0
var labelSumLoop = asm.CreateLabelId("sum_loop");
asm.BL(labelSumLoop);
//
// // Do something with result (for now, just returning)
// ret // Return from _start (normally would return to a caller)
asm.RET();
//
//
// // Function: sum_loop(x0)
// // - Takes x0 as the loop limit
// // - Returns the sum in x0
// sum_loop:
asm.BindLabel(labelSumLoop);
// mov x1, #0 // Accumulator (sum)
asm.MOVZ(X1, 0);
// mov x2, #0 // Counter
asm.MOVZ(X2, 0);
//
// loop_start:
var labelLoopStart = asm.CreateLabelId("loop_start");
asm.BindLabel(labelLoopStart);
// add x1, x1, x2 // Add counter (x2) to sum (x1)
asm.ADD(X1, X1, X2);
// add x2, x2, #1 // Increment counter
asm.ADD(X2, X2, 1);
//
// cmp x2, x0 // Compare counter with limit
asm.CMP(X2, X0);
// blt loop_