home *** CD-ROM | disk | FTP | other *** search
/ ftp.whtech.com / ftp.whtech.com.tar / ftp.whtech.com / articles / archives / limanews.exe / ASSM_3.TXT < prev    next >
Text File  |  2006-10-19  |  6KB  |  113 lines

  1. ORIGINALLY PUBLISHED IN LIMA NEWSLETTER FEBURARY 1994
  2.  
  3.                                Assembler Executing  #3  
  4.                                   By Bob Carmany 
  5.  
  6.      Have you ever heard of the "Riddle of the Sphinx"?  It goes something like
  7. this: "What walks on four legs in the morning, two legs at mid-day, and three
  8. legs in the evening"?  A real puzzler, huh? (answer later).  Why did I bring
  9. that up?  It's about the way I feel about this next topic -- addressing modes
  10. for registers which is where we will start.  Let's have at it! 
  11.      The first of the five general addressing modes is Register Direct
  12. Addressing.  It is very simple (probably why I only had to read it once to
  13. understand it!).  It simply takes the contents of one register and copies it to
  14. a second register.  After the operation, both registers are identical.  It
  15. looks like this: 
  16.  
  17.      MOV   R10,R1 
  18.  
  19.      If R10 contained the value 3, both would contain 3 after the operation.
  20. No worries about this one! 
  21.  
  22. WARNING: THIS NEXT SECTION SHOULD BE READ ONLY WHILE SOBER!!!
  23.  
  24.      The second of the five general addressing modes is Register Indirect
  25. Addressing.  Now things start to get complicated! This copies values from one
  26. register to the LOCATION contained in the second register.  For example, if R1
  27. (our example) contained a memory location, Indirect Addressing would copy our
  28. value 3 to the address contained in R1 instead of to R1 itself.  I'm not sure I
  29. still understand this one fully! Anyway, it looks like this: 
  30.  
  31.      MOV   R10,*R1 
  32.  
  33.      I think of it as moving a value to the location POINTED TO by the second
  34. register. 
  35.      The third of the general addressing modes is Register Indirect
  36. Autoincrement Addressing.  Here's where things start to ge bloody unbearable!
  37. For this example, we will use some hex values (more fun).  R10 contains the hex
  38. value A062 and R3 contains the hex value B37E when we start this example.  Ok,
  39. this operation moves the value A062 (from R10) to memory location B37E (pointed
  40. to by R1) and then increments R1 by two.  So, when the operation js complete,
  41. R1 points to B380.  The format looks like this: 
  42.  
  43.      MOV   R10,*R1+ 
  44.  
  45.      This is one I have problems with!  In fact, it is my justification for
  46. keeping a book on elementary A/L programming next to the computer.  Have Ron or
  47. Tony explain it to you at the next meeting. 
  48.      Whew!  Time for an easy one.  The fourth general addressing mode is
  49. Symbolic Addressing.  It can be used to move a value to a location in general
  50. memory that isn't in a register (ie. a memory location).  It can also be used
  51. to move the value to a memory location specified by name.  For example: 
  52.  
  53.      MOV   R10,@@>837C 
  54.  
  55.      moves the contents of R10 to the memory location >837C.  Or: 
  56.  
  57.      MOV   R10,@@SCRN 
  58.  
  59.      moves the contents of R10 to the memory location named SCRN. 
  60.  
  61.      The last of the general addressing modes is Indexed Addressing.  This is a
  62. combination of Symbolic Addressing and an address in a register.  Let's take a
  63. look at this one!  Suppose R10 contains our hex value A062 and R1 contains the
  64. value 0004 and SCRN contains the hex value B37E.  The operation: 
  65.  
  66.      MOV   @@SCRN(R1),R10 
  67.  
  68.      Moves the value contained in R10 to address B382 (the memory location in
  69. SCRN - B37E plus 4 -- the value in R1). 
  70.      I'm beginning to get the idea that I was in fact "sold a blind horse" by
  71. those two --Ron K and Tony McG.  All of this has made my head hurt and bsides
  72. that, I'm thirsty!  I'll be back in a few minutes to continue this (I hope). 
  73.      Immediate Addressing is the next one.  It is almost as easy as the first
  74. of the general addressing modes that we discussed.  There are two instructions
  75. to use with it -- LI (LoadImmediate) and AI -- (AddImmediate).  They do exactly
  76. that!  Depending on which one you use, they either load or add a value to a
  77. register.  For example: 
  78.  
  79.      LI   R10,5 
  80.  
  81.      loads the value 5 into R10. And: 
  82.  
  83.      AI   R10,4 
  84.  
  85.      Adds 4 to the current value of R10.  The biggest advantage that they have
  86. is a savings in space when assembled. 
  87.      The last of the addressing modes that we will attempt for the present is
  88. the PC (Program Counter)-relative Addressing mode.  The discussion on this one
  89. is going to be brief  --- find an elementary A/L book and read about jump
  90. instructions.  There are 13 of them and the easiest thing to do is read about
  91. them at your own pace.  I would suggest "Learning TI-99/4A Home Computer
  92. Assembly Language Programming" by Ira McComic.  It's the one I use and where I
  93. got most of my examples from. 
  94.      Now, for my very first attempt at an A/L program.  This program runs from
  95. the E/A cartridge because I'm just not up to writing my own standalone routines
  96. for some of this stuff.  It is much easier to use the REF table to access the
  97. routines, anyway.  This program serves no utilitarian purpose.  It just
  98. displays bits of text on the screen. 
  99.      Oh yes, I only got 7 errors the first time I assembled this lot from the
  100. source code.  Most of them were typos but I got some colorful screen displays
  101. at the start when I used the wrong register in the SCRWRT routine for
  102. displaying the text.  I got the inspiration for this by examining bits of
  103. commented source code that came my way from Ron K (and his cohorts) in their
  104. undying effort to coerce me into trying A/L in the first place.  Anyway, much
  105. to my surprise, this stupid program actually worked after I corrected the typos
  106. and the errant register access.  It isn't the most elegant program but maybe
  107. Tony started this way once . . .naw, not a chance! 
  108.      The answer to the riddle: a man.  Crawls on all fours as a baby, walks on
  109. two legs in middle age, and with a cane (three legs) when aged.  'Til next
  110. month! 
  111. .PL 1 
  112.  
  113.