VOOZH about

URL: https://qiita.com/DQNEO/items/d450a3c43f55b79f292b

⇱ アセンブラ(32bit)でhello world #x86 - Qiita


👁 Image
7

Go to list of users who liked

6

Share on X(Twitter)

Share on Facebook

Add to Hatena Bookmark

More than 5 years have passed since last update.

@DQNEO(DQNEO)in👁 Image
Mercari

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

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

Go to list of users who liked

6
0

Go to list of comments

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
7

Go to list of users who liked

6