6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

アセンブラ(32bit)でhello world

Last updated at Posted at 2014-11-24

巷のアセンブリ入門とかを見ると、hello worldするのにlibcのprintfを呼んでいる例が多くて、「それアセンブリちゃうやんけC言語やんけ」という気持ちになってきます。

というわけでwrite(2)を直接叩くhello worldを書いてみました。

/**
 * Linux i386でのhello world
 * 実行方法:
 * gcc -o hello hello.s
 * ./hello
 *
 */
.file   "hello.s"
        .data
        //ここからスタート
        .global main
main:
        pushl  %ebp
        movl %esp, %ebp
        movb $0x00, -1(%ebp) # \0
        movb $0x0A, -2(%ebp) # \n
        movb $0x6f, -3(%ebp) # o
        movb $0x6c, -4(%ebp) # l
        movb $0x6c, -5(%ebp) # l
        movb $0x65, -6(%ebp) # e
        movb $0x68, -7(%ebp) # h

        movl $4,        %eax   # sys_write
        movl $1,        %ebx   # stdout
        leal -7(%ebp),  %ecx   # address of 'h'
        movl $7,        %edx   # len 7
        int  $0x80             # system call

        popl  %ebb  # おまじない
        ret
6
6
1

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
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?