Linear Regression in Assembly
A line fitted through data, one machine instruction at a time.
Built in January 2024 for a computer organization course: a program that reads a data file, splits it, fits a straight line and tests it, written in MIPS assembly with no library underneath.
From text to numbers
Even reading a number was code.
The data file arrives as characters. Each digit becomes a number by subtracting the code for "0", and every further digit multiplies what is already there by ten, then adds itself. So "9" then "8" becomes 98.
Train and test
A coin flip for every row.
A random 0 or 1 sends each row to training or testing, until training holds 80% of the rows. The line learns from those alone, so the rest can show whether it works.
The fit
Every slope solved at once.
Averages
Every column summed and divided, in floating point.
The table
How each input moves with the others, and with the answer.
The solve
Gauss-Jordan elimination, largest pivot first, in double precision.
The line
The intercept from the slopes, then the formula printed.
The test
Asked about a row it never saw.
In this run the row with 98 was held back. The line learned from the other eight, then answered for it:
Actual: 98 Predicted: 97.477615
Outcome
Checked against a separate solver.
Revisited in 2026: the course version fitted each input on its own, so the fit was rewritten to solve every input together, then checked over 90 runs on nine data files against an independent least squares solve. The 2024 code stays in the repository beside it.
|\_/| **************************** (\_/)
/ @ @ \ * Project Complete! * (='.'=)
( > º < ) * Goodbye! * (')_(')
`>>x<<´ * (Abdullah Mehtab) *
/ O \ *
Next: the rest of the range.
Responses