William Stevenson > VM-Dreamer > VM::Dreamer::Instructions

Download:
Dreamer/VM-Dreamer-0.851.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 0.851   Source  

NAME ^

VM::Dreamer::Instructions - The heavy lifting

SYNOPSIS ^

input_to_mb( $machine, '72' ); output_from_my( $machine, $operand ); store( $machine, $operand ); load( $machine, $operand ); add( $machine, $operand ); subtract( $machine, $operand ); branch_always( $machine, $operand ); branch_if_zero( $machine, $operand ); branch_if_negative( $machine, $operand ); branch_if_positive( $machine, $operand ); halt($machine);

DESCRIPTION ^

These functions will be used in a dispatch table in VM::Dreamer::Languages::YourMachine where you map your operation codes to these functions.

A base 10 machine with an op code width of 1 might map op code 7 to branch_always. A base 2 machine with an opcode width of 4 might map 0101 to subtract.

For an example, see VM::Dreamer::Languages::Grasshopper

If you'd like to add more instructions, you can do so here in VM::Dreamer::Instructions and send me a pull request. You can also use VM::Dreamer::Local for your own code.

input_to_mb

input_to_mb( $machine, '72' );

Prompts the user for input and, if valid, stores their input in memory at address '72'.

output_from_mb

output_from_mb( $machine, '72' );

Outputs the value stored in memory at address '72' to the user.

store

store( $machine, '1011101' );

Stores the value on the accumulator at address '1011101' in memory.

load

load( $machine, '271104523210' );

Loads the value stored in memory at address '271104523210' onto the accumulator.

add

add( $machine, '10011100101001' );

Adds the value stored in memory at address '10011100101001' to the current value on the accumulator.

subtract( $machine, '9744321229' );

Subtracts the value stored in memory at address '9744321229' from the current value on the accumulator.

If the resulting value is negative, the negative flag is set and the remaining value on the accumulator is undefined.

branch_always

branch_always( $machine, '432' );

Sets the value of the counter to 432, always.

This means that the next instruction executed will be fetched from address 432 in memory.

branch_if_zero

branch_if_zero( $machine, '34221023' );

Sets the value of the counter to 34221023 if the value on the accumulator is zero.

In other words, if the accumulator is zero, fetch the next instruction from address 34221023 in memory.

branch_if_negative

branch_if_negative( $machine, '1521532' );

Sets the value of the counter to 1521532 if the negative flag is set.

In other words, if the negative flag is set, fetch the next instruction from address 1521532 in memory.

branch_if_positive

branch_if_positive( $machine, '92345' );

Sets the value of the counter to 92345 if the value on the accumulator is greater than zero and the negative flag is not set.

In other words, if the negative flag is unset and the accumulator is greater than 0, fetch the next instruction from address 92345 in memory.

halt

halt($machine);

Sets the halt flag to 1. This means that the machine should cease operation.

SEE ALSO ^

VM::Dreamer::execute_next_instruction VM::Dreamer::Languages::Grasshopper

AUTHOR ^

William Stevenson <william at coders dot coop>

COPYRIGHT AND LICENSE ^

This software is Copyright (c) 2013 by William Stevenson.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)
syntax highlighting: