Jump to content

Machine code: Difference between revisions

→‎{{header|Go}}: Now uses actual x64 opcodes rather than x86/x64 'glue code' .
m (Clarified the program a little bit.)
(→‎{{header|Go}}: Now uses actual x64 opcodes rather than x86/x64 'glue code' .)
Line 374:
This task requires the use of 'cgo' which enables Go to interface with C code by importing a pseudo-package called "C".
 
Although Go supports both 32-bit and 64-bit architectures, I'm writing this on a 64-bit Ubuntu 1620.04 system. I'vem therefore utilizedusing thex64 PicoLispopcodes entry'srather 'gluethan code'the to enable thex86 (32-bit) codeopcodes tolisted runin the ontask itdescription.
 
There doesn't appear to be a way to cast a pointer to a native buffer to a Go function pointer so that the machine code can be run directly. I've therefore written a C function to perform this step and embedded it in the program which 'cgo' allows us to do.
Line 399:
func main() {
code := []byte{
1440x55, //0x48, Align0x89, 0xe5, 0x89, 0x7d,
1440xfc, 0x89, 0x75, 0xf8, 0x8b, 0x75,
1060xfc, 120x03, //0x75, Prepare0xf8, stack0x89, 0x75,
1840xf4, 70x8b, 00x45, 00xf4, 00x5d, 0xc3,
72, 193, 224, 32,
80,
139, 68, 36, 4, 3, 68, 36, 8, // Rosetta task code
76, 137, 227, // Get result
137, 195,
72, 193, 227, 4,
128, 203, 2,
72, 131, 196, 16, // Clean up stack
195, // Return
}
le := len(code)
9,488

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.