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?

中古ノート、買ってみた。 その70

0
Last updated at Posted at 2025-11-19

概要

中古ノート買ってみた。
wsl1のubuntu18.04にnasm入れてみた。
forthコンパイラ、見つけたのでやってみた。

参考にしたページ

手順

paiza.ioのpython3でコンパイル。

投入したソースコード

6 3 + 2 - . 3 4 * 2 / 1 + . 2 3 drop dup dup 1 + + + 7 dup . . .

生成されたアセンブラ

 .text
    .globl main
main:
    pushq %rbp
    movq %rsp, %rbp

    pushq $6
    pushq $3
    popq %rax
    addq %rax, (%rsp)
    pushq $2
    popq %rax
    subq %rax, (%rsp)
    popq %rsi
    leaq IO, %rdi
    movq $0, %rax
    callq printf
    pushq $3
    pushq $4
    popq %rax
    imulq (%rsp), %rax
    movq %rax, (%rsp)
    pushq $2
    popq %rbx
    popq %rax
    cqto
    idivq %rbx
    pushq %rax
    pushq $1
    popq %rax
    addq %rax, (%rsp)
    popq %rsi
    leaq IO, %rdi
    movq $0, %rax
    callq printf
    pushq $2
    pushq $3
    addq $8, %rsp
    movq (%rsp), %rax
    pushq %rax
    movq (%rsp), %rax
    pushq %rax
    pushq $1
    popq %rax
    addq %rax, (%rsp)
    popq %rax
    addq %rax, (%rsp)
    popq %rax
    addq %rax, (%rsp)
    pushq $7
    movq (%rsp), %rax
    pushq %rax
    popq %rsi
    leaq IO, %rdi
    movq $0, %rax
    callq printf
    popq %rsi
    leaq IO, %rdi
    movq $0, %rax
    callq printf
    popq %rsi
    leaq IO, %rdi
    movq $0, %rax
    callq printf
    movq $0, %rax
    leaveq
    retq
    .data
IO:
    .string "%lld"

ubuntuで、アセンブル、実行


# gcc -o forth0 forth0.s -no-pie

# ./forth0
77777


成果物

以上。

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?