Show HN:Torque——一款适用于任何处理器的轻量级元汇编器
Show HN: Torque – A lightweight meta-assembler for any processor

原始链接: https://benbridle.com/projects/torque.html

Torque 是一款轻量级、通用的元汇编器,旨在解决现有汇编器,特别是针对嵌入式处理器的不足之处。它旨在提供一个单一的、文档完善且高效的工具,可用于各种架构和操作系统。Torque 通过在汇编程序本身中将指令编码定义为宏来实现这一点,利用整数、位序列、标签和强大的宏来模拟基于处理器数据手册的任何汇编语言。 Torque 使用 Rust 编程语言构建。您可以从 code.benbridle.com/torque-asm 下载源代码或预编译的 Linux 可执行文件。要从源代码构建,请安装 Rust 的 nightly 工具链。使用命令 `tq [源文件] [目标文件] --format=<格式>` 将源文件汇编成指定的目标格式。完整文档可在用户手册 (v2.1.0) 中找到。Torque 旨在通过提供通用的汇编器解决方案来简化嵌入式开发。

Benbridle最近在Hacker News上发布了Torque,这是一个轻量级的“元汇编器”,旨在适用于各种不同的处理器架构。与传统的汇编器不同,Torque没有内置指令集。用户可以使用宏从比特级开始定义自己的指令集,从而创建针对目标处理器的定制语言。这允许完全控制,并消除了对字宽、指令格式或字节序的假设。 Benbridle开发Torque是为了克服在使用PIC微控制器官方汇编器时遇到的限制。他还成功地用它来编程TRS-80电脑中的Z80处理器。该项目旨在为汇编编程提供一个灵活且适应性强的解决方案,无论底层架构如何。他邀请用户试用并提供反馈。

原文

Torque is a lightweight meta-assembler that provides the tools necessary to write programs for any processor architecture.

For a quick overview of the language, either read the language overview section of the manual, see this example of a completed program, or skim one of the following hands-on tutorials:

For a demonstration of how to write high-level optimising macros in Torque, see:

Background

Existing assemblers for embedded processors suffer from a number of issues. Assemblers tend to be poorly documented, provide languages that are clunky and verbose, be bloated and difficult to operate, and work only on one operating system. Development of C compilers is often a higher priority than the development of good assemblers.

Instead of learning a new assembler for every embedded processor, it would be preferrable to instead use a single general-purpose assembler for every project. Torque was created to fill this niche.

Design

Torque is designed around the idea that any assembly language can be emulated with just integers, bit sequences, labels, and sufficiently powerful macros. With Torque, the instruction encoding for a target processor can be defined as a set of macros in the program itself, using templates to specify how values are packed into ranges of bits. A program can be written for any processor using only Torque and the datasheet for that processor.

Installation

Source code for the torque assembler can be downloaded from code.benbridle.com/torque-asm.

The latest release is available at tq-2.1.0 as a pre-compiled Linux executable.

Build from source

To build the Torque assembler from source, first install the Rust compiler from www.rust-lang.org/tools/install, then install the nightly toolchain with rustup toolchain install nightly, and then run cargo +nightly build --release inside the torque-asm source code directory.

The compiled binary will be created at ./target/release/tq.

Usage

The following command will assemble the Torque source file source and save the assembled output to the file destination in the chosen format.

tq [source] [destination] --format=<format>

Documentation

  • Manual v2.1.0
    The full user manual for version 2.1.0 of the language and assembler.

Development

联系我们 contact @ memedata.com