RosettaCodeData/Task/Machine-code/Draco/machine-code-2.draco

29 lines
930 B
Plaintext

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