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

  1. ORIGINALLY PUBLISHED IN LIMA NEWSLETTER DECEMBER 1993
  2.  
  3. December 1993 BB&P Editor's note:  The following article by Bob
  4. Carmany is the first in a series.  This first article in the series
  5. was published several years ago in the Hunter Valley (Australia) user
  6. group's newsletter.  The rest of the series, which will appear in
  7. futue issues of BB&P, has not previously been published. 
  8.      ---------------------------------------------------------- 
  9.                            Assembler Executing . . . 
  10.                                By Bob Carmany 
  11.  
  12.      (This is going to be a series of narrations about my "adventures"
  13. through the wonderous world of Assembly Language.  I have Ron
  14. Kleinschafer and Tony McGovern to thank for prodding me into this. If
  15. I can try it, anyone can!) 
  16.      The first thing to do is to find a book for the beginner dealing
  17. with the basic ideas of Assembly Language (hereafter called "A/L").  I
  18. discovered much to my dismay that the rather extensive manual that
  19. comes with the E/A cartridge assumes a prior knowledge of A/L.
  20. Anyway, I finally found a rather elementary text on the subject and
  21. decided to spend some time learning to program in A/L -- after all, it
  22. was supposed to be easy! 
  23.      I quickly discovered that books aren't written in logical order.
  24. This one was making comparisons between XB and A/L coding and I
  25. decided that wasn't the best way to start.  You have to understand
  26. some basics before you can get tha far.  For example, there was a good
  27. deal of discussion of converting numbers from one base to another ---
  28. a good place to start! 
  29.      There are three number bases that we have to deal with in A/L
  30. programming. I could see that this was going to be fun! Binary (zero's
  31. and one's) is the only language that the computer understands.
  32. Fortunately, we no longer have to program in binary -- an interpreter
  33. does that for us.  The other two number bases are hexidecimal (base
  34. 16) and decimal (what we all learned in school).  I could see that
  35. this was getting easier all the time.  One of the number bases had
  36. already been eliminated.  All I had to do was learn how to convert a
  37. number from decimal to hexidecimal and vice versa. 
  38.      OK, let's see what the book has to say! You take the decimal
  39. number and divide it by radix 16.  I didn't know there was gardening
  40. involved in this! I have a whole row of radixes planted out back ---
  41. my error, that's radishes! Sorry, back to the task at hand.  This is
  42. awful! You have to keep track of these "F's" and "A's" when you divide
  43. the numbers for the conversions.  Anyway, I managed to get through the
  44. exercises in the book but it must have had the wrong answers in a
  45. couple of places because they didn't agree with my results at all! I
  46. could see right off that I had been sold a "blind horse" by Ron and
  47. Tony! You know what? I got through the whole chapter and you know what
  48. the book said? "The easiest way is to use a decimal to hexidecimal
  49. calculator or a computer program to do the calculations for you".
  50. Hmmm! I think I just happen to have a program that does that.  In
  51. fact, it gives you the equivalent in all three bases! So much for that
  52. chapter and here is the conversion program. 
  53.  
  54.  
  55. 100 ON WARNING NEXT :: CALL CLEAR :: H$="0123456789ABCDEF" :: PRINT
  56. "DEPRESS YOUR ALPHA LOCK KEY": :"PRESS LETTER FOR INPUT BASE": : 
  57.  
  58. 110 PRINT : :"D=DEC #  H=HEX #  B=BIN #": : :: CALL SOUND(80,660,6) 
  59.  
  60. 120 CALL KEY(0,K,S):: IF S<1 THEN 120 ELSE ON POS("DHB",CHR$(K),1)+1
  61. GOTO 110,13 0,140,150 
  62.  
  63. 130 INPUT "DEC #=":DEC :: IF DEC<-32768 OR DEC>65535 THEN 130 ELSE
  64. A,DEC=INT(DEC -65536*(DEC<0)):: GOSUB 200 :: GOSUB 220 :: GOTO 160 
  65.  
  66. 140 PRINT "HEX #=" :: ACCEPT AT(23,7)BEEP SIZE(4)VALIDATE(H$):HEX$ ::
  67. GOSUB 180 :: GOSUB 200 :: GOTO 160 
  68.  
  69. 150 PRINT "BIN #=" :: ACCEPT AT(23,7)BEEP SIZE(16)VALIDATE("10"):BIN$
  70. :: GOSUB 90 :: GOSUB 220 :: GOSUB 210 
  71.  
  72. 160 A=INT(DEC/256):: PRINT :"D=";DEC;TAB(12);A;DEC-A*256 :: IF
  73. DEC>32767 THEN PR INT " ";DEC-65536 
  74.  
  75. 170 PRINT "H= ";HEX$:"B= ";SEG$(BIN$,1,8)&&" "&&SEG$(BIN$,9,8)::
  76. HEX$,BIN$="" :: A ,DEC=0 :: GOTO 110 
  77.  
  78. 180 HEX$=SEG$("0000",1,4-LEN(HEX$))&&HEX$ :: FOR I=1 TO 4 ::
  79. A,DEC=DEC+(POS(H$,SEG$(HEX$,I,1),1)-1)*16^(4-I):: NEXT I :: RETURN 
  80.  
  81. 190 FOR I=1 TO LEN(BIN$)::
  82. DEC=DEC-2^(I-1)*(SEG$(BIN$,(LEN(BIN$)+1-I),1)="1"):: NEXT I :: RETURN 
  83.  
  84. 200 A=A/2 :: BIN$=STR$(-(A-INT(A)<>0))&&BIN$ :: A=INT(A):: IF A THEN
  85. 200 
  86.  
  87. 210 BIN$=SEG$(RPT$("00",8),1,16-LEN(BIN$))&&BIN$ :: RETURN 
  88.  
  89. 220 A=DEC+65536*(DEC>32767) 
  90.  
  91. 230 HEX$=SEG$(H$,(INT(A/4096)AND 15)+1,1)&&SEG$(H$,(INT(A/256)AND
  92. 15)+1,1)&&SEG$(H $,(INT(A/16)AND 15)+1,1)&&SEG$(H$,(A AND 15)+1,1)::
  93. RETURN 
  94.  
  95.      Maybe this isn't going to be so bad after all.  I managed to
  96. finesse having to calculate all of those conversions by hand with a
  97. short program that I found in my library.  Let's see, there is
  98. something about registers in the next chapter. 
  99.      This one starts of with a rather innocent statement.  It says
  100. that there are three internal registers in the TI CPU --- the Program
  101. Counter. the Workspace Pointer, and the Status Register.  No worries,
  102. mate! This doesn't look to be too difficult! The Program Counter (PC)
  103. is a special register that keeps track of the address of the
  104. instruction to be performed.  After the instruction is performed, the
  105. CPU adjusts the address to the next instruction.  Right --- the same
  106. thing as a line number in XB! Geez, I might have to apologize to Ron
  107. and Tony for what I wrote earlier.  This isn't too bad so far! 
  108.      Now for the Workspace Pointer (WP) is another register that
  109. contains the address of the program's workspace.  Whew! A sentence
  110. that says absolutely nothing! OK, a workspace is a memory area of 16
  111. words of memory that are accessed faster than the rest of the
  112. computer's memory.  Each of these words is referred to as a working
  113. register.  Aha! I bet that is what they are talking about with those
  114. R0 to R15 things in the A/L source code.  That means that the
  115. Workspace Pointer must point to the first of the working registers --
  116. R0 --- and the rest must follow immediately in memory.  This stuff is
  117. getting a little more complicated but I think I can grasp the
  118. concept. 
  119.      Now for the last of these registers --- the Status Register (SR).
  120. The book says that it holds the individual status bits that are
  121. affected by the instructions are executed.  Now that makes no sense at
  122. all to me.  It seems that each of the status bits is affected
  123. differently depending on the instruction executed and they can be read
  124. by the conditional jump instructions to make the program branch to
  125. another routine.  That sound like the "IF --THEN" statement in XB.  I
  126. guess I'll have to wait until I work with the individual instructions
  127. to see which of the 16 status bits they affect.  Hey! They even
  128. provided a chart: 
  129.  
  130.  Name                     Abbreviation                  Bit Position 
  131.  ~~~~                     ~~~~~~~~~~~~                  ~~~ ~~~~~~~~ 
  132.  
  133.  Logical Greater Than       L>                              0 
  134.  Arithmetic Greater Than    A>                              1 
  135.  Equal                      EQ                              2 
  136.  Carry                      CY                              3 
  137.  Overflow                   OV                              4 
  138.  Odd Parity                 OP                              5 
  139.  Extended Operation         X                               6 
  140.  Not Used                   --                              7-11 
  141.  Interrupt Mask             I0-I3                           12-15 
  142.  
  143.      I've heard of some of these at one time or another but I guess
  144. I'll just have to wait and see how they can be tested and used by the
  145. various A/L instructions. 
  146.      All of this reading and writing has made my mouth dry! It's time
  147. for a cold Foster's (no Toohey's to be had here) and a bit of a rest
  148. before I start the second article in this series.  I think I'll look
  149. at the structure of a bit of source code and maybe see if I can
  150. translate some familiar XB statements into corresponding A/L source
  151. code.  That should be interesting! 
  152.