VOOZH about

URL: https://qiita.com/ohisama@github/items/402d5db54b84b46516f5

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


👁 Image
2

Go to list of users who liked

2

Share on X(Twitter)

Share on Facebook

Add to Hatena Bookmark

More than 5 years have passed since last update.

@ohisama@github

アセンブラからcの関数

2
Posted at

概要

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

サンプルコード

import subprocess
import os

def gcc():
	s_file = 'main.s'
	test_s = """
.code32
.text
.extern test
.global main
main:
	call test
	mov		$4, %eax
	mov		$1, %ebx
	mov	 	$msg, %ecx
	mov 	$6, %edx
	int	 	$0x80
	ret
.data
msg:
	.ascii 	"hello "
"""
	with open(s_file, 'w') as f:
		f.write(test_s)
	c_file = 'test.c'
	test_c = """
# include <stdio.h>	
void test()
{
	printf("world!");
}
"""
	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()




成果物

以上。

2

Go to list of users who liked

2
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
2

Go to list of users who liked

2