2
2

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の関数

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

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
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?