home *** CD-ROM | disk | FTP | other *** search
- ; Example 3: Graphics
-
- ; This fiendishly-difficult-to-write program computes powers of
- ; three up to any number of digits. It starts with N1=3,
- ; copies N1 to N2, then adds N2 to N1 twice, and repeats this
- ; process forever.
-
- ; The main point of this example is to give you something
- ; interesting to watch in the xComputer's "Graphics"
- ; memory display. To use it, load the program, set the
- ; Run Speed sub-menu of the Options menu to "Fastest"
- ; and set the Memory Display sub-menu of the Options menu
- ; to "Graphics". In this display mode, each bit of each
- ; location in memory is represented by one pixel in the
- ; memory display area of the xComputer window. In this
- ; case, the program itself will show up as a bunch of
- ; pixels at the top of the display. When you run the
- ; program, N1 and N2 will appear as groups of pixels
- ; in the middle and at the bottom of the display. You will
- ; see rapid changes in N1 and N2 and in the data locations
- ; at the end of the program. This is, in some ways, the
- ; most realistic view you can get of what goes on in a
- ; computer's memory as a program executes.
-
- ; This file also illustrates the "#" directive, which
- ; tells the computer to repeat an item in a program a
- ; specified number of times.
-
- 1024# 0 ; This is equivalent to typing 1024 0's. The
- ; directive "1024#" tells the computer to
- ; repeat the next item 1024 times. In this
- ; case, the purpose is to make sure that
- ; everything previously in memory is cleared
- ; out before the program is loaded.
-
- @PC 0 ; For convenience, make sure that the PC contains
- ; a 0, the starting location of the program,
- ; after the program is loaded.
-
- @0 ; Start loading the program at location 0
-
- lod-c 3 ; The program itself...
- sto N1
- lod-c 1
- sto ct1
-
- copy: lod ct1
- sto ct2
- sto ct
- lod-c N1
- sto src
- lod-c N2
- sto dest
- c1: lod-i src
- sto-i dest
- lod ct
- dec
- jmz sum
- sto ct
- lod src
- dec
- sto src
- lod dest
- dec
- sto dest
- jmp c1
-
- sum: lod ct2
- sto ct
- lod-c N2
- sto src
- lod-c N1
- sto dest
- lod-c 0
- sto carryQ
- s1: lod-i dest
- add-i src
- sto-i dest
- jmf cr1
- s2: lod-i dest
- add-i src
- sto-i dest
- jmf cr2
- s3: lod ct
- dec
- jmz copy
- sto ct
- lod src
- dec
- sto src
- lod dest
- dec
- sto dest
- jmp s1
-
- cr1: lod-c s2
- sto return
- jmp add1
-
- cr2: lod-c s3
- sto return
- jmp add1
-
- add1: lod ct
- sto aCt
- lod dest
- sto aDest
- a1: lod aDest
- dec
- sto aDest
- lod aCt
- dec
- sto aCt
- jmz advnc
- lod-i aDest
- add-c 1
- sto-i aDest
- jmf a1
- jmp-i return
- advnc: lod carryQ
- jmz adv1
- lod-i aDest
- add-c 1
- sto-i aDest
- jmp-i return
- adv1: lod ct1
- inc
- sto ct1
- lod-c 1
- sto-i aDest
- lod-c 1
- sto carryQ
- jmp-i return
-
- return:data ; Data locations used by the program in its
- ct1: data ; calculations
- ct2: data
- ct: data
- src: data
- dest: data
- aCt: data
- aDest: data
- carryQ:data
-
- @500 ; "N1" will refer to location 500
- N1: data
-
- @1000 ; "N2" will refer to location 1000
- N2: data
-