--- title: "Machine Code Counter" id: 77451 type: "computer_media" slug: "machine-code-counter" url: "http://localhost/computer_media/machine-code-counter/" markdown_url: "http://localhost/computer_media/machine-code-counter.md" published_at: "2026-11-15T18:38:22+00:00" modified_at: "2026-11-15T18:38:22+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2026/11/machine-code-counter-1.png" excerpt: "A 35-byte machine-code routine that counts on the screen until a key is pressed, with a POKE loader and the BASIC version for comparison." 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/" - name: "ZX81" slug: "zx81" taxonomy: "post_tag" url: "http://localhost/tag/zx81/" model: - name: "Sinclair ZX81" slug: "zx81" taxonomy: "model" url: "http://localhost/model/zx81/" - name: "Timex/Sinclair 1000" slug: "ts-1000" taxonomy: "model" url: "http://localhost/model/ts-1000/" indiv: - name: "Stan Piotrowski" slug: "stan-piotrowski" taxonomy: "indiv" url: "http://localhost/indiv/stan-piotrowski/" genre: - name: "Machine Language" slug: "machine-language" taxonomy: "genre" url: "http://localhost/type/machine-language/" media_type: "Program" programmers: - name: "Stan Piotrowski" slug: "stan-piotrowski" taxonomy: "indiv" url: "http://localhost/indiv/stan-piotrowski/" download_url: "https://archive.org/download/timex-sinclair-software-archive/Machine%20Code%20Counter%20%281984%29%28Piotrowski%2C%20Stan%29%28TS1000%29%28CA%29%28Program%29.zip" mediadate: "1984" images: - url: "http://localhost/wp-content/uploads/2026/11/machine-code-counter-1.png" article_media: - id: 40057 title: "Machine Code Programming (part 1)" type: "article" url: "http://localhost/article/basic-programming-2/" media_type_tags: "Machine Language" license: false --- # Machine Code Counter A 35-byte machine-code routine that counts upward in the middle of the screen, writing each digit straight into the display file, until you press a key. Stan Piotrowski gives it next to a four-line BASIC program that does the same job, to show how much faster machine code is. Type RAND USR 16514: the download already holds the bytes in the line 1 REM, and a key press stops the count. Lines 10-70 are the article’s general-purpose POKE loader (RUN, then enter the bytes one at a time). BASIC.p is the four-line BASIC counter, for comparison. Use 16K: the routine writes to the full-size display file. As printed, byte 60 is labelled DEC A; 60 is INC A, which is what makes the count go up. The LD DE,381 bytes are printed as 17,124,1 (that is 380), which only moves the counter one column. Published in Sinc-Link early 1984 (Vol. 2 No. 1) ([Machine Code Programming (part 1)](https://timexsinclair.com/article/basic-programming-2/)). ## Source Code ``` Listing 1 (BASIC version): 10 LET A=1 20 PRINT AT 10,14;A 30 LET A=A+1 40 GOTO 20 Listing 2 (loader): 1 REM XXXX....etc (35 X's) 10 LET A=16514 20 INPUT B 30 POKE A,B 40 SCROLL 50 PRINT A;",";PEEK A 60 LET A=A+1 70 GOTO 20 Listing 3 (machine code): 42,12,64 LD HL, (16396) :display file location 17,124,1 LD DE, 381 :screen centre 25 ADD HL,DE 126 CHECK LD A,(HL) :A contains the character at that location 254,0 CP 0 :is it blank? 32,2 JRNZ +2 :No. It contains a number so jump forward 2 bytes 62,28 LD A,28 :Yes. A now contains the zero digit 60 DEC A :LET A=A-1 254,38 CP 38 :is A larger than the code for digit "9"? 32,5 JRNZ +5 :No. Jump ahead 5 bytes 54,28 LD (HL),28 :Yes. Print a zero 43 DEC HL :move display back 1 space 24,239 JR -17 :jump back 17 bytes to CHECK 119 LD (HL),A :print the digit A contains 205,187,2 CALL 699 :keyboard scan 62,255 LD A,255 189 CP L :check for no 202,130,64 JP Z, 16514 key pressed 201 RET :if a key is pressed, return to Basic & stop. ```