LoginSignup
0
0

More than 3 years have passed since last update.

paizaでアセンブラ その8

Posted at

概要

paizaでアセンブラ、やってみた。
code32でやってみた。

閃きのイメージ

python2で書いてます。

サンプルコード

import subprocess
import os

def gcc():
    c_file = 'test.s'
    test_c = """
.code32
.text   
.globl  main

main:
    movl    $4, %eax
    movl    $1, %ebx
    movl    $msg, %ecx
    movl    $6, %edx
    int     $0x80
    movl    $1, %eax
    int     $0x80

.data
msg:
    .byte   104
    .byte   101
    .byte   108
    .byte   108
    .byte   111
    .byte   10
"""
    with open(c_file, 'w') as f:
        f.write(test_c)
    os.system("gcc -no-pie %s" % c_file)
    os.system("./a.out")
    os.system("ls")

if __name__ == '__main__':
  gcc()


成果物

サンプルコード

import subprocess
import os

def gcc():
    c_file = 'test.s'
    test_c = """
.code32
.text
.global main

main:
    mov     $msg, %edi
    call    puts
    ret

.data   
msg:
    .asciz "hello world!"
"""
    with open(c_file, 'w') as f:
        f.write(test_c)
    os.system("gcc -no-pie %s" % c_file)
    #os.system("file a.out")
    os.system("./a.out")

if __name__ == '__main__':
  gcc()

成果物

以上。

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