home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / alt / folklore / computer / 16443 < prev    next >
Encoding:
Internet Message Format  |  1992-11-19  |  6.6 KB

  1. Path: sparky!uunet!think.com!rst
  2. From: rst@think.com (Robert Thau)
  3. Newsgroups: alt.folklore.computers
  4. Subject: Re: ASSEMBLY LANGUAGE IBM
  5. Date: 19 Nov 1992 19:07:45 GMT
  6. Organization: Thinking Machines Corporation
  7. Lines: 145
  8. Message-ID: <1egom1INNdk1@early-bird.think.com>
  9. References: <16NOV92.12250000.0072@VM1.MCGILL.CA>
  10. NNTP-Posting-Host: turing.think.com
  11.  
  12. In article <16NOV92.12250000.0072@VM1.MCGILL.CA> IEGS@MUSICB.MCGILL.CA (IEGS) writes:
  13. >HOW COULD YOU SOLVE THIS:
  14. >DETERMINE HOW MANY MICRO-INSTRUCTIONS ARE REQUIRE TO PERFORM
  15. >THE ASSEMBLY INSTRUCTIONS WITH OPERATION CODES FROM 0 TO 4.
  16. >  WRITE A (MAC-1) ASSEMBLY IBM PROGRAM TO COMPUTE X = MIN(A,B)
  17. >{IF (A<B) X=A ELSE X=B}
  18. >PLEASE REPLY TO MC.BER
  19.  
  20. Many people have noted that a problem with this article is that it clearly
  21. comes from some guy trying to get the net to do his homework.  But there is
  22. an even worse problem, namely the failure to specify which IBM machine the
  23. code is for, nor which subroutine linkage conventions are in effect.  To
  24. show what effect these can have, here are some examples.  (I suppose that I
  25. should point out here that I'm doing this all from old manuals; corrections
  26. and embellishments by genuine old timers are much appreciated).  I begin
  27. with a code fragment for the type 709 electronic data-processing machine
  28. (using the FAP assembler):
  29.  
  30.        CLA       A            LOAD ACCUMULATOR WITH 'A'
  31.        CAS       B            COMPARE 'B'
  32.        CLA       B            IF B LESS THAN A, RELOAD ACCUMULATOR
  33.        NOP
  34.        STO       X            STORE LESSER QUANTITY IN X
  35.        ...
  36.  
  37. Readers who are unfamiliar with 709 assembly should note the action of the
  38. CAS instruction (Compare Accumulator with Storage), which skips one
  39. instruction if the number in the accumulator is equal to the addressed
  40. operand, and two if it is less.  The rest is straightforward.
  41.  
  42. The sequence above is suitable for open coding.  However, if we want to be
  43. able to call the minimum subroutine as a closed subroutine using the
  44. standard FORTRAN calling sequence for FUNCTION subprograms (i.e.,
  45.  
  46.        TSX       MYMIN,4
  47.        TSX       A
  48.        TSX       B
  49.        ...
  50.  
  51. with the addresses of the arguments placed in tagless TSX instructions),
  52. and place the result in the usual place (the accumulator), things get a
  53. little more complicated.  The easiest approach is to use indirect addressing:
  54.  
  55.  MYMIN CLA*      1,4
  56.        CAS*      2,4
  57.        CLA*      2,4
  58.        TRA       3,4 
  59.        TRA       3,4
  60.  
  61. where TRA 3,4 is the return sequence (transferring control to the third
  62. instruction after the TSX --- Transfer and Set Index --- in the calling 
  63. routine).  However, if we want to use the calling sequence of the library 
  64. routines (SINF, COSF, etc. --- we're talking FORTRAN II here, so the 'F' at 
  65. the end of the name has semantic content), then the arguments will be in 
  66. the AC and MQ, and we may use the following routine:
  67.  
  68.  MYMIN STQ       SAVEQ
  69.        CAS       SAVEQ
  70.        XCA
  71.        TRA       1,4
  72.        TRA       1,4
  73.  SAVEQ PZE
  74.  
  75. Here, the XCA instruction exchanges the contents of the AC and MQ, and the
  76. PZE (Plus ZEro) is a dummy operation which assembles a word of zero bits
  77. to reserve space.  (I might just as well have punched
  78.  
  79.  SAVEQ BSS       1
  80.  
  81. to reserve a Block (of one word) Starting with the Symbol SAVEQ, but for
  82. a block of fewer than 24 words, that would have wasted space in the object 
  83. deck.  FAP also supports a BES directive, for Block Ending with Symbol,
  84. should you want that).
  85.  
  86. At this point, the influence of the calling sequence ought to be clear.
  87. The above examples all have just about nothing in common, aside from the
  88. use of a CAS instruction.  However, the influence of the processor type can
  89. be even more overwhelming.  For instance, the first fragment above (open
  90. coded, with arguments at known addresses) might be coded as follows in 1401
  91. Autocoder:
  92.  
  93. MIN       ZA   A,X           COPY A TO X 
  94.           S    B,X           SUBTRACT B 
  95.           BWZ  USEB,X,K      BRANCH ON NEGATIVE DIFFERENCE...  
  96.           ZA   B,X 
  97.           B    OUT
  98. USEB      ZA   A,X
  99. OUT       ...
  100.  
  101. (My apologies to Autocoder purists for omitting the sequence numbers).
  102.  
  103. Here, the ZA instructions (Zero and Add) are 1401-ese for a
  104. memory-to-memory move (the 1401 having no accumulator).  The BWZ is a
  105. branch which tests the zone bits of the least significant character of the
  106. difference which has been developed in X; the K modifier makes it a test
  107. for a negative sign.  For this to work, the X field must have at least one
  108. more character of storage reserved for it than the larger of A and B.  It
  109. is assumed that all relevant word marks have been set in the memory in
  110. advance. 
  111.  
  112. Lastly, here's a version coded up in my best impression of SOAP, for the
  113. IBM 650:
  114.  
  115.         RAL    A
  116.         SL     B
  117.         MIN    STOA       STOB
  118. STOA    AL     8001
  119.         STL    RESULT     OUT
  120. STOB    STD    RESULT
  121. OUT     ...
  122.  
  123. Note that each 650 instruction has two addresses.  In most cases, these
  124. are the address of an operand, and the address of the next instruction.
  125. (The assembler defaults the latter so that straight-line code proceeds
  126. in sequence, but the programmer can set it explicitly to force an 
  127. unconditional branch).  However, in the case of conditional branch 
  128. instructions (e.g. the "MIN" above, a branch conditional on the sign of
  129. the accumulator), they are the addresses to use in the "true" and "false" 
  130. cases.
  131.  
  132. Users should note that this routine leaves the result in the distributor (a
  133. machine register which gets a copy of almost any word transferred between
  134. the drum and the CPU under program control, whose contents can be read at
  135. address 8001); fetching it from there may be much quicker than getting it
  136. back from address 'X', because it avoids the latency inherent in the 650's
  137. drum memory.  (Arithmetic overflow in the computation of the difference of
  138. A and B is not an issue, btw, since overflow in the lower accumulator will
  139. simply result in the extra digits appearing in the upper half).
  140.  
  141. At this point, it ought to be crystal clear that the real problem with
  142. "MC.BER"'s request is that it wasn't nearly specific enough.  However,
  143. there is another issue here which might affect answers even if it were;
  144. information on IBM machines of these early vintages is scarce enough that
  145. even if "MC.BER" had posed the question properly, the most charitably
  146. inclined reader might have trouble responding.  A while ago, someone was
  147. trying to start a project to put together a library of simulators for
  148. historic hardware (of which the 709/0 and the 650 are certainly examples);
  149. has anything happened on this?  Failing that, would there be any interest
  150. at all in detailed textual technical summaries?
  151.  
  152. (He couldn't possibly have been interested in current IBM hardware...
  153. just look where he posted the article!)
  154.  
  155. rst
  156.  
  157.