Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
21
Task/Machine-code/Draco/machine-code-1.draco
Normal file
21
Task/Machine-code/Draco/machine-code-1.draco
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
/* 8080 machine code in an array */
|
||||
[6] byte add_mc = (
|
||||
0xC1, /* POP B - get return address */
|
||||
0xD1, /* POP D - get second argument */
|
||||
0xE1, /* POP H - get first argument */
|
||||
0x19, /* DAD D - add arguments */
|
||||
0xC5, /* PUSH B - push return address back */
|
||||
0xC9 /* RET - return */
|
||||
);
|
||||
|
||||
proc nonrec main() void:
|
||||
/* Declare a function pointer */
|
||||
type fn = proc(word a, b) word;
|
||||
fn add;
|
||||
|
||||
/* Pretend the array is actually a function */
|
||||
add := pretend(add_mc, fn);
|
||||
|
||||
/* Call the function and print the result */
|
||||
writeln(add(12, 7))
|
||||
corp
|
||||
28
Task/Machine-code/Draco/machine-code-2.draco
Normal file
28
Task/Machine-code/Draco/machine-code-2.draco
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
proc nonrec main() void:
|
||||
word a, b, c;
|
||||
|
||||
/* assign values to the input variables */
|
||||
a := 12;
|
||||
b := 7;
|
||||
|
||||
/* inline machine code to add A and B
|
||||
*
|
||||
* Note that we have to cast each value to a byte,
|
||||
* because by default, numeric constants are assumed
|
||||
* to be 16-bit words, and would be emitted as two
|
||||
* bytes each.
|
||||
*
|
||||
* The intent is for the programmer to define byte
|
||||
* constants corresponding to opcodes, and write
|
||||
* "assembly", but that is beyond the scope here. */
|
||||
code(
|
||||
make(0x2A, byte), a, /* LHLD a - load var A into HL */
|
||||
make(0xEB, byte), /* XCHG - put it in DE */
|
||||
make(0x2A, byte), b, /* LHLD b - load var B into HL */
|
||||
make(0x19, byte), /* DAD D - add DE to HL */
|
||||
make(0x22, byte), c /* SHLD c - store the result in var C */
|
||||
);
|
||||
|
||||
/* print the result */
|
||||
writeln(c);
|
||||
corp
|
||||
Loading…
Add table
Add a link
Reference in a new issue