--- title: "Yards, Feet and Inches Subroutine" id: 72003 type: "computer_media" slug: "yards-feet-and-inches-subroutine" url: "http://localhost/computer_media/yards-feet-and-inches-subroutine/" markdown_url: "http://localhost/computer_media/yards-feet-and-inches-subroutine.md" published_at: "2026-10-20T14:07:42+00:00" modified_at: "2026-10-20T14:15:32+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2022/04/20230809-041332.jpg" excerpt: "An eleven-line subroutine that normalizes a length given in yards, feet and inches, including negative values, by converting to inches and back." category: - name: "Archived Media" slug: "archived-media" taxonomy: "category" url: "http://localhost/category/archived-media/" post_tag: - name: "Downloadable" slug: "downloadable" taxonomy: "post_tag" url: "http://localhost/tag/downloadable/" - name: "TS 1000" slug: "ts1000" taxonomy: "post_tag" url: "http://localhost/tag/ts1000/" model: - name: "Timex/Sinclair 1000" slug: "ts-1000" taxonomy: "model" url: "http://localhost/model/ts-1000/" genre: - name: "Utility" slug: "utility" taxonomy: "genre" url: "http://localhost/type/utility/" media_type: "Program" download_url: "https://archive.org/download/timex-sinclair-software-archive/Yards%20Feet%20and%20Inches%20Subroutine%20%28198x%29%28-%29%28TS1000%29%28US%29%28Program%29.zip" mediadate: "198x" media_type_tags: "Utility" --- # Yards, Feet and Inches Subroutine Converts a length held in three variables, `Y` yards, `F` feet and `I` inches, into normal form, so that inches run 0–11 and feet 0–2. It totals everything in inches, then divides back out into feet and yards. Negative lengths are handled by working with the absolute value and restoring the sign at the end. The routine starts at line 1000 and ends with `RETURN`, ready to be called with `GOSUB 1000` from another program. This is the worked subroutine example from the subroutines chapter of the Sinclair ZX81 / Timex Sinclair 1000 BASIC manual. It came from an unlabeled tape, which holds two identical recordings, one saved as `PRT 1 FT TO INCHES`. ## Program Analysis ### Program Structure Line 900 is a REM with the program name. Line 1010 converts to inches with `36*Y+12*F+I`. Line 1030 saves the sign in `E` using `SGN`, and 1040 takes `ABS`. Lines 1060–1090 split off feet with `INT (I/12)` and yards with `INT (F/3)`, multiplying each part by `E` so all three results carry the original sign. There is no calling program on the tape, so the routine does nothing if run by itself until it reaches `RETURN`, which stops with an error because no `GOSUB` is active. ## Source Code ``` 900 REM "PRT 1 FT TO INCHES" 1000 REM SUBROUT TO ADJUST Y,F,ITO THE NORMAL FORM FOR YARDS,FEET AND INCHES 1010 LET I=36*Y+12*F+I 1020 REM NOW EVERYTHING IS IN INCHES 1030 LET E=SGN I 1040 LET I=ABS I 1050 REM WE WORK WITH I POSITIVE,HOLDING ITS SIGN IN E 1060 LET F=INT (I/12) 1070 LET I=(I-12*F)*E 1080 LET Y=INT (F/3)*E 1090 LET F=F*E-3*Y 1100 RETURN ```