1
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 3 years have passed since last update.

アセンブラからcの関数 その2

Last updated at Posted at 2020-03-06

#概要

アセンブラからcの関数、呼び出して見た。
x64で、やって見た。

#サンプルコード

import subprocess
import os

def gcc():
	s_file = 'main.s'
	test_s = """
.code64
.global main
.text
main:
    call    test
    mov     $message, %rdi
    call    puts
    ret
.data   
message:
    .asciz "world!"
"""
	with open(s_file, 'w') as f:
		f.write(test_s)
	c_file = 'test.c'
	test_c = """
#include <stdio.h>	
void test()
{
	printf("hello ");
}
"""
	with open(c_file, 'w') as f:
		f.write(test_c)
	os.system("gcc -no-pie test.c main.s")
	os.system("./a.out")

if __name__ == '__main__':
    gcc()




#成果物

以上。

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