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 Description
nbits Number The number of bits the architecture supports
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:

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 Mon Feb 09 2026 21:26:04 GMT-0800 (Pacific Standard Time)