Class: BFCpu

BFCpu(nbits, program, memorySize, inputCharCodes)

A class that stores the CPU model for the BF program execution. This includes the: data and instruction pointers, the instruction list, the memory and the execution counter

Constructor

new BFCpu(nbits, program, memorySize, inputCharCodes)

The constructor for the BF CPU
Parameters:
Name Type Default Description
nbits Number 8 The number of bits the architecture supports. Must be on of [8, 16, 32]
program BFProgram The program to execute
memorySize Number The size of the allocated memory at start up
inputCharCodes Array.<Number> The ASCII char codes of the input string
Source:
See:
  • Program
  • Instruction

Methods

execute()

Execute the entire program until the instruction pointer reaches the end of the file.
Source:

getCurrentCell() → {Number}

Gets the current data cell value.
Source:
Returns:
- The current cell value
Type
Number

getDataPtr() → {Number}

Get the current location of the data pointer.
Source:
Returns:
- The data pointer location.
Type
Number

getNextInput() → {Number}

Get the next input from the input buffer. Returns zero at the end of the array if it is not Null terminated.
Source:
Returns:
- The ASCII char code
Type
Number

reset()

Resets the CPU architecture: clears the output, zeros memory, moves data pointer to the start, moves instruction pointer to the start, zeros the execute counter.
Source:

setCurrentCell(value)

Set the current data cell to a new value.
Parameters:
Name Type Description
value Number The new cell value
Source:

setDataPtr(value)

Set the data pointer to a new value
Parameters:
Name Type Description
value Number The new data pointer location.
Source:

setDataPtrWrapMode(mode)

Sets the data pointer mode to either wrap around or throw an error on overflow and underflow.
Parameters:
Name Type Description
mode Boolean True if wrap
Source:

setInstructionPtr(value)

Set the instruction pointer to a new location
Parameters:
Name Type Description
value Number The new instruction location
Source:

step()

Execute one instruction and increment the instruction pointer.
Source:

Documentation generated by JSDoc 4.0.2 on Fri Jun 12 2026 23:36:44 GMT-0700 (Pacific Daylight Time)