0
0

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 1 year has passed since last update.

paizaでアセンブラ その16

Last updated at Posted at 2022-10-18

概要

paizaでアセンブラ、やってみた。
アセンブラ、見つけたので、やってみた。

参考にしたページ

paiza.ioでやってみた。

動きませんでした。

import subprocess
import os

def gcc():
    c_file = 'test.s'
    test_c = """
.code64
.text
.globl main
main:
    mov $1, %al     ; sys_write のシステムコール番号
    mov $1, %dil    ; 標準出力のファイルディスクリプタ
    lea hello, %rsi ; 書き出すデータのアドレス
    mov $len, %dl   ; 書き出す文字数
    syscall         ; sys_write の実行
    mov $60, %al    ; sys_exit のシステムコール番号
    mov $0, %dil    ; 終了ステータス
    syscall         ; sys_exit の実行
.data
hello:
    .ascii  "hello, world"
.set    len, . - hello
"""
    with open(c_file, 'w') as f:
        f.write(test_c)
    #os.system("cat test.s")
    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 = """
.code64
.text
.globl main
main:
    mov $1, %rax
    mov $1, %rdi
    lea hello, %rsi
    mov $12, %rdx
    syscall       
    mov $60, %rax
    mov $0, %rdi 
    syscall
.data
hello:
    .ascii  "hello, world"

"""
    with open(c_file, 'w') as f:
        f.write(test_c)
    #os.system("cat test.s")
    os.system("gcc -no-pie %s" % c_file)
    os.system("./a.out")
    #os.system("ls")
    
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?