Skip to content

B side: Keeping values

A cassette tape with a handwritten label: "B Side. Fortran, the language that speaks maths."

B B side · Fortran · The language that speaks maths

How do you tell the machine to remember a number?

19 Fortran words in this segment
26 Assembly words for the same job

What Fortran says well here

  • Each name has a type, for example INTEGER or REAL. The compiler stops many mistakes before the program runs.
  • A list or a table of values (an array) is one noun, with a name and a shape.

What is hard to say

  • You do not choose where the values go in memory. The compiler chooses for you.

One sentence in Fortran

integer :: lives = 3

It says: Make a whole-number name, lives, with the value 3.

The words, by part of speech

Verbs (2) · A statement that does something, for example PRINT, CALL or ALLOCATE.

WordMeaningExample
ALLOCATEMake space for an ALLOCATABLE array.allocate(x(n))
DEALLOCATERelease the space of an array.deallocate(x)

Nouns (6) · A kind of value (a type), for example INTEGER or REAL.

WordMeaningExample
INTEGERA whole number, for example -1, 0 or 42.integer :: lives
REALA number with a decimal point, for example 3.14.real :: speed
LOGICALA value that is true or false.logical :: landed
CHARACTERText.character(len=20) :: name
COMPLEXA complex number: a real part and an imaginary part.complex :: z
TYPEA new noun that you make from other nouns (a derived type).type :: ship

Adjectives (9) · An attribute, for example ALLOCATABLE or PARAMETER.

WordMeaningExample
PARAMETERThe value never changes (a constant).real, parameter :: g = 1.62
DIMENSIONThis name holds a list or a table of values (an array).real, dimension(100) :: x
ALLOCATABLEThe program sets the size of this array when it runs.real, allocatable :: x(:)
POINTERThis name points to a different value.real, pointer :: p
TARGETA pointer can point to this value.real, target :: t
SAVEKeep this value between calls.integer, save :: count
KINDSelect the precision: how many digits a number keeps.real(kind=real64) :: t
INT8 / INT16A kind name from ISO_FORTRAN_ENV: a whole number of exactly 1 or 2 bytes. The same size as a BYTE or a WORD on the A side.integer(int16) :: table(0:255)
REAL64A kind name from ISO_FORTRAN_ENV: a decimal-point number of 8 bytes (double precision).real(real64) :: theta

Grammar marks (2) · Maths signs (+ - * / **), the = sign, and (:) for part of an array.

WordMeaningExample
::Separates the description from the names in a declaration.real :: x, y
=Put the value on the right into the name on the left. It is not the maths "equals".x = x + 1

Watch out: what the review found

These notes come from the review of the AI-written guides. They show traps that are easy to miss.

  • D02-M4 major These are 16-bit registers. 16.16 math needs 32-bit registers (EAX and the others, 386 and later) or register pairs on the 8086. REP MOVSD (L31) also needs a 386 or later. The document mixes 8086 and 386 targets and does not say so.
  • D13-M4 major The video names neither LoROM nor HiROM, and it does not discuss fast or slow ROM. Its memory lesson is the data bank register: ROM from bank $C0, code in the second half of each bank, so the mirror reaches the hardware registers and "the first 8K of low RAM" (20:35 to 21:59). It moved the objects from bank $7F to the first RAM bank to avoid bank switches. The document misses this lesson, which is the closest SNES parallel to the 8086 segment registers.