VOOZH about

URL: https://qiita.com/ohisama@github/items/e28a71654954865638ec

⇱ アセンブラからcの関数 その2 #GCC - Qiita


👁 Image
1

Go to list of users who liked

0

Share on X(Twitter)

Share on Facebook

Add to Hatena Bookmark

More than 5 years have passed since last update.

@ohisama@github

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

1
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

Go to list of users who liked

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

Go to list of users who liked

0