LoginSignup
0
0

More than 5 years have passed since last update.

paizaでアセンブラ その7

Last updated at Posted at 2019-01-13

概要

paizaでアセンブラ、やってみた。
クワインとやらをやってみる。

参考にしたページ

サンプルコード

python2です。

import subprocess
import os

def gcc():
    p_file = 'quine.S'
    test_p = """
.text
.global main
main:    
mov $1,%eax
mov $1,%edi
mov $m,%esi
mov $138,%edx
syscall
mov $60,%eax
dec %edi
syscall
m:.incbin "quine.S"
"""
    with open(p_file, 'w') as f:
        f.write(test_p)
    c_file = 'fizzbuzz.s'
    test_c = """
.text
.global main
main:    
mov $1,%eax
mov $1,%edi
mov $m,%esi
mov $138,%edx
syscall
mov $60,%eax
dec %edi
syscall
m:.incbin "quine.S"
"""
    with open(c_file, 'w') as f:
        f.write(test_c)
    os.system("gcc -no-pie %s" % c_file)
    os.system("uname -a")
    os.system("gcc --version")
    result = subprocess.Popen('./a.out', stdout = subprocess.PIPE).communicate()[0]
    for i, v in enumerate(result[ : -1].split('\n')):
        print v

if __name__ == '__main__':
  gcc()


実行結果

Linux 8e7123c5ab55 4.15.0-1025-aws #25-Ubuntu SMP Wed Oct 10 14:23:49 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
gcc (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


.text
.global main
main:    
mov $1,%eax
mov $1,%edi
mov $m,%esi
mov $138,%edx
syscall
mov $60,%eax
dec %edi
syscall
m:.incbin "quine.S"

成果物

以上。

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