0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

bfソースをスーパーコンピュータ富岳のaarch64 assemblyにトランスパイル

0
Last updated at Posted at 2026-03-26

bfソースをaarch64アセンブリにトランスパイルします。
上記のトランスパイラで、次のように変換してください。

./lgbt.py map.a64fx.json header.a64fx.s hello.bf tailor.a64fx.s >hello.arm64.s

アセンブラを通りました。Claudeから、これで動くとOkをもらいました。それと、人伝で試してもらって、動くと言われました。
brainfuckソースは何でも良いですので、mandelbrot.bfでやってみるのもいいでしょう。スーパーコンピュータでbrainfuckのプログラムが動くなんて、愉快ではないですか。富岳はaarch64でしたが、frontierはx86_64アーキテクチャだったはず。frontierでも、x86_64トランスパイルを通すと、bfのソースが動きます。

トランスパイルされたソースを、FreeBSDでアセンブルするのは次のようにします。

% llvm-mc -triple=aarch64-unknown-freebsd -filetype=obj hello.aarch64.s -o hello.o
%

map file

map.a64fx.json
{
    ">": "add x19, x19, #1\n",
    "<": "sub x19, x19, #1\n",
    "+": [  "ldrb w0, [x19]",
            "add w0, w0, #1",
            "strb w0, [x19]" ],
    "-": [  "ldrb w0, [x19]",
            "sub w0, w0, #1",
            "strb w0, [x19]" ],
    ".": [  "mov x0, #1",
            "mov x1, x19",
            "mov x2, #1",
            "mov x8, #64",
            "svc #0" ] ,
    ",": [  "mov x0, #0",
            "mov x1, x19",
            "mov x2, #1",
            "mov x8, #63",
            "svc #0" ],
    "[": [  "openlabel:",
            "ldrb w0, [x19]",
            "cbz w0, closelabel" ] ,
    "]": [  "b openlabel",
            "closelabel:" ]
}

headerfile

header.a64fx.s
.section .text
    .globl _start
_start:
    adrp    x19, _my_data
    add     x19, x19, :lo12:_my_data

tailor file

tailor.a64fx.s
    mov     x0, #0
    mov     x8, #93
    svc     #0
    .section .bss
_my_data:
    .zero   65536

hello.bf

hello.bf
>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]
>++++++++[<++++>-] <.>+++++++++++[<++++++++>-]<-.--------.+++
.------.--------.[-]>++++++++[<++++>- ]<+.[-]++++++++++.

トランスパイル後の結果ファイル

hello.arm64.s
.section .text
    .globl _start
_start:
    adrp    x19, _my_data
    add     x19, x19, :lo12:_my_data
add x19, x19, #1
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
LB1:
ldrb w0, [x19]
cbz w0, LE1

sub x19, x19, #1
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
add x19, x19, #1
ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
b LB1
LE1:

sub x19, x19, #1
mov x0, #1
mov x1, x19
mov x2, #1
mov x8, #64
svc #0
add x19, x19, #1
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
LB2:
ldrb w0, [x19]
cbz w0, LE2

sub x19, x19, #1
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
add x19, x19, #1
ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
b LB2
LE2:

sub x19, x19, #1
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
mov x0, #1
mov x1, x19
mov x2, #1
mov x8, #64
svc #0
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
mov x0, #1
mov x1, x19
mov x2, #1
mov x8, #64
svc #0
mov x0, #1
mov x1, x19
mov x2, #1
mov x8, #64
svc #0
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
mov x0, #1
mov x1, x19
mov x2, #1
mov x8, #64
svc #0
LB3:
ldrb w0, [x19]
cbz w0, LE3

ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
b LB3
LE3:

add x19, x19, #1
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
LB4:
ldrb w0, [x19]
cbz w0, LE4

sub x19, x19, #1
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
add x19, x19, #1
ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
b LB4
LE4:

sub x19, x19, #1
mov x0, #1
mov x1, x19
mov x2, #1
mov x8, #64
svc #0
add x19, x19, #1
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
LB5:
ldrb w0, [x19]
cbz w0, LE5

sub x19, x19, #1
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
add x19, x19, #1
ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
b LB5
LE5:

sub x19, x19, #1
ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
mov x0, #1
mov x1, x19
mov x2, #1
mov x8, #64
svc #0
ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
mov x0, #1
mov x1, x19
mov x2, #1
mov x8, #64
svc #0
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
mov x0, #1
mov x1, x19
mov x2, #1
mov x8, #64
svc #0
ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
mov x0, #1
mov x1, x19
mov x2, #1
mov x8, #64
svc #0
ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
mov x0, #1
mov x1, x19
mov x2, #1
mov x8, #64
svc #0
LB6:
ldrb w0, [x19]
cbz w0, LE6

ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
b LB6
LE6:

add x19, x19, #1
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
LB7:
ldrb w0, [x19]
cbz w0, LE7

sub x19, x19, #1
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
add x19, x19, #1
ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
b LB7
LE7:

sub x19, x19, #1
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
mov x0, #1
mov x1, x19
mov x2, #1
mov x8, #64
svc #0
LB8:
ldrb w0, [x19]
cbz w0, LE8

ldrb w0, [x19]
sub w0, w0, #1
strb w0, [x19]
b LB8
LE8:

ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
ldrb w0, [x19]
add w0, w0, #1
strb w0, [x19]
mov x0, #1
mov x1, x19
mov x2, #1
mov x8, #64
svc #0
    mov     x0, #0
    mov     x8, #93
    svc     #0
    .section .bss
_my_data:
    .zero   65536

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?