Git Product home page Git Product logo

as_tanka_codejp's Introduction

"CodeJP"アセンブラ短歌

TrelloのCode 2016 企画できんぎょばちにこっそり挙げていた「アセンブラ短歌」を勝手にやってみました。

b8 03 00 cd 10
b3 0f b9 06 00 b8 c0 07
8e c0 bd 19 00
b8 01 13 cd 10 eb fe
43 6f 64 65 4a 50

五・八・五・七・六で、一応、合計三十一バイト(みそひとバイト)です。

バイナリの内容について

上記のバイナリはOSレスでQEMU上に"CodeJP"と表示するプログラムです。

三十一バイトにコード(textセクション)とデータ(dataセクション)を含んでいます。

最後の6バイトがデータで、内容は"CodeJP"のアスキーコードです。

アスキーコード部分を文字で表すと以下のようになり、

b8 03 00 cd 10
b3 0f b9 06 00 b8 c0 07
8e c0 bd 19 00
b8 01 13 cd 10 eb fe
'C' 'o' 'd' 'e' 'J' 'P'

「ほにゃららほにゃらら・・CodeJP」と最後に"CodeJP"のアスキー値で締められている所がいい感じかなと思っています。

試し方

Makefileを同梱しており、make runでビルド・実行が行えます。(要GCC、Make、QEMU)

as_tanka_codejp.img について

最終生成物であり、QEMUが実行する対象であるas_tanka_codejp.img自体は512バイトあります。

これは、BIOSにディスクの先頭512バイトをMBR(Master Boot Record)である(実行するものである)と認識させるには、先頭から510バイト目に0xaa55を配置する必要があるためです。

as_tanka_codejp.imgの逆アセンブル結果は、以下のコマンドで確認できます。

$ objdump -D -b binary -mi386 -Maddr16,data16 as_tanka_codejp.img

as_tanka_codejp.img: ファイル形式 binary

セクション .data の逆アセンブル:

00000000 <.data>:
   0:   b8 03 00                mov    $0x3,%ax
   3:   cd 10                   int    $0x10
   5:   b3 0f                   mov    $0xf,%bl
   7:   b9 06 00                mov    $0x6,%cx
   a:   b8 c0 07                mov    $0x7c0,%ax
   d:   8e c0                   mov    %ax,%es
   f:   bd 19 00                mov    $0x19,%bp
  12:   b8 01 13                mov    $0x1301,%ax
  15:   cd 10                   int    $0x10
  17:   eb fe                   jmp    0x17
  19:   43                      inc    %bx
  1a:   6f                      outsw  %ds:(%si),(%dx)
  1b:   64 65 4a                fs gs dec %dx
  1e:   50                      push   %ax
        ...
 1fb:   00 00                   add    %al,(%bx,%si)
 1fd:   00 55 aa                add    %dl,-0x56(%di)
  • CPU起動直後のモードであるリアルモード(16ビットモード)の実行バイナリなので、objdumpに16ビットとして認識させるオプションを付けています

as_tanka_codejp.Sを見るとわかりますが、jmp 0x17がアセンブラのコードの最後で、それ以降はアスキーコードをobjdumpが無理やり命令として逆アセンブルしています。

データの最後である'P'(0x50)までで0x1f(31)であり、一応、三十一バイトに収まっています。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.