memory

package
v0.0.0-...-5f9b76b Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2018 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const INCREMENT = 1

Program counter increment value

View Source
const LR = 30

Link register number

View Source
const MEMORY_SIZE = 4096

Data memory size in number of words

View Source
const SP = 28

Stack pointer register number

View Source
const STACK_SIZE = 256

Stack size in number of words

View Source
const WORD_SIZE = 4

Number of bytes in a word

View Source
const XZR = 31

XZR register number

Variables

View Source
var InstructionMem = InstructionMemory{
	PC:           0,
	Instructions: []string{},
	Labels:       make(map[string]int64),
}

Instance of instruction memory

Functions

func InitRegisters

func InitRegisters()

InitRegisters is a function to initiate register values.

func IsValidPC

func IsValidPC(PC int64) bool

IsValidPC is a function to check if program counter is valid.

func SaveRegisters

func SaveRegisters()

SaveRegisters is a function to store register values in a buffer.

func ShowRegisters

func ShowRegisters(showAll bool)

ShowRegisters is a function to pretty print register values to terminal.

Types

type AddAndSetFlagsInstruction

type AddAndSetFlagsInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : ADD AND SET FLAGS

Example : ADDS X1, X2, X3
Meaning : X1 = X2 + X3

Comments : Adds and sets condition codes

type AddImmediateAndSetFlagsInstruction

type AddImmediateAndSetFlagsInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : ADD IMMEDIATE AND SET FLAGS

Example : ADDIS X1, X2, 40
Meaning : X1 = X2 + 40

Comments : Adds constant and sets condition codes

type AddImmediateInstruction

type AddImmediateInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : ADD IMMEDIATE

Example : ADDI X1, X2, 40
Meaning : X1 = X2 + 40

type AddInstruction

type AddInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : ADDITION

Example : ADD X1, X2, X3
Meaning : X1 = X2 + X3

type AndImmediateInstruction

type AndImmediateInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : LOGICAL AND IMMEDIATE

Example : ANDI X1, X2, #20
Meaning : X1 = X2 & 20

Comments : Bitwise-And of X2 with a constant, stores result in X1

type AndInstruction

type AndInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : LOGICAL AND

Example : AND X1, X2, X3
Meaning : X1 = X2 & X3

Comments : Bitwise-And of X2 and X3, stores result in X1

type BranchInstruction

type BranchInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : UNCONDITIONAL BRANCH

Example : B label
Meaning : go to label

Comments : Branch to PC-relative target address

type BranchOnNonZeroInstruction

type BranchOnNonZeroInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : COMPARE AND BRANCH ON NOT EQUAL 0

Example : CBNZ X1, label
Meaning : if (X1 != 0) go to label

Comments : NotEqual 0 test; PC-relative branch

type BranchOnZeroInstruction

type BranchOnZeroInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : COMPARE AND BRANCH ON EQUAL 0

Example : CBZ X1, label
Meaning : if (X1 == 0) go to label

Comments : Equal 0 test; PC-relative branch

type BranchToRegisterInstruction

type BranchToRegisterInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : UNCONDITIONAL BRANCH TO REGISTER

Example : BR LR
Meaning : go to address stored in LR

Comments : Branch to address stored in register. Used for switch, procedure return

type BranchWithLinkInstruction

type BranchWithLinkInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : UNCONDITIONAL BRANCH WITH LINK

Example : BL label
Meaning : X30 = PC + 4; go to label

Comments : For procedure call (PC-relative)

type ConditionalBranchInstruction

type ConditionalBranchInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : CONDITIONAL BRANCH

Example : B.cond label
Meaning : if (condition true) go to label

Comments : Test condition codes; if true, then branch

type DataMemory

type DataMemory struct {
	sync.RWMutex
	Memory []int32
}

type ExclusiveOrImmediateInstruction

type ExclusiveOrImmediateInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : LOGICAL EXCLUSIVE-OR IMMEDIATE

Example : EORI X1, X2, #20
Meaning : X1 = X2 ^ 20

Comments : Bitwise-Xor of X2 with a constant, stores result in X1

type ExclusiveOrInstruction

type ExclusiveOrInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : LOGICAL EXCLUSIVE-OR

Example : EOR X1, X2, X3
Meaning : X1 = X2 ^ X3

Comments : Bitwise-Xor of X2 and X3, stores result in X1

type Instruction

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

All instructions implement the Instruction interface

type InstructionMemory

type InstructionMemory struct {
	PC           int64
	Instructions []string
	Labels       map[string]int64
}

Struct to represent instruction memory

func (*InstructionMemory) ExtractLabels

func (instructionMemory *InstructionMemory) ExtractLabels()

ExtractLabels is a method to extract labels from instructions.

func (*InstructionMemory) ValidateAndExecuteInstruction

func (instructionMemory *InstructionMemory) ValidateAndExecuteInstruction() error

ValidateAndExecuteInstruction is a method to check instruction type, perform syntax analysis, parse the statement and execute it

type LeftShiftInstruction

type LeftShiftInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : LOGICAL LEFT SHIFT

Example : LSL X1, X2, #10
Meaning : X1 = X2 << 10

Comments : Left shifts X2 by a constant, stores result in X1

type LoadByteInstruction

type LoadByteInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : LOAD BYTE

Example : LDURB X1, [X2, #40]
Meaning : X1 = Memory[X2 + 40]

Comments : Byte from memory to register

type LoadHalfInstruction

type LoadHalfInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : LOAD HALFWORD

Example : LDURH X1, [X2, #40]
Meaning : X1 = Memory[X2 + 40]

Comments : Halfword from memory to register

type LoadInstruction

type LoadInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : LOAD

Example : LDUR X1, [X2, #40]
Meaning : X1 = Memory[X2 + 40]

Comments : Word from memory to register

type MoveWithKeepInstruction

type MoveWithKeepInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : MOVE WITH KEEP

Example : MOVK X1, 20, LSL 0
Meaning : X1 = 20 or 20*(2^16) or 20*(2^32) or 20*(2^48)

Comments : Loads 16-bit constant, rest unchanged

type MoveWithZeroInstruction

type MoveWithZeroInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : MOVE WITH ZERO

Example : MOVZ X1, 20, LSL 0
Meaning : X1 = 20 or 20*(2^16) or 20*(2^32) or 20*(2^48)

Comments : Loads 16-bit constant, rest zeroes

type MulInstruction

type MulInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : MULTIPLICATION

Example : MUL X1, X2, X3
Meaning : X1 = X2 * X3

type OrImmediateInstruction

type OrImmediateInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : LOGICAL OR IMMEDIATE

Example : ORRI X1, X2, #20
Meaning : X1 = X2 | 20

Comments : Bitwise-Or of X2 with a constant, stores result in X1

type OrInstruction

type OrInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : LOGICAL OR

Example : ORR X1, X2, X3
Meaning : X1 = X2 | X3

Comments : Bitwise-Or of X2 and X3, stores result in X1

type RightShiftInstruction

type RightShiftInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : LOGICAL RIGHT SHIFT

Example : LSR X1, X2, #10
Meaning : X1 = X2 >> 10

Comments : Right shifts X2 by a constant, stores result in X1

type StoreByteInstruction

type StoreByteInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : STORE BYTE

Example : STURB X1, [X2, #40]
Meaning : Memory[X2 + 40] = X1

Comments : Byte from register to memory

type StoreHalfInstruction

type StoreHalfInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : STORE HALFWORD

Example : STURH X1, [X2, #40]
Meaning : Memory[X2 + 40] = X1

Comments : Halfword from register to memory

type StoreInstruction

type StoreInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : STORE

Example : STUR X1, [X2, #40]
Meaning : Memory[X2 + 40] = X1

Comments : Word from register to memory

type SubAndSetFlagsInstruction

type SubAndSetFlagsInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : SUB AND SET FLAGS

Example : SUBS X1, X2, X3
Meaning : X1 = X2 - X3

Comments : Subtracts and sets condition codes

type SubImmediateAndSetFlagsInstruction

type SubImmediateAndSetFlagsInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : SUB IMMEDIATE AND SET FLAGS

Example : SUBIS X1, X2, 40
Meaning : X1 = X2 - 40

Comments : Subtracts constant and sets condition codes

type SubImmediateInstruction

type SubImmediateInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : SUB IMMEDIATE

Example : SUBI X1, X2, 40
Meaning : X1 = X2 - 40

type SubInstruction

type SubInstruction struct {
	// contains filtered or unexported fields
}

INSTRUCTION : SUBTRACTION

Example : SUB X1, X2, X3
Meaning : X1 = X2 - X3

Jump to

Keyboard shortcuts

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