Call a foreign-language function: Difference between revisions
Add Standard ML version using PolyML
Puppydrum64 (talk | contribs) |
(Add Standard ML version using PolyML) |
||
(17 intermediate revisions by 7 users not shown) | |||
Line 17:
* [[Use another language to call a function]]
<br><br>
=={{header|8th}}==
<syntaxhighlight lang="forth">
\ tell 8th what the function expects:
"ZZ" "strdup" func: strdup
"VZ" "free" func: free
\ call the external funcs
"abc" dup \ now we have two strings "abc" on the stack
strdup .s cr \ after strdup, you'll have the new (but duplicate) string on the stack
\ the ".s" will show both strings and you can see they are different items on the stack
free \ let the c library free the string
</syntaxhighlight>
=={{header|68000 Assembly}}==
{{works with|Sega Genesis}}
Line 26 ⟶ 36:
'''Z80 Code:'''
<
jr start
Line 55 ⟶ 65:
ExampleFunction: ;ADDR: &0072($A00072)
ret ;for simplicity this does nothing but in reality you'd have it do something sound-related here.</
Here's the 68000 code that will get the Z80 to call this function:
<
MOVE.W #$100,$A11100 ;write: z80 reset
.wait:
Line 74 ⟶ 84:
MOVE.B #$FF,$A01F01 ;unlock the semaphore
MOVE.W #0,$A11100 ;Z80 Bus Request - after this write, the Z80 will start executing code.</
=={{header|Ada}}==
Ada provides standard interfaces to [[C]], [[C++]], [[Fortran]] and [[Cobol]]. Other language interfaces can be provided as well, but are not mandatory. Usually it is possible to communicate to any language that supports calling conventions standard to the [[OS]] ('''cdecl''', '''stdcall''' etc).
<
with Interfaces.C; use Interfaces.C;
with Interfaces.C.Strings; use Interfaces.C.Strings;
Line 104 ⟶ 101:
Put_Line (Value (S2));
Free (S2);
end Test_C_Interface;</
=={{header|Aikido}}==
There are two ways to call a <em>native</em> function in Aikido. The first is to write a wrapper function in C++ that is invoked from the Aikido interpreter. In a C++ file:
<
extern "C" { // need C linkage
Line 120 ⟶ 116:
}
}</
Then in the Aikido program:
<
println (strdup ("Hello World!"))</
The second way is to use a <em>raw native</em> function. These functions must adhere to a defined set of rules and can be called directly from the Aikido interpreter. In the case of <code>strdup</code> we need to play a nasty trick because it returns a pointer that we need to print as a string.
<
native function free(p) // also need to free the result
Line 141 ⟶ 137:
p++
}
free (s) // done with the memory now</
=={{header|ALGOL 68}}==
The designers of Algol 68 made it extremely hard to incorporate code written in other languages. To be fair, this was a long time ago when such considerations weren't thought important and one should be careful to apply Hanlon's razor.
Line 149 ⟶ 144:
Note that I chose a non-trivial library function because the suggested strdup() doesn't really demonstrate the technique all that well.
<
BEGIN
MODE PASSWD = STRUCT (STRING name, passwd, INT uid, gid, STRING gecos, dir, shell);
Line 217 ⟶ 212:
FI
END
</syntaxhighlight>
{{out}}
<pre>
root:x:0:0:root:/root:/bin/bash
</pre>
=={{header|ARM Assembly}}==
{{works with|as|Raspberry Pi}}
<syntaxhighlight lang="arm assembly">
/* ARM assembly Raspberry PI */
Line 279 ⟶ 273:
pop {r0,r1,r2,r7,lr} @ restaur des 2 registres */
bx lr @ return
</syntaxhighlight>
=={{header|Arturo}}==
'''C Library'''
<
// clang -c -w mylib.c
// clang -shared -o libmylib.dylib mylib.o
Line 297 ⟶ 290:
int doubleNum(int num){
return num * 2;
}</
'''Calling from Arturo'''
<
call.external: "mylib" 'sayHello ["John"]
Line 314 ⟶ 307:
loop 1..3 'x [
print ["The double of" x "is" doubleNum x]
]</
{{out}}
Line 322 ⟶ 315:
The double of 2 is 4
The double of 3 is 6 </pre>
=={{header|AutoHotkey}}==
from the documentation for dllcall: <
WhichButton := DllCall("MessageBox", "int", "0", "str", "Press Yes or No", "str", "Title of box", "int", 4)
MsgBox You pressed button #%WhichButton%.</
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<
SYS "GetProcAddress", msvcrt%, "_strdup" TO `strdup`
SYS "GetProcAddress", msvcrt%, "free" TO `free`
Line 338 ⟶ 329:
PRINT $$address%
SYS `free`, address%
</syntaxhighlight>
=={{header|C}}==
===Assembly via GCC===
Assembly code can be embedded and compiled via GCC.
<syntaxhighlight lang="c">
#include <stdlib.h>
#include <stdio.h>
Line 368 ⟶ 358:
return 0 ;
}
</syntaxhighlight>
Output:
<pre>
Line 381 ⟶ 371:
===Python===
'''IMPORTANT''' : The following implementation has been tested against Python 2.7, this won't work on a system which does not have the relevant files installed. Also pay attention to the compilation flags.
<
int main()
Line 396 ⟶ 386:
Py_Finalize();
return 0;
}</
'''Compilation''' : Change 2.7 and relevant paths for a different Python version / different install location
<pre>
Line 408 ⟶ 398:
First 10 multiples of 3 in reverse order : [30, 27, 24, 21, 18, 15, 12, 9, 6, 3]
</pre>
=={{header|C++}}==
While calling C functions from C++ is generally almost trivial, <code>strdup</code> illustrates some fine point in communicating with C libraries. However, to illustrate how to generally use C functions, a C function <code>strdup1</code> is used, which is assumed to have the same interface and behaviour as strdup, but cannot be found in a standard header.
In addition, this code demonstrates a call to a FORTRAN function defined as
<
DOUBLE PRECISION MULTIPLY, X, Y</
Note that the calling convention of FORTRAN depends on the system and the used FORTRAN compiler, and sometimes even on the command line options used for the compiler; here, GNU Fortran with no options is assumed.
<
#include <string> // for C++ strings
#include <iostream> // for output
Line 457 ⟶ 446:
// free, not delete, nor delete[], nor operator delete
std::free(msg2);
}</
=={{header|Clojure}}==
{{libheader|clojure-jna}}
Since Clojure is hosted on the JVM, you can follow the same approach as the [[#Java|Java]] solution and invoke your Java class from Clojure:
<
Alternatively, to avoid having to create a library in native code you could use JNA and the clojure-jna library for convenience. Here's how you can invoke ''strcmp'' from the libc shared library:
<
(jna/invoke Integer c/strcmp "apple" "banana" ) ; returns -1
Line 471 ⟶ 459:
(jna/invoke Integer c/strcmp "banana" "apple" ) ; returns 1
(jna/invoke Integer c/strcmp "banana" "banana" ) ; returns 0</
=={{header|CMake}}==
''This code uses a deprecated feature of CMake.'' In 2014, CMake 3.0 deprecated load_command(). CMake 3.0 can run this code but shows a deprecation warning. When a future version of CMake removes load_command(), this code will stop working, and there will be no way to call C functions from CMake.
Line 479 ⟶ 466:
'''CMakeLists.txt'''
<
project("outer project" C)
Line 503 ⟶ 490:
2012 / 500 = ${quot}
2012 % 500 = ${rem}
")</
'''div/CMakeLists.txt'''
<
project(div C)
Line 513 ⟶ 500:
# Compile cmDIV from div-command.c
add_library(cmDIV MODULE div-command.c)</
'''div/div-command.c'''
<
#include <stdio.h>
#include <stdlib.h>
Line 570 ⟶ 557:
info->InitialPass = initial_pass;
api = info->CAPI;
}</
=={{header|COBOL}}==
Tested with GnuCOBOL
<
program-id. foreign.
Line 601 ⟶ 587:
display "error calling free" upon syserr
end-if
goback.</
{{out}}
Line 609 ⟶ 595:
Hello, world
</pre>
=={{header|Common Lisp}}==
{{libheader|CFFI}}
<
(c-string (cffi:foreign-funcall "strdup" :string string :pointer)))
(unwind-protect (write-line (cffi:foreign-string-to-lisp c-string))
Line 620 ⟶ 605:
(values))
Hello World!
; No value</
=={{header|Crystal}}==
Crystal allows to easily interface with C functions, both from object files and shared libraries.
<
lib LibC
fun free(ptr : Void*) : Void
Line 635 ⟶ 619:
LibC.free p # pointer can be freed as String.new(Char*) makes a copy of data
puts s2</
=={{header|D}}==
<
import std.string: toStringz;
import std.conv: to;
Line 673 ⟶ 656:
free(str1);
free(str2);
}</
{{out}}
<pre>str1: Hello World!
str2: Hello World!</pre>
=={{header|Delphi}}==
===Importing the function from a shared library===
Line 687 ⟶ 669:
The file first has to be bound to your unit:
<
{$O myhello.obj}
</syntaxhighlight>
The next step is to do an external declaration for the function:
<
procedure Hello(S: PChar); stdcall; external;
</syntaxhighlight>
Afterwards usage of the function is just as with any other function.
=={{header|Ecstasy}}==
Ecstasy was designed around software containers and a strong security model. As such, Ecstasy does not have an FFI, and Ecstasy code cannot direcly access operating system or other foreign functions. More specifically, code running within an Ecstasy container cannot call foreign functions; any such required capabilities must be implemented outside of Ecstasy and then <i>injected</i> into an Ecstasy container.
=={{header|Factor}}==
Line 702 ⟶ 687:
libc is already loaded, it is used by Factor elsewhere.
<
: my-strdup ( str -- str' )
strdup [ utf8 alien>string ] [ (free) ] bi ;</
( scratchpad ) "abc" my-strdup .
"abc"
=={{header|FBSL}}==
Alongside its interpretative BASIC-style layer, FBSL also hosts built-in Intel-style Dynamic Assembler JIT and ANSI-C Dynamic C JIT compiler layers. BASIC, DynAsm and DynC procedures can be mixed freely to best suit the host script's intended purposes. The procedures follow their own respective syntaxes but are called in the host script in exactly the same way:
Line 776 ⟶ 760:
FBSL features a built-in stack balancing mechanism which eliminates stack corruption regardless of whether the API calls are using STDCALL or CDECL calling conventions. Please note that FBSL's BASIC and DynAsm '''do not''' make use of forward function declarations or header files.
=={{header|Forth}}==
{{works with|GNU Forth|0.7.0}}
Line 782 ⟶ 765:
Every version of GNU Forth has experimented with a different means to do C foreign function calls. The current implementation resolves various incompatibilities which had plagued earlier mechanisms by parsing C header files and using the host's native toolchain (i.e. gcc and ld) to generate thunks.
<
\c #include <string.h>
Line 804 ⟶ 787:
duped dup strlen type \ testing
duped free throw \ gforth ALLOCATE and FREE map directly to C's malloc() and free()</
=={{header|Fortran}}==
Since Fortran 2003, the standard provides the ISO_C_BINDING module to help interface with C programs. Before this, compiler vendors often provided nonstandard extensions to do this. Even with this new facility, some features, such as calling a STDCALL function on Windows, need some nonstandard extension.
Line 815 ⟶ 797:
Here is an example using the ISO_C_BINDING standard module to link against the C API functions ''strdup'', ''free'' and ''puts''. The program will print two copies of the string ''"Hello, World!"'' using the ''puts'' function. One copy is obtained from ''strdup'', then released with ''free''. The C bindings are placed in an interface module to simplify reuse. The addresses of the two copies are also printed.
<
use iso_c_binding
implicit none
Line 859 ⟶ 841:
transfer(ptr, 0_c_intptr_t)
call free(ptr)
end program</
=={{header|FreeBASIC}}==
Normally it's an easy matter to call a function in the C Standard Library, statically, from FreeBASIC.
Line 866 ⟶ 847:
As this uses LocalAlloc in kernel32.dll internally to allocate memory for the duplicated string, we need to call
LocalFree to free this memory using the pointer returned by strdup.
<
'Using StrDup function in Shlwapi.dll
Line 885 ⟶ 866:
DyLibFree(library) '' unload first dll
DyLibFree(library2) '' unload second fll
End</
{{out}}
<pre>
duplicate
</pre>
=={{header|FutureBasic}}==
The C Standary Library doesn't include the strdup() function. In the code below, strdup has been declared, written and executed in C. FB allows users to pass-through and compile C code, while it treating its execution as if it's native FB. That's what been chosen for this example.
<syntaxhighlight lang="futurebasic">
include "NSLog.incl"
BeginCDeclaration
char *strdup(const char *src);
EndC
BeginCFunction
char *strdup(const char *src) {
char *dst = malloc(strlen (src) + 1); // Space for length plus null
if (dst == NULL) return NULL; // No memory
strcpy(dst, src); // Copy the characters
return dst; // Return the new string
}
EndC
BeginCCode
NSLog( @"%s", strdup( "Hello, World!" ) );
EndC
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
Hello, World!
</pre>
=={{header|Go}}==
Using cgo, part of the standard Go command set.
<
// #include <string.h>
Line 921 ⟶ 931:
// demonstrate we have string contents intact
fmt.Println(go2)
}</
Output:
<pre>
hello C
</pre>
=={{header|Hare}}==
<
use fmt;
Line 943 ⟶ 952:
fmt::printfln("{}", strings::fromc(dup))!;
cfree(dup);
};</
=={{header|Haskell}}==
<
import Foreign (free)
Line 961 ⟶ 969:
s2_hs <- peekCString s2 -- marshall the C string called s2 into a Haskell string named s2_hs
putStrLn s2_hs
free s2) -- s is automatically freed by withCString once done</
==Icon and {{header|Unicon}}==
Line 969 ⟶ 977:
The first step is to create a shared library, to wrap the target C functions and do type conversions on the input and returned values. The arguments to the wrapper functions form a list, and this list must be unpacked to retrieve the arguments to send to the target function. To get at <code>strdup</code> and <code>strcat</code> we would have:
<syntaxhighlight lang="c">
#include <string.h>
#include "icall.h" // a header routine from the Unicon sources - provides helpful type-conversion macros
Line 988 ⟶ 996:
RetString (result);
}
</syntaxhighlight>
Then the Unicon program must 'access' the function in the shared library: the important step is 'loadfunc' which accesses the named function in the shared library. After that, the C function can be called from within a program:
<syntaxhighlight lang="unicon">
$define LIB "libstrdup-wrapper.so"
Line 1,016 ⟶ 1,024:
write (strcat ("abc", "def"))
end
</syntaxhighlight>
Output:
Line 1,024 ⟶ 1,032:
abcdef
</pre>
=={{header|J}}==
Here is a windows specific implementation (for relatively recent versions of windows):
<
strdup=: 'msvcrt.dll _strdup >x *' cd <
free=: 'msvcrt.dll free n x' cd <
getstr=: free ] memr@,&0 _1</
With these definitions:
<
Hello World!</
Portability is possible, but often irrelevant for a task of this sort. To make this work with a different OS, you would need to use the appropriate file name for libc for the os in question. For example, on linux, replace msvcrt.dll with /lib/libc.so.6 (or whichever version of libc you are using).
See also: [http://www.jsoftware.com/help/user/call_procedure.htm J's documentation]
=={{header|Java}}==
Java uses JNI to call other languages directly. Because it is a managed language, a "shim" layer needs to be created when dealing with things outside of the managed environment.
Line 1,048 ⟶ 1,054:
'''JNIDemo.java'''
<
{
static
Line 1,059 ⟶ 1,065:
private static native String callStrdup(String s);
}</
Two things to note: First, the "native" stub which will be linked with a native library, and second, the call to System.loadLibrary to actually do the linking at runtime. The class must then be compiled without the native library.
Line 1,068 ⟶ 1,074:
The generated file, '''JNIDemo.h''':
<
#include <jni.h>
/* Header for class JNIDemo */
Line 1,088 ⟶ 1,094:
}
#endif
#endif</
Next, the C code which utilizes JNI to bridge between the managed and unmanaged environments. It should include the "h" file, and implement the exported function declared in that file. The specifics of writing JNI code are beyond the scope of this task.
'''JNIDemo.c'''
<
#include "JNIDemo.h"
Line 1,136 ⟶ 1,142:
return dupeString;
}
</syntaxhighlight>
In a Windows environment, a dll by the same name should be created ("JNIDemo.dll"). In a Linux environment, a shared object marked executable and with a name preceded by "lib" should be created (in this case, "libJNIDemo.so"). Your compiler will need to know the location of "jni.h", which is in the "include" directory of the JDK. Linux may also need includes that are in the "include/linux" directory. Linux example using gcc:
Line 1,147 ⟶ 1,153:
Hello World!
</pre>
=={{header|JavaScript}}==
'''Node.js'''
Line 1,155 ⟶ 1,160:
'''md5sum.cc'''
<
#include <openssl/md5.h>
Line 1,182 ⟶ 1,187:
}
NODE_API_MODULE(addon, Init)</
Then compile the file with [https://github.com/nodejs/node-gyp node-gyp].
<syntaxhighlight lang
Once it has compiled, create the JavaScript bindings.
'''binding.js'''
<
module.exports = addon.md5sum;</
Then, you're able to call the function from any Node.js JavaScript file.
''Using Require:''
<
console.log(md5sum('hello'));</
{{out}}
<pre>
Line 1,205 ⟶ 1,210:
'''binding.js'''
<
const require = createRequire(import.meta.url);
const addon = require('../build/Release/md5sum-native');
export default addon.md5sum;</
And call the function as follows:
<
console.log(md5sum('hello'));</
{{out}}
<pre>
Line 1,223 ⟶ 1,228:
Julia has a built-in keyword <code>ccall</code> to call external C-like functions. For example:
<
@show unsafe_string(p) # "Hello world"
ccall(:free, Void, (Ptr{Cuchar},), p)</
'''PyCall''', [https://github.com/JuliaPy/PyCall.jl source]:
<
@pyimport math
@show math.cos(1) # 0.5403023058681398</
=={{header|Kotlin}}==
{{Works with|Ubuntu|14.04}}
<
import kotlinx.cinterop.*
Line 1,242 ⟶ 1,246:
val hw = strdup ("Hello World!")!!.toKString()
println(hw)
}</
{{out}}
Line 1,248 ⟶ 1,252:
Hello World!
</pre>
=={{header|LabVIEW}}==
Use Connectivity >> Libraries & Executables >> Call Library Function Node to call an external .dll file. This example uses the WinAPI's MessageBoxA function.<br/>{{VI snippet}}<br/>
[[File:LabVIEW Call a foreign-language function.png]]
=={{header|Lisaac}}==
Use backtick notation (`...`) for referencing foreign language (C) features.
<
+ name := TEST_C_INTERFACE;
Line 1,278 ⟶ 1,280:
// this will also be inserted in-place, expression type disregarded
`free(@p)`;
);</
=={{header|Locomotive Basic}}==
WinAPE has a built-in Z80 assembler that can copy the assembled program into the Amstrad CPC's memory. Whatever address your <code>org</code> directive was at can be <code>CALL</code>ed in BASIC.
<
ld a,'A'
call &bb5a
ret</
{{out}}
Line 1,292 ⟶ 1,293:
A
Ready</pre>
=={{header|Lua}}==
Using the [http://luajit.org/ext_ffi.html FFI library] available in [http://luajit.org/ LuaJIT]:
<
ffi.cdef[[
char * strndup(const char * s, size_t n);
Line 1,311:
print("Copy: " .. s2)
print("strlen: " .. ffi.C.strlen(s2))
</syntaxhighlight>
=={{header|Luck}}==
Luck supports interfacing with most C libraries out of the box:
<
import "string.h";;
Line 1,323 ⟶ 1,322:
let s2:char* = strdup(cstring(s1));;
puts(s2);;
free(s2 as void*)</
=={{header|M2000 Interpreter}}==
=== Call C Functions from Dll===
There is a difference between Windows and Wine implementation of _strdump and swprintf.
Value of '''a''' has to hold chars to read from sBuf$ as returned from msvcrt.swprintf, but this can't work in Ubuntu using Wine and in Windows as expected, so we can use '''LeftPart$(string, string as delimiter sign not included as result)'''
<syntaxhighlight lang="m2000 interpreter">
Module CheckCCall {
Line 1,352 ⟶ 1,350:
}
CheckCCall
</syntaxhighlight>
Output:
Line 1,360 ⟶ 1,358:
===Call VbScript===
<syntaxhighlight lang="m2000 interpreter">
Module Checkit {
Global a()
Line 1,404 ⟶ 1,402:
}
CheckIt
</syntaxhighlight>
===Call Javascript===
<syntaxhighlight lang="m2000 interpreter">
Module CheckJavaScript {
Clear
Line 1,461 ⟶ 1,459:
}
CheckJavaScript
</syntaxhighlight>
===Call A System Function (Win32)===
<syntaxhighlight lang="m2000 interpreter">
Declare MessageBox Lib "user32.MessageBoxW" {long alfa, lptext$, lpcaption$, long type}
Print MessageBox(Hwnd, "HELLO THERE", "GEORGE", 2)
Remove "user32"
</syntaxhighlight>
===Make, use and remove a C Dll at runtime===
H C dll to produce an array of primes. We can
<syntaxhighlight lang="m2000 interpreter">
Module checkit {
Static DisplayOnce=0
Line 1,599 ⟶ 1,597:
checkit
</syntaxhighlight>
=={{header|Maple}}==
We can call strdup, as requested, in the following way
<
> strdup( "foo" );
"foo"
</syntaxhighlight>
However, this doesn't make a lot of sense in Maple, since there can be only one copy of any Maple string in memory. Moreover, I don't see any easy way to free the memory allocated by strdup. A more sensible example for Maple follows. (It might be sensible if you wanted to compare your system library version of sin with the one built-in to Maple, for instance.)
<
csin := proc(s::numeric)
option call_external, define_external(sin, s::float[8],
Line 1,618 ⟶ 1,615:
> csin( evalf( Pi / 2 ) );
1.</
=={{header|Mathematica}}/{{header|Wolfram Language}}==
This works on windows and on linux/mac (through Mono)
<
externalstrdup = DefineDLLFunction["_strdup", "msvcrt.dll", "string", {"string"}];
Print["Duplicate: ", externalstrdup["Hello world!"]]</
output
<pre>Duplicate: Hello world!</pre>
Also there is ExternalEvaluate that can call many other languages.
=={{header|Maxima}}==
<
Use load("funcs.lisp"), or inside Maxima: */
Line 1,638 ⟶ 1,633:
f(5, 6);
11</
=={{header|Mercury}}==
Mercury is designed to interact sensibly with foreign code, even while keeping itself as pure and as safe as is possible in such circumstances. Here is an example of calling C's strdup() function from within Mercury:
<
:- interface.
Line 1,666 ⟶ 1,660:
io.write_string(strdup("Hello, worlds!\n"), !IO).
:- end_module test_ffi.</
Only the lines wrapped in comments matter for this. The rest is an application skeleton so this can be compiled and tested.
Line 1,674 ⟶ 1,668:
After this the Mercury strdup/1 function itself is declared. For purposes of exposition it has been declared fully with types and modes. The modes, however, are redundant since by default functions in Mercury have all input parameters and an output return value. Also, the determinism is declared which is again redundant. By default Mercury functions are deterministic. That line could easily have been written thusly instead:
<
The next block of code is the foreign_proc pragma declaration. In this declaration the language ("C") is declared, the footprint of the function is again provided, this time with variable names and modes but without the determinism, a set of properties is declared and the actual C code to be executed is provided. This last piece is trivial, but the properties themselves are worth looking more closely at.
Line 1,681 ⟶ 1,675:
Of note is that '''no separate C source file needs to be provided'''. The compiler takes care of putting in all the required boilerplate code necessary to conform to the specifications provided. The resulting code can be treated as much a part of the program as any native Mercury code would be: types, modes, determinism, purity, etc. all managed similarly.
=={{header|Modula-2}}==
The first file (Vga.c) creates the function prototypes.
<
int Initialize (void)
Line 1,751 ⟶ 1,744:
{
*ch = vga_getkey ();
}</
The next file is the definition module, but in this context it is called a '''FOREIGN MODULE'''.
<
TYPE EGAcolour = (black, blue, green, cyan, red, pink, brown, white,
Line 1,784 ⟶ 1,777:
PROCEDURE GetKey (VAR ch : CHAR);
END Vga.</
The third file is an example program.
<
FROM InOut IMPORT Read, Write, WriteBf, WriteString;
Line 1,818 ⟶ 1,811:
Write (ch);
WriteBf;
END svg01.</
=={{header|Modula-3}}==
Modula-3 provides many predefined interfaces to C files. Here we use <tt>Cstring</tt> which uses C string functions. Note we have to convert strings of type <tt>TEXT</tt> into C strings (NULL terminated character arrays). Also note the code requires the <tt>UNSAFE</tt> keyword because it interfaces with C (which is unsafe).
<
IMPORT IO, Ctypes, Cstring, M3toC;
Line 1,838 ⟶ 1,830:
M3toC.FreeCopiedS(string1);
M3toC.FreeCopiedS(string2);
END Foreign.</
Output:
<pre>
string1 # string2
</pre>
=={{header|Mosaic}}==
<
importdll msvcrt =
Line 1,856 ⟶ 1,847:
str2:=_strdup(&.str)
println str2
end</
=={{header|Never}}==
Never includes libffi for access to foreign functions, but currently only supports very basic types, int, float, string. ''strdup'' will work, but the ''voidness'' of ''free'' is not yet supported. This solution uses some of the Math functions in libm instead.
<
extern "libm.so.6" func coshf(x : float) -> float
extern "libm.so.6" func powf(base : float, exp : float) -> float
Line 1,880 ⟶ 1,870:
0
}</
Line 1,891 ⟶ 1,881:
1.18
</pre>
=={{header|NewLISP}}==
newLISP has two FFI APIs. The simple API needs no type specifiers but is limited to integers and pointers.
The extended API can specify types for return values and parameters and can also be used for floats and structs.
<
(import "libc.dylib" "strdup")
(println (get-string (strdup "hello world")))
Line 1,902 ⟶ 1,891:
(import "libc.dylib" "strdup" "char*" "char*")
(println (strdup "hello world"))
</syntaxhighlight>
=={{header|Nim}}==
Since Nim compiles to C by default, this task is easily done:
<
echo strcmp("abc", "def")
echo strcmp("hello", "hello")
Line 1,914 ⟶ 1,902:
var x = "foo"
printf("Hello %d %s!\n", 12, x)</
=={{header|OCaml}}==
===Outline of what is linked against===
For the hypothetical [[C]] library that contains functions described by a header file with this in:
<
float myfunc_b(int, float);
char *myfunc_c(int *, int);</
The header file is named "<tt>mylib.h</tt>", and linked against the library with <tt>-lmylib</tt> and compiled with <tt>-I/usr/include/mylib</tt>.
Line 1,929 ⟶ 1,916:
====file "mylib.ml":====
<
external myfunc_b: int -> float -> float = "caml_myfunc_b"
external myfunc_c: int array -> string = "caml_myfunc_c"</
====file "wrap_mylib.c":====
<
#include <caml/alloc.h>
#include <mylib.h>
Line 1,963 ⟶ 1,950:
free(arr);
return caml_copy_string(s);
}</
====the Makefile:====
(replace spaces by tabs)
<
ocamlc -c -ccopt -I/usr/include/mylib $<
Line 1,992 ⟶ 1,979:
clean:
rm -f *.[oa] *.so *.cm[ixoa] *.cmxa</
the file <tt>mylib.cma</tt> is used for the interpreted and bytecode modes, and <tt>mylib.cmxa</tt> is for the native mode.
Line 2,001 ⟶ 1,988:
There is another solution for calling C functions from a C library which is to use '''ocaml-ctypes'''. We can then define bindings by writing only OCaml code without any C stubs. The equivalent for wrapping the previous hypothetical [[C]] library will be:
<
open Foreign
Line 2,011 ⟶ 1,998:
let arr = CArray.of_list int lst in
myfunc_c (to_voidp (CArray.start arr)) (CArray.length arr)
;;</
=={{header|Ol}}==
<
(import (otus ffi))
Line 2,021 ⟶ 2,007:
(print (strdup "Hello World!"))
</syntaxhighlight>
Windows has no a "strdup" function, so windows version should look like this.
<
(import (otus ffi))
Line 2,034 ⟶ 2,020:
(print (strdup "Hello World!"))
</syntaxhighlight>
Note: this simplest way is not freeing allocated by "strdup" function string.
Ol provides a way to call ol functions directly from native code (means callbacks).
<
; The sample usage of GTK3+ library
(import (otus ffi)
Line 2,074 ⟶ 2,060:
(g_application_run app 0 #false)
</syntaxhighlight>
=={{header|Odin}}==
<syntaxhighlight lang="odin">package main
import "core:fmt"
foreign import libc "system:c"
@(default_calling_convention="c")
foreign libc {
@(link_name="strdup") cstrdup :: proc(_: cstring) -> cstring ---
@(link_name="free") cfree :: proc(_: rawptr) ---
}
main :: proc() {
s1 : cstring = "hello"
s2 := cstrdup(s1)
fmt.printf("{}\n", s2)
cfree(rawptr(s2))</syntaxhighlight>
=={{header|Oz}}==
First we need to create a so-called "native functor" that converts the arguments and describes the C functions:
<
#include <string.h>
Line 2,098 ⟶ 2,104:
};
return table;
}</
Save this file as "strdup.cc". To automate compiling and linking, we need a makefile for <code>ozmake</code>, the Oz build tool. Save this file as "makefile.oz":
<
lib : [
'strdup.o' 'strdup.so'
]
rules:o('strdup.so':ld('strdup.o'))
)</
Call <code>ozmake</code> in the same directory.
Now we can write some code that uses the wrapped C function (make sure Emacs' working directory is set to the same directory):
<
[Strdup] = {Module.link ['strdup.so{native}']}
in
{System.showInfo {Strdup.strdup "hello"}}</
=={{header|PARI/GP}}==
Of course it is trivial to include C functions in PARI, and not uncommon. C++ functions are similar, as PARI is written in a C++-friendly style. The <code>system</code> and <code>install</code> commands allow foreign-language functions to be called from within gp.
=={{header|Pascal}}==
See [[Call_a_foreign-language_function#Delphi | Delphi]]
=={{header|Perl}}==
Perl code calls a C function <code>c_dup()</code> passing a string <code>'Hello'</code> as an argument, which gets transparently converted to a C string, the <code>c_dup()</code> function makes a copy of that string using <code>strdup()</code> function, stores pointer to the copy in the <code>copy</code> variable and returns it. The returned <code>char</code> pointer gets converted transparently to a Perl string value and gets returned to the calling Perl code which prints it. Then the Perl code calls a C function <code>c_free()</code> to free the allocated memory. Both of the C functions are defined inline in the Perl program and are automatically compiled (only once, unless they change) and linked at runtime. Here is the entire program:
<
char *copy;
char * c_dup(char *orig) {
Line 2,134 ⟶ 2,137:
};
print c_dup('Hello'), "\n";
c_free();</
Another example, instead of returning the copy to Perl code it prints it using C printf:
<
void c_hello (char *text) {
char *copy = strdup(text);
Line 2,144 ⟶ 2,147:
}
};
c_hello 'world';</
=={{header|Phix}}==
The foreign language functions must be compiled to .dll (or .so) form.<br>
Line 2,151 ⟶ 2,153:
a library component which can be re-used in different applications.<br>
See also builtins/cffi.e, a text-based C interface that handles C-style structs, unions, and function declarations directly.
<!--<
<span style="color: #008080;">without</span> <span style="color: #008080;">js</span> <span style="color: #000080;font-style:italic;">-- not from a browser, mate!</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">shlwapi</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">open_dll</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"shlwapi.dll"</span><span style="color: #0000FF;">),</span>
Line 2,162 ⟶ 2,164:
<span style="color: #0000FF;">?</span><span style="color: #7060A8;">peek_string</span><span style="color: #0000FF;">(</span><span style="color: #000000;">pMem</span><span style="color: #0000FF;">)</span>
<span style="color: #7060A8;">assert</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">c_func</span><span style="color: #0000FF;">(</span><span style="color: #000000;">xLocalFree</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">pMem</span><span style="color: #0000FF;">})==</span><span style="color: #004600;">NULL</span><span style="color: #0000FF;">)</span>
<!--</
{{out}}
<pre>
"Hello World!"
</pre>
=={{header|PHP}}==
{{works with|PHP|7.4}}
PHP 7.4+ has as support to call external C-like functions using extension . See this Windows example:
<syntaxhighlight lang="php">$ffi = FFI::cdef("char *_strdup(const char *strSource);", "msvcrt.dll");
$cstr = $ffi->_strdup("success");
$str = FFI::string($cstr);
echo $str;
FFI::free($cstr);
</syntaxhighlight>
=={{header|PicoLisp}}==
The easiest is to inline the C code. Another possibility would be to write it
Line 2,177 ⟶ 2,189:
===32-bit version===
<
(gcc "str" NIL # The 'gcc' function passes all text
Line 2,195 ⟶ 2,207:
/**/
(println 'Duplicate (duptest "Hello world!"))</
===64-bit version===
<syntaxhighlight lang="c">
/*
How to create the shared lib/so file:
Line 2,218 ⟶ 2,230:
int main() {
}
</syntaxhighlight>
<syntaxhighlight lang="picolisp">
(prinl "Calling custom so/dll library...")
(set 'A NIL)
Line 2,226 ⟶ 2,238:
(prinl "A=" A)
(when (not (= A NIL)) (prinl "Success!"))
</syntaxhighlight>
<out>
Line 2,235 ⟶ 2,247:
</pre>
</out>
=={{header|PL/I}}==
<syntaxhighlight lang="text">declare strdup entry (character (30) varyingz) options (fastcall16);
put (strdup('hello world') );</syntaxhighlight>
=={{header|Prolog}}==
In SWI-Prolog we need to do two things. First we need to declare a mapping from a Prolog file to a C implementation:
<
:- use_foreign_library(plffi).</
This declares a module "plffi" that exports the '''predicate''' (''not'' function!) "strdup/2". This predicate has two arguments: the first being the atom being strduped, the second being the duped atom. (You can think of these as an in parameter and an out parameter and be about 2/3 right.)
Line 2,251 ⟶ 2,261:
Then we need to write a C file that gives us the interface to the underlying C function (strdup in this case), mapping the ''predicate''' call to a C '''function''' call:
<
#include <stdio.h>
#include <SWI-Prolog.h>
Line 2,270 ⟶ 2,280:
{
PL_register_foreign("strdup", 2, pl_strdup, 0);
}</
This C code provides us with two things. The function install_plffi() is provided to register the name "strdup" and to map it to its C implementation pl_strdup(). Here we're saying that "strdup" has an arity of 2, is implemented by pl_strdup and has no special flags.
Line 2,278 ⟶ 2,288:
We compile this very easily:
<
Then, from within the SWI-Prolog interactor:
<
% plffi compiled into plffi 0.04 sec, 1,477 clauses
true.
Line 2,296 ⟶ 2,306:
?- X = booger, strdup(booger, X).
X = booger.</
=={{header|PureBasic}}==
Here we will use [http://flatassembler.net/ Fasm (flat assembler)] to create an object file and then import the function
Line 2,303 ⟶ 2,312:
the resulting executable. [http://www.purebasic.com/ PureBasic] supports {Windows, Linux, MacOS}.
<syntaxhighlight lang="purebasic">
; Call_a_foreign_language_function.fasm -> Call_a_foreign_language_function.obj
; the assembler code...
Line 2,343 ⟶ 2,352:
public strucase as "_strucase@4"
</syntaxhighlight>
<syntaxhighlight lang="purebasic">
; the PureBasic code...
Line 2,356 ⟶ 2,365:
; cw(peeks(*r))
Debug peeks(*r)
</syntaxhighlight>
Line 2,363 ⟶ 2,372:
HELLO WORLD!!
</pre>
=={{header|Python}}==
<
libc = ctypes.CDLL("/lib/libc.so.6")
libc.strcmp("abc", "def") # -1
libc.strcmp("hello", "hello") # 0</
=={{header|Racket}}==
<
#lang racket/base
(require ffi/unsafe)
Line 2,414 ⟶ 2,421:
;; Let's try it:
(strdup "Hello World!")
</syntaxhighlight>
=={{header|Raku}}==
(formerly Perl 6)
{{Works with|rakudo|2016.07}}
<syntaxhighlight lang="raku"
sub strdup(Str $s --> Pointer) is native {*}
Line 2,427 ⟶ 2,433:
my $p = strdup("Success!");
say 'puts returns ', puts($p);
say 'free returns ', free($p);</
{{out}}
<pre>Success!
puts returns 9
free returns 0</pre>
=={{header|REALbasic}}==
<syntaxhighlight lang="vb">
Declare Function CreateFileW Lib "Kernel32" (FileName As WString, DesiredAccess As Integer, ShareMode As Integer, SecurityAttributes As Integer, _
CreateDisposition As Integer, Flags As Integer, Template As Integer) As Integer
Line 2,457 ⟶ 2,462:
MsgBox("Error Number: " + Str(GetLastError))
End If
</syntaxhighlight>
=={{header|REXX}}==
The use of the '''address''' statement isn't normally required, but it's shown here as an illustrative example.
<
cmd = "MODE" /*define the command that is to be used*/
Line 2,468 ⟶ 2,472:
address 'SYSTEM' cmd opts /*invoke a cmd via the SYSTEM interface*/
/*stick a fork in it, we're all done. */</
{{out|output|text= when executing under a Microsoft Windows system in the USA, code pages vary upon the country:}}
<pre>
Line 2,475 ⟶ 2,479:
Code page: 437
</pre>
=={{header|Ruby}}==
Line 2,487 ⟶ 2,490:
{{works with|MRI}}
<
#include <stdlib.h> /* free() */
#include <string.h> /* strdup() */
Line 2,520 ⟶ 2,523:
VALUE mRosettaCode = rb_define_module("RosettaCode");
rb_define_module_function(mRosettaCode, "strdup", rc_strdup, 1);
}</
<
require 'mkmf'
create_makefile('rc_strdup')</
<
require 'rc_strdup'
puts RosettaCode.strdup('This string gets duplicated.')</
=== FFI ===
Line 2,534 ⟶ 2,537:
A recent effort to make it easier to write libraries, portable across platforms and interpreters, led to the creation of a [http://sourceware.org/libffi/ libffi] binding simply called [http://wiki.github.com/ffi/ffi/ ffi] for completely dynamic calls.
<
require 'ffi'
Line 2,549 ⟶ 2,552:
puts duplicate.get_string(0)
LibC.free(duplicate)
</syntaxhighlight>
Line 2,557 ⟶ 2,560:
{{works with|Ruby|2.0+}}
<
# Find strdup(). It takes a pointer and returns a pointer.
Line 2,569 ⟶ 2,572:
duplicate = strdup.call("This is a string!")
puts duplicate.to_s # Convert the C string to a Ruby string.
Fiddle.free duplicate # free() the memory that strdup() allocated.</
Fiddle::Importer is also part of Ruby's standard library.
{{works with|Ruby|2.0+}}
<
require 'fiddle/import'
Line 2,585 ⟶ 2,588:
duplicate = C.strdup("This is a string!")
puts duplicate.to_s
Fiddle.free duplicate</
=== RubyInline ===
Line 2,591 ⟶ 2,594:
Using {{libheader|RubyGems}} package [http://www.zenspider.com/ZSS/Products/RubyInline/ RubyInline], which compiles the inlined code on demand during runtime.
<
require 'inline'
Line 2,623 ⟶ 2,626:
t = InlineTester.new
11.upto(14) {|n| p [n, t.factorial_ruby(n), t.factorial_c(n)]}
p t.my_ilogb(1000)</
outputs (note Ruby's implicit use of Bignum past 12!, while C is stuck with a long int):
Line 2,631 ⟶ 2,634:
[14, 87178291200, 1278945280]
9</pre>
=={{header|Rust}}==
<
//c function that returns the sum of two integers
Line 2,646 ⟶ 2,648:
add_input(in1, in2) };
assert!( (output == (in1 + in2) ),"Error in sum calculation") ;
}</
=={{header|Scala}}==
<
try System.loadLibrary("JNIDemo")
Line 2,655 ⟶ 2,656:
println(callStrdup("Hello World!"))
}</
=={{header|Smalltalk}}==
The way external functions are declared is different among Smalltalk dialects. However, there are not many situations where you'd need them (and especially not for simple things like strdup).
{{works with | Smalltalk/X}}
<
!CallDemo class methods!
strdup:arg
Line 2,666 ⟶ 2,667:
! !
Transcript showCR:( CallDemo strdup:'Hello' )</
=={{header|Standard ML}}==
{{works with|Poly/ML}}
<syntaxhighlight lang="sml">local
val libc = Foreign.loadLibrary "libc.so.6"
val sym = Foreign.getSymbol libc "strdup"
in
val strdup = Foreign.buildCall1(sym, (Foreign.cString), Foreign.cString)
end</syntaxhighlight>
{{out}}
<pre>
> strdup "test string";
val it = "test string": string
>
</pre>
=={{header|Stata}}==
Line 2,676 ⟶ 2,692:
As an example let's build a '''[https://en.wikipedia.org/wiki/Hilbert_matrix Hilbert matrix]''' in C.
<
#include "stplugin.h"
Line 2,689 ⟶ 2,705:
}
return 0;
}</
The DLL can be built from '''Visual Studio''', or in the console with <code>cl /LD hilbertmat.c stplugin.c</code>. With '''MinGW''', compile with <code>gcc -shared stplugin.c hilbertmatrix.c -o hilbertmat.plugin</code>. With '''Pelles C''', compile with <code>cc /Tx64-coff /Ze stplugin.c hilbertmat.c /DLL /OUT:hilbertmat.plugin</code>. The DLL must be renamed with the '''.plugin''' extension, and put in a directory visible in [https://www.stata.com/help.cgi?adopath adopath].
Line 2,695 ⟶ 2,711:
Declare also an ADO file to call the plugin:
<
matrix define `1'=J(`2',`2',0)
plugin call hilbertmat, `1' `2'
end
program hilbertmat, plugin</
Then, you may call
<
. matrix list mymat
Line 2,713 ⟶ 2,729:
r2 .5 .33333333
r3 .33333333 .25 .2
r4 .25 .2 .16666667 .14285714</
Notice the program as is has minimal protection against invalid arguments. Production code should be more careful.
Line 2,722 ⟶ 2,738:
As an example let's build a '''[https://en.wikipedia.org/wiki/Hilbert_matrix Hilbert matrix]''' in Java.
<
public class HilbertMatrix {
Line 2,737 ⟶ 2,753:
return 0;
}
}</
Compile with <code>javac -cp %STATA%\utilities\jar\sfi-api.jar HilbertMatrix.java</code>, assuming %STATA% is the path to the Stata install directory.
Line 2,743 ⟶ 2,759:
In Stata, assuming HilbertMatrix.class resides in K:\java:
<
. matrix list mymat
Line 2,752 ⟶ 2,768:
r2 .5 .33333333
r3 .33333333 .25 .2
r4 .25 .2 .16666667 .14285714</
Notice that Mata has the builtin function '''[https://www.stata.com/help.cgi?mf_Hilbert Hilbert]''' to do the same:
<
[symmetric]
1 2 3 4
Line 2,764 ⟶ 2,780:
3 | .3333333333 .25 .2 |
4 | .25 .2 .1666666667 .1428571429 |
+---------------------------------------------------------+</
=={{header|Swift}}==
Because Swift uses the Objective-C runtime it is trivial to call C/Objective-C functions directly in Swift.
<
let hello = "Hello, World!"
let fromC = strdup(hello)
let backToSwiftString = String.fromCString(fromC)</
=={{header|Tcl}}==
{{libheader|critcl}}
In this solution, we wrap up the <code>ilogb</code> function from C's math library with critcl so that it becomes one of Tcl's normal functions (assuming Tcl 8.5):
<
critcl::code {
#include <math.h>
Line 2,784 ⟶ 2,798:
return ilogb(value);
}
package provide ilogb 1.0</
Note that we do not show <code>strdup</code> here because Tcl manages the memory for strings in complex ways and does not guarantee to preserve string pointers from one call into the C API to the next (e.g., if it has to apply an encoding transformation behind the scenes).
<!-- TODO: a basic thunk, and show off using SWIG -->
=={{header|TXR}}==
Line 2,803 ⟶ 2,816:
There is no way to use the <code>str</code> family of types, yet do manual memory management; FFI manages automatically. Code that wants to manually manage a foreign resource referenced by pointer should use <code>cptr</code> or <code>carray</code>, depending on required semantics.
=={{header|V (Vlang)}}==
Note: Vlang also has a C2V transpiler.
<syntaxhighlight lang="vlang">
#include "stdlib.h"
#include "string.h"
// Declare C functions that will be used.
fn C.strdup(txt &char) &char
fn C.strcat(dest &char, src &char) &char
fn main() {
txt_1 := "Hello World!"
txt_2 := " Let's Wish for Peace!"
// Memory-unsafe operations must be marked as such (unsafe {...}), or won't compile.
unsafe {
dup := C.strdup(txt_1.str)
println('${cstring_to_vstring(dup)}')
addto := C.strcat(dup, txt_2.str)
println('${cstring_to_vstring(addto)}')
// Must manually free memory or program can hang because unsafe.
free(dup)
free(addto)
}
exit(0)
}
</syntaxhighlight>
{{out}}
<pre>
Hello World!
Hello World! Let's Wish for Peace!
</pre>
=={{header|Wren}}==
Although RC task solutions are usually written for execution by Wren CLI, the language's main purpose is for embedding and the embedding API is written in C. It is therefore a relative easy matter to call a C function from Wren after first embedding the latter in a suitable C program.
<syntaxhighlight lang="wren">/* Call_a_foreign-language_function.wren */
class C {
Line 2,814 ⟶ 2,862:
var s = "Hello World!"
System.print(C.strdup(s))</
which we embed in the following C program and run it.
Note that it's safe to free the pointer returned by strdup after passing it to Wren because wrenSetSlotString copies the C string to a new String object managed by Wren’s garbage collector.
<
#include <stdio.h>
#include <string.h>
Line 2,885 ⟶ 2,933:
WrenVM* vm = wrenNewVM(&config);
const char* module = "main";
const char* fileName = "
char *script = readFile(fileName);
WrenInterpretResult result = wrenInterpret(vm, module, script);
Line 2,901 ⟶ 2,949:
free(script);
return 0;
}</
{{out}}
Line 2,911 ⟶ 2,959:
===UASM 2.52===
Calling C functions in Assembly is trivial at best. It's not anymore complicated than using them in C itself. Strdup for example..
<
option casemap:none
Line 2,942 ⟶ 2,990:
;main endp
;end
</syntaxhighlight>
====Lua====
Using the liblua that comes with Lua 5.2(?). Assembling is the same as always, Link with a -llua using clang or gcc.
<
option casemap:none
Line 3,192 ⟶ 3,240:
end
</syntaxhighlight>
Addition.lua
<
function addition(a, b)
print('---> Lua calc: ' .. a .. ' + ' .. b .. ' = ' .. a+b)
return a + b
end
</syntaxhighlight>
{{out}}
<pre>
Line 3,214 ⟶ 3,262:
{{trans|Wren}}
So yeah. This inits Wrens VM in Assembly to call strdup in C. Now PIE(Position independent executable) compliant.
<
;; libc stuff..
extern printf
Line 3,392 ⟶ 3,440:
ret
</syntaxhighlight>
strdup.wren
<
class C {
foreign static strdup(s)
Line 3,400 ⟶ 3,448:
var s = "Goodbye, World!"
System.print(C.strdup(s))
</syntaxhighlight>
strdup.c
<syntaxhighlight lang="c">
void free( void* ptr );
char * strdup( const char *str1 );
Line 3,416 ⟶ 3,464:
free(t);
}
</syntaxhighlight>
{{out}}
<pre>
Line 3,422 ⟶ 3,470:
Goodbye, World!
</pre>
=={{header|Zig}}==
<
const c = @cImport({
@cInclude("stdlib.h"); // `free`
Line 3,436 ⟶ 3,483:
try std.io.getStdOut().writer().print("{s}\n", .{copy});
c.free(copy);
}</
=={{header|zkl}}==
In my opinion, FFIs are very problematic and it is better, if you really need external functionality, to spend the effort to write a glue library. Certainly a lot more work. And it only works for C or C++.
Line 3,444 ⟶ 3,490:
flf.c:
<
// flf.c, Call a foreign-language function
Line 3,479 ⟶ 3,525:
}
return methodCreate(Void,0,zkl_strlen,vm);
}</
In use on Linux:
{{out}}
Line 3,494 ⟶ 3,540:
3
</pre>
{{omit from|360 Assembly|A CPU only understands its own machine language. So no assembly language can do this.}}
{{omit from|6502 Assembly}}
{{omit from|8051 Assembly}}
{{omit from|8080 Assembly}}
{{omit from|8086 Assembly}}
{{omit from|68000 Assembly}}
{{omit from|AArch64 Assembly}}
{{omit from|ARM Assembly}}
|