@@ -12,29 +12,55 @@ Sometimes however, it is mandatory to communicate directly with the system.
1212Embedded and bare-metal development, system programming and better memory
1313managing are just some examples of why this access is needed.
1414
15+ ---
16+ ## Acessing CPU Registers
17+
18+ When compiled to some CPUs, the program binary has access to a set of CPU
19+ Registers that are used to do operations or controll the CPU behavior.
20+
1521// TODO
1622
23+ ---
1724## Inline Assembly
1825
19- The target will provide a library with interfaces to allow this
20- connection .
26+ When read and write to the registers themselves are not enough, Abstract
27+ has a rich system that allow the user to write an entire assembly subroutine .
2128
2229As a example of use, being targeted to x86_64 assemby:
2330
2431``` abs
2532from Std.Console import
26- from Std.System.Assembly.x86_64Assembly import {
27- Instructions as opcode,
28- ReferenceOperators as refas
29- }
33+ from Std.System.Assembly.x86_64Assembly import { assemblyContext }
3034
3135func foo()
3236{
3337
3438 let string message = "Hello, World!";
3539
36- opcode.MOV(.RDI, refas.memptr(message))
37- opcode.CALL(refas.memptr(writeln))
40+ # Calling writeln(message) though assembly
41+
42+ # This will create the context object.
43+ # The context object is used to store the
44+ # entire assembly code in a tiny scope,
45+ # allowing that the code will be emited as
46+ # is and do not receive any optimizations.
47+ assemblyContext()
48+
49+ # The context return an instance that contains
50+ # diverse methods to write the assembly code.
51+ # See the example:
52+
53+ # The first argument must go in the RAX register
54+ # the mov instruction follows the order 'to <- from'
55+ .MOV().reg(.rax).ptr(message)
56+ # Then we can make a call to the function pointer
57+ .CALL().ptr(writeln)
58+
59+ #This is equivalent to
60+ ###
61+ MOV $rax, message
62+ CALL Std.Console.writeln
63+ ###
3864
3965}
4066
0 commit comments