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

  1. ORIGINALLY PUBLISHED IN LIMA NEWSLETTER MARCH 1994
  2.  
  3.                         Assembler Executing #4 
  4.                             By Bob Carmany 
  5.  
  6.      I'm not sure whether it was out of friendship or revenge but Ron
  7. Kleinschafer sent along a great heap of A/L source code for me to
  8. examine.  Not just a few files but an entire disk full of the stuff!
  9. Commented source code --this ought to be easy enough to understand
  10. ---WRONG!!! After a couple of hours (with my trusty elementary text in
  11. hand) a few rays of light penetrated the darkness! This was great
  12. stuff and I was even starting to understand a bit of what he did! It
  13. did make my head ache, though! Anyway, I learned a couple of things
  14. from reading all of that code --- It takes a heap of code to construct
  15. a meaningful program and there are several ways to get the same job
  16. done. 
  17.      As an example, let's take a look at something simple --a loop.
  18. That is an easy and painless start! For the purposes of this
  19. illustration, we will assume that the guts of the loop are coded
  20. identically and only a few selected lines will change.  You will see
  21. what I mean when we get into the program segment. 
  22.      Let's start with the first one: 
  23.  
  24.         LI   R6,4             Load the loop limit (4) into register 6 
  25.         |     | 
  26. LOOP    |      
  27.       loop contents 
  28.       and instructions 
  29.         |     | 
  30.         |     | 
  31.         AI   R6,-1   Add -1 to the loop counter in R6 after each pass 
  32.  
  33.         JNE  LOOP    Compare the result of the arithmetic function to 
  34.                      zero and jump back to rerun LOOP if not equal to 
  35.                      zero 
  36.  
  37.      Easy enough so far! But, being a sneaky and devious language,
  38. there is another simple way to do the very same thing. 
  39.  
  40.        LI    R6,4             Load loop limit (4) into register 6 
  41.        |      | 
  42. LOOP   |      | 
  43.       loop contents 
  44.       and instructions 
  45.        |      | 
  46.        |      | 
  47.        DEC   R6               Decrement R6 by one 
  48.  
  49.        JNE   LOOP             Same as the first example 
  50.  
  51.      These are just two examples of how to code the very same idea in
  52. different ways.  In the examples we used A(dd)I(mmediate) and
  53. DEC(rement) to effectively reduce the value in R6 by one in each
  54. iteration of the loop until a value of zero was reached at which time
  55. control was passed to another program segment. 
  56.      Of course, the converse is true as well.  By using a positive
  57. value after AI, we can create an incrementing loop.  The AI
  58. instruction can be replaced just as easily by INC(rement).  So we have
  59. created to instructions that perform the same function. 
  60.  
  61.        AI    R6,1 
  62.  
  63. and 
  64.        INC   R6 
  65.      An incrementing loop takes a bit more "engineering" to switch
  66. control when the loop limit has been reached but that is a minor
  67. inconvenience.  In fact, even with my feeble experience in A/L
  68. programming I can think of four or five other ways to construct a
  69. basic loop --either decrementing or incrementing it as the case may
  70. be. 
  71.      I guess that we are just about done with the preliminaries.  We
  72. have covered addressing modes, number conversions, and figured out
  73. that there is no "right way" to write an A/L program --just different
  74. ways.  Now we can start a bit of poking about! 
  75.      Before we get started, there are a few definitions that we have
  76. to become familiar with so we know what we are doing (?). 
  77.  
  78. Bit - a single binary digit 
  79.  
  80. Niblet - two bits 
  81.  
  82. Nibble - Four bits 
  83.  
  84. Byte - eight bits 
  85.  
  86. Word - two bytes (16 bits) 
  87.  
  88.      Ok, since I've hacked about a bit in A/L I have discovered that
  89. there are some instructions that are used a lot more than others.  The
  90. whole lot of them fits into a series of categories.  It's time to look
  91. at one of them.  These are the instructions that move data about in a
  92. program 
  93.  
  94. Name             OpCode       Comments 
  95. ~~~~             ~~~~~~       ~~~~~~~~ 
  96.  
  97. Move Word        MOV   This instruction can use any of the 5 general 
  98.                        addressing modes 
  99.  
  100. Move Byte        MOVB  Same as above 
  101.  
  102. Swap Bytes       SWPB  Same as above 
  103.  
  104. Load Immediate   LI    Register direct mode using immediate addressing 
  105.  
  106. Load Wkspace poi LWPI  Immediate addressing 
  107.  
  108. Load Int Mask Im LIMI  Immediate addressing 
  109.  
  110. Store Wkspace P  STWP  Register direct mode 
  111.  
  112. Store Status     STST  Register direct mode 
  113.  
  114. Shift Rt Logical SRL   Register direct mode with a count value 
  115.  
  116. Shift Rt Arith   SRA   Same as above 
  117.  
  118. Shift Rt Circ.   SRC   Same as above 
  119.  
  120. Shift Left Arith SLA   Same as above  
  121.  
  122.      The most commonly used instructions are the first five and the
  123. last four in the list.  Even amongst that group, there are a couple
  124. that do most of the work and we will take a look at them now. 
  125.  
  126. MOV   Source operand, Destination Operand 
  127.  
  128. example: 
  129.  
  130. MOV R1,R6 moves (or copies) the contents of R1 into R6 
  131.  
  132.      MOVB does the same thing except that it moves just 8 bits instead
  133. of 16 like MOV does. 
  134.  
  135. LI    Register, Operand 
  136.  
  137. example: 
  138.  
  139. LI    R1,10     loads 10 into R1 
  140.  
  141.      LWPI functions the same except that the operand is loaded into a
  142. workspace. 
  143.  
  144. SWPB  Register 
  145.  
  146. example: 
  147.  
  148. SWPB R7
  149.      Swaps or switches the right and left bytes of the word in R7. 
  150.  
  151.      All of this has made me a bit thirsty.  It's time to satisfy the
  152. inner man.  I hope that you will see where all of this is headed as I
  153. try to cope with the rest of this A/L stuff that Tony and Ron got me
  154. started on.  Oh well, jot down some notes and I'll continue this next
  155. month and hopefully it will lead somewhere besides insanity! 
  156.  
  157.