OldAsm

Posted on April 9, 2010, 1:58 am UTC by Steve (about 1 year ago)

Code (highlighted for Text)

  1. {{
  2.  
  3. *********************************
  4. *  Assembly Language Simple     *
  5. *  Author: Steven Donald        *
  6. *  Date: 4/6/2010               *
  7. *********************************
  8.  
  9.  -----------------REVISION HISTORY-----------------
  10.  v1.00 - Original Version
  11.  
  12. }}
  13.  
  14. CON
  15.  
  16.   _clkmode = xtal1 + pll16x
  17.   _xinfreq = 5_000_000
  18.  
  19.   _RX           = 31
  20.   _TX           = 30
  21.  
  22. OBJ
  23.   SPORT : "FullDuplexSerial"
  24.  
  25. VAR
  26.   'Our block of memory for this example
  27.   long  TheResult  
  28.   long  Iamdone  
  29.  
  30.  
  31. PUB Start
  32.  
  33.   TheResult := 10
  34.   Iamdone := -1
  35.  
  36.   SPORT.start(_RX, _TX, %0000, 19200)
  37.  
  38.   cognew(@MyAsm,@TheResult)
  39.  
  40.   SPORT.str(String("Assembly Example"))
  41.   SPORT.tx(13)
  42.  
  43.   repeat
  44.  
  45.   while (Iamdone == -1)
  46.  
  47.   SPORT.str(String(" TheResult: "))
  48.   SPORT.dec(TheResult)
  49.   SPORT.tx(13)
  50.  
  51.   SPORT.str(String(" Iamdone: "))
  52.   SPORT.dec(Iamdone)
  53.   SPORT.tx(13)
  54.    
  55.  
  56. DAT
  57. ''__________
  58. ''Assembly: MyAsm
  59. ''
  60. ''             31                             0
  61. ''            +--------------------------------+
  62. '' $0000????  |           TheResult            |
  63. ''            +--------------------------------+
  64. '' $0000????  |           Iamdone              |
  65. ''            +--------------------------------+
  66. '' Pass the address of two contiguous 32 bit variables in Main Memory.
  67. '' TheResult    - The 32 bit value to increment.
  68. '' Iamdone      - A flag to say when we are done
  69.  
  70.               ORG   0
  71. MyAsm         mov       t1,par                  'Grab the passed parameter (address of variable block)
  72.  
  73.               rdlong    Val,t1                  'Go to the hub and access main memory (RAM)
  74.                                                 'Read the value at the first location passed (par)
  75.  
  76.                                                
  77.               'Changed this from add to sub, to subtract one from the value we read from main memory
  78.               sub       Val,#1
  79.  
  80.              
  81.               wrlong    Val,t1                  'Go back to the hub and write the value back to main memory
  82.               mov       Val,#0                  'Move a zero into Val
  83.               add       t1,#4                   'Passed address gets incremented by 4 (to point to the next long)
  84.               wrlong    Val,t1                  'Clear the 'IamDone flag
  85.  
  86.               cogid     id                      'get 'this' cogs id
  87.               cogstop   id                      'use the id to stop the cog
  88.  
  89. ' All this below this line is data that is also moved into the COG or reserved by the Propeller Tool
  90. ' --------------------------------------------------------------------------------------------------
  91. myblock       long      $01234567               'Just some data (that we'll use later)
  92.               long      $89ABCDEF
  93.               long      $AABBCCDD
  94.               long      $00112233
  95.               long      $44556677
  96.               long      $8899AABB
  97.  
  98. t1            res       2                       't1 is used to hold the pointer to main memory
  99. Val           res       1                       'Local variable Val
  100. id            res       1                       'id is used to stop the COG
  101.  
  102.  
  103.  
  104.