How does the instructor pointer work with a stack?

64 Views Asked by At

I recently read about a programming language called Befunge (esoteric programming language). It deals with operations with a stack. The Wikipedia article contains this text:

The instruction pointer begins at a set location (the upper-left corner of the playfield) and is initially travelling in a set direction (right). As it encounters instructions, they are executed. Befunge-93 has no jumps farther than two cells, so control flow is done by altering the direction of the program counter, sending it to different literal code paths. (Befunge-98 has far jumps, but because of inertia in the community, these are rarely used.) The following, for example, is an infinite loop: >v ^<

I don’t understand what "instructor pointer" means. Can somebody explain it to me in simpler terms?

1

There are 1 best solutions below

0
On

This is what the linked Wikipedia page says right at the beginning. Emphasis is mine.

A Befunge program is laid out on a two-dimensional playfield of fixed size. The playfield is a rectangular grid of ASCII characters, each generally representing an instruction. The playfield is initially loaded with the program.

Execution proceeds by the means of a program counter (-93) or instruction pointer (-98). This points to a grid cell on the playfield.

Both terms program counter and instruction pointer mean the same thing. It is an abstract "variable" that realizes a pointer to the next instruction to execute. You can literally use your pointer finger (sic!) and use it to read the next character of the program (grid cell), which encodes the instruction.

In this case the instruction pointer needs to hold at least two indexes, one for the row and one for the column of the current cell. One would also add the current direction to be able to advance.