instructions

package module
v0.0.0-...-387e20d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2018 License: MIT Imports: 3 Imported by: 2

Documentation

Overview

Package instructions provides functions for decoding and disassembling Human Resource machine instructions stored in a profile

Index

Constants

View Source
const (
	OP_INBOX      = 0x0
	OP_OUTBOX     = 0x1
	OP_COPY_FROM  = 0x2
	OP_COPY_TO    = 0x3
	OP_ADD        = 0x4
	OP_SUB        = 0x5
	OP_BUMP_MINUS = 0x6
	OP_BUMP_PLUS  = 0x7
	OP_JUMP       = 0x8
	OP_JUMP_ZERO  = 0x9
	OP_JUMP_NEG   = 0xA
	OP_JUMP_TGT   = 0xD
	MODE_DIRECT   = 0x1
	MODE_INDIRECT = 0x2
)

Variables

View Source
var InstructionsWithArg = instructionsWithArg{
	OP_COPY_FROM:  {},
	OP_COPY_TO:    {},
	OP_ADD:        {},
	OP_SUB:        {},
	OP_BUMP_MINUS: {},
	OP_BUMP_PLUS:  {},
}

A map containing opcodes that take an argument

View Source
var InstructionsWithLabel = instructionsWithLabel{
	OP_JUMP:      {},
	OP_JUMP_ZERO: {},
	OP_JUMP_NEG:  {},
}

A map containing opcodes that have a target label

View Source
var InstrunctionMnemonics = instrunctionMnemonics{
	OP_INBOX:      "INBOX",
	OP_OUTBOX:     "OUTBOX",
	OP_COPY_FROM:  "COPYFROM",
	OP_COPY_TO:    "COPYTO",
	OP_ADD:        "ADD",
	OP_SUB:        "SUB",
	OP_BUMP_MINUS: "BUMPDN",
	OP_BUMP_PLUS:  "BUMPUP",
	OP_JUMP:       "JUMP",
	OP_JUMP_ZERO:  "JUMPZ",
	OP_JUMP_NEG:   "JUMPN",
}

A map of mnemonics

Functions

func NextLabel

func NextLabel(label string) string

Given a label, return the next label. The starting label for Human Resource Machine programs should be "a"

Types

type Comment

type Comment []CommentLine

A comment made up of one or more comment lines

type CommentLine

type CommentLine []CommentPoint

A single unbroken graphical line, however a CommentLine of length one represents a dot

type CommentPoint

type CommentPoint struct {
	X uint16
	Y uint16
}

A point in a comment, represented by an X and Y coordinate decoded from the RawComment

type Comments

type Comments []Comment

A sequence of comments

func DecodeComments

func DecodeComments(rawComments RawComments) (Comments, error)

Decode a sequence of RawComments into Comments. Comments are useful when, for example, rendering the comments

type DisassembleArgInstruction

type DisassembleArgInstruction struct {
	DisassembleInstruction
	Arg      uint32
	Indirect bool
}

An instruction taking one argument (implements DisassembleInterface)

type DisassembleComment

type DisassembleComment struct {
	Index uint32
}

A comment (implements DisassembleInterface)

type DisassembleInstruction

type DisassembleInstruction struct {
	Line int
	Op   OpCode
}

An instruction taking no arguments (implements DisassembleInterface)

type DisassembleInterface

type DisassembleInterface interface {
	// contains filtered or unexported methods
}

An interface for different kinds of disassembled instructions.

type DisassembleJumpInstruction

type DisassembleJumpInstruction struct {
	DisassembleInstruction
	TargetLabel string
	Target      int
}

An jump instruction (implements DisassembleInterface)

type DisassembleJumpTarget

type DisassembleJumpTarget struct {
	Label  string
	Jumpee int
}

A jump target (implements DisassembleInterface)

type Disassembled

type Disassembled []DisassembleInterface

A list of disassembled instructions

func Disassemble

func Disassemble(instructions Instructions) Disassembled

Given a sequence of instructions, return the disassembled instructions

type Instruction

type Instruction struct {
	Comment uint32
	Op      uint32
	Mode    uint32 // or flag?
	Arg     uint32
}

A decoded binary instruction

type Instructions

type Instructions []Instruction

A list of binary instructions

func DecodeInstructions

func DecodeInstructions(reader io.Reader) (Instructions, error)

Decode and return a sequence of instructions read from the passed in reader. The reader must be correctly positioned so that the first word read contains the instruction count

type Labels

type Labels map[uint32]string

A map of instruction indices to label names

func MakeLabels

func MakeLabels(instructions Instructions) Labels

Given a list of instructions, return a map containing the symbolic label names for all jump targets

type OpCode

type OpCode uint32

Binary opcode

func (OpCode) String

func (o OpCode) String() string

Return the mnemonic for the opcode

type RawComment

type RawComment [][4]byte

A raw comment

type RawComments

type RawComments []RawComment

A sequence of raw comments

func DecodeRawComments

func DecodeRawComments(reader io.ReadSeeker) (RawComments, error)

Decode binary comments found in reader into "raw" comments. RawComments are useful when rendering the comments back to a textual Human Resource Machine program representation. The reader must be correctly positioned so that the first word read contains the comment count

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL