You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Run machine code, assembly and webassembly directly in Python.
Have you ever realized you can't remember how to add numbers in Python but you do remember how to do it in assembly?
If the answer is yes this is the package for you, using pyas you will be able to run machine code, assembly and webassembly directly from within Python!
Warning
currently this only supports Linux and pyscript
frompyasimportfunctionadd_one=function(
'8b c7'# mov eax, edi'83 c0 01'# add eax, 1'c3'# ret
)
return_same=function(
''' 8b c7 # mov eax, edi c3 // ret '''
)
print(add_one(10), "=", return_same(10), "+ 1")
# output: 11 = 10 + 1add_numbers=lambdai, val: function(
''' 8b c7 ; mov eax, edi 83 c0 %.2x # add eax, i c3 // ret '''%i,
val# every value after the first argument will be passed directly to the function if supplied
)
print(add_numbers(4, 10), "=", "10 + 4")
# output: 14 = 10 + 4
Assembly
frompyasimportfunctionadd_one=function(
''' mov eax, edi add eax, 1 ret ''',
raw=False
)
return_same=function(
''' mov eax, edi ret ''',
raw=False
)
print(add_one(10), "=", return_same(10), "+ 1")
# output: 11 = 10 + 1add_numbers=lambdai, val: function(
''' mov eax, edi add eax, %d ret '''%i,
val, # every value after the first argument will be passed directly to the function if suppliedraw=False
)
print(add_numbers(4, 10), "=", "10 + 4")
# output: 14 = 10 + 4
WebAssembly
pyas will automatically recognize running in a web browser and will run Webassembly, but you'll have to specify a func_name.