home *** CD-ROM | disk | FTP | other *** search
/ MacFormat España 14 / MacFormat n. 14 (Spain) / MacFormat 14.bin / Shareware Internet / Educación / xComputer 1.2.1 / Examples / Example 3 - Graphics < prev    next >
Encoding:
Text File  |  1995-12-28  |  3.4 KB  |  150 lines

  1. ; Example 3: Graphics
  2.  
  3. ; This fiendishly-difficult-to-write program computes powers of
  4. ; three up to any number of digits.  It starts with N1=3,
  5. ; copies N1 to N2, then adds N2 to N1 twice, and repeats this
  6. ; process forever.
  7.  
  8. ; The main point of this example is to give you something
  9. ; interesting to watch in the xComputer's "Graphics"
  10. ; memory display.  To use it, load the program, set the
  11. ; Run Speed sub-menu of the Options menu to "Fastest"
  12. ; and set the Memory Display sub-menu of the Options menu
  13. ; to "Graphics".  In this display mode, each bit of each
  14. ; location in memory is represented by one pixel in the
  15. ; memory display area of the xComputer window.  In this
  16. ; case, the program itself will show up as a bunch of
  17. ; pixels at the top of the display.  When you run the
  18. ; program, N1 and N2 will appear as groups of pixels 
  19. ; in the middle and at the bottom of the display.  You will
  20. ; see rapid changes in N1 and N2 and in the data locations
  21. ; at the end of the program.  This is, in some ways, the
  22. ; most realistic view you can get of what goes on in a
  23. ; computer's memory as a program executes.
  24.  
  25. ; This file also illustrates the "#" directive, which
  26. ; tells the computer to repeat an item in a program a
  27. ; specified number of times.
  28.  
  29. 1024# 0   ;  This is equivalent to typing 1024 0's.  The
  30.           ;     directive "1024#" tells the computer to
  31.           ;     repeat the next item 1024 times.  In this
  32.           ;     case, the purpose is to make sure that
  33.           ;     everything previously in memory is cleared
  34.           ;     out before the program is loaded.
  35.  
  36. @PC 0     ; For convenience, make sure that the PC contains
  37.           ;    a 0, the starting location of the program,
  38.           ;    after the program is loaded.
  39.  
  40. @0        ; Start loading the program at location 0
  41.  
  42.        lod-c 3    ; The program itself...
  43.        sto N1
  44.        lod-c 1
  45.        sto ct1
  46.  
  47. copy:  lod ct1
  48.        sto ct2
  49.        sto ct
  50.        lod-c N1
  51.        sto src
  52.        lod-c N2
  53.        sto dest
  54. c1:    lod-i src
  55.        sto-i dest
  56.        lod ct
  57.        dec
  58.        jmz sum
  59.        sto ct
  60.        lod src
  61.        dec
  62.        sto src
  63.        lod dest
  64.        dec
  65.        sto dest
  66.        jmp c1
  67.  
  68. sum:   lod ct2
  69.        sto ct
  70.        lod-c N2
  71.        sto src
  72.        lod-c N1
  73.        sto dest
  74.        lod-c 0
  75.        sto carryQ
  76. s1:    lod-i dest
  77.        add-i src
  78.        sto-i dest
  79.        jmf cr1
  80. s2:    lod-i dest
  81.        add-i src
  82.        sto-i dest
  83.        jmf cr2
  84. s3:    lod ct
  85.        dec
  86.        jmz copy
  87.        sto ct
  88.        lod src
  89.        dec
  90.        sto src
  91.        lod dest
  92.        dec
  93.        sto dest
  94.        jmp s1
  95.  
  96. cr1:   lod-c s2
  97.        sto return
  98.        jmp add1
  99.  
  100. cr2:   lod-c s3
  101.        sto return
  102.        jmp add1
  103.  
  104. add1:  lod ct
  105.        sto aCt
  106.        lod dest
  107.        sto aDest
  108. a1:    lod aDest
  109.        dec
  110.        sto aDest
  111.        lod aCt
  112.        dec
  113.        sto aCt
  114.        jmz advnc
  115.        lod-i aDest
  116.        add-c 1
  117.        sto-i aDest
  118.        jmf a1
  119.        jmp-i return
  120. advnc: lod carryQ
  121.        jmz adv1
  122.        lod-i aDest
  123.        add-c 1
  124.        sto-i aDest
  125.        jmp-i return
  126. adv1:  lod ct1
  127.        inc
  128.        sto ct1
  129.        lod-c 1
  130.        sto-i aDest
  131.        lod-c 1
  132.        sto carryQ
  133.        jmp-i return
  134.  
  135. return:data     ; Data locations used by the program in its
  136. ct1:   data     ;    calculations
  137. ct2:   data
  138. ct:    data
  139. src:   data
  140. dest:  data
  141. aCt:   data
  142. aDest: data
  143. carryQ:data
  144.  
  145. @500         ; "N1" will refer to location 500
  146. N1: data
  147.  
  148. @1000        ; "N2" will refer to location 1000
  149. N2: data
  150.