srctree

Robin Linden parent 59ea1cb8 86f124d8
azm/example: Set up a binary for dumping the assembled code

inlinesplit
azm/BUILD added: 35, removed: 3, total 32
@@ -1,4 +1,4 @@
load("@rules_cc//cc:defs.bzl", "cc_library", "cc_test")
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
load("//bzl:copts.bzl", "HASTUR_COPTS")
 
cc_library(
@@ -20,3 +20,12 @@ cc_library(
) for src in glob(
include = ["*_test.cpp"],
)]
 
cc_binary(
name = "azm_example",
srcs = ["azm_example.cpp"],
copts = HASTUR_COPTS,
deps = [
":azm",
],
)
 
filename was Deleted added: 35, removed: 3, total 32
@@ -0,0 +1,23 @@
// SPDX-FileCopyrightText: 2023 Robin Lindén <dev@robinlinden.eu>
//
// SPDX-License-Identifier: BSD-2-Clause
 
#include "azm/assembler.h"
 
#include <algorithm>
#include <iostream>
#include <iterator>
 
int main() {
using namespace azm;
Amd64Assembler assembler;
assembler.mov(Reg32::Eax, Imm32{0xdeadbeef});
assembler.mov(Reg32::Ecx, Imm32{0x4321});
assembler.mov(Reg32::Edx, Imm32{0x12345678});
assembler.mov(Reg32::Ebx, Imm32{0x1234});
assembler.ret();
auto code = assembler.take_assembled();
// Print the machine code in a format usable for something like
// `objdump -D -b binary -mi386:x86-64 -Mintel <file>`.
std::ranges::copy(code, std::ostreambuf_iterator<char>(std::cout));
}