From: rst@think.com (Robert Thau)
Newsgroups: alt.folklore.computers
Subject: Re: ASSEMBLY LANGUAGE IBM
Date: 19 Nov 1992 19:07:45 GMT
Organization: Thinking Machines Corporation
NNTP-Posting-Host: turing.think.com

In article <16NOV92.12250000.0072@VM1.MCGILL.CA> IEGS@MUSICB.MCGILL.CA (IEGS) writes:
>HOW COULD YOU SOLVE THIS:
>DETERMINE HOW MANY MICRO-INSTRUCTIONS ARE REQUIRE TO PERFORM
>THE ASSEMBLY INSTRUCTIONS WITH OPERATION CODES FROM 0 TO 4.
>  WRITE A (MAC-1) ASSEMBLY IBM PROGRAM TO COMPUTE X = MIN(A,B)
>{IF (A<B) X=A ELSE X=B}
>PLEASE REPLY TO MC.BER

Many people have noted that a problem with this article is that it clearly
comes from some guy trying to get the net to do his homework.  But there is
an even worse problem, namely the failure to specify which IBM machine the
code is for, nor which subroutine linkage conventions are in effect.  To
show what effect these can have, here are some examples.  (I suppose that I
should point out here that I'm doing this all from old manuals; corrections
and embellishments by genuine old timers are much appreciated).  I begin
with a code fragment for the type 709 electronic data-processing machine
(using the FAP assembler):

       CLA       A            LOAD ACCUMULATOR WITH 'A'
       CAS       B            COMPARE 'B'
       CLA       B            IF B LESS THAN A, RELOAD ACCUMULATOR
       NOP
       STO       X            STORE LESSER QUANTITY IN X
       ...

Readers who are unfamiliar with 709 assembly should note the action of the
CAS instruction (Compare Accumulator with Storage), which skips one
instruction if the number in the accumulator is equal to the addressed
operand, and two if it is less.  The rest is straightforward.

The sequence above is suitable for open coding.  However, if we want to be
able to call the minimum subroutine as a closed subroutine using the
standard FORTRAN calling sequence for FUNCTION subprograms (i.e.,

       TSX       MYMIN,4
       TSX       A
       TSX       B
       ...

with the addresses of the arguments placed in tagless TSX instructions),
and place the result in the usual place (the accumulator), things get a
little more complicated.  The easiest approach is to use indirect addressing:

 MYMIN CLA*      1,4
       CAS*      2,4
       CLA*      2,4
       TRA       3,4 
       TRA       3,4

where TRA 3,4 is the return sequence (transferring control to the third
instruction after the TSX --- Transfer and Set Index --- in the calling 
routine).  However, if we want to use the calling sequence of the library 
routines (SINF, COSF, etc. --- we're talking FORTRAN II here, so the 'F' at 
the end of the name has semantic content), then the arguments will be in 
the AC and MQ, and we may use the following routine:

 MYMIN STQ       SAVEQ
       CAS       SAVEQ
       XCA
       TRA       1,4
       TRA       1,4
 SAVEQ PZE

Here, the XCA instruction exchanges the contents of the AC and MQ, and the
PZE (Plus ZEro) is a dummy operation which assembles a word of zero bits
to reserve space.  (I might just as well have punched

 SAVEQ BSS       1

to reserve a Block (of one word) Starting with the Symbol SAVEQ, but for
a block of fewer than 24 words, that would have wasted space in the object 
deck.  FAP also supports a BES directive, for Block Ending with Symbol,
should you want that).

At this point, the influence of the calling sequence ought to be clear.
The above examples all have just about nothing in common, aside from the
use of a CAS instruction.  However, the influence of the processor type can
be even more overwhelming.  For instance, the first fragment above (open
coded, with arguments at known addresses) might be coded as follows in 1401
Autocoder:

MIN       ZA   A,X           COPY A TO X 
          S    B,X           SUBTRACT B 
          BWZ  USEB,X,K      BRANCH ON NEGATIVE DIFFERENCE...  
          ZA   B,X 
          B    OUT
USEB      ZA   A,X
OUT       ...

(My apologies to Autocoder purists for omitting the sequence numbers).

Here, the ZA instructions (Zero and Add) are 1401-ese for a
memory-to-memory move (the 1401 having no accumulator).  The BWZ is a
branch which tests the zone bits of the least significant character of the
difference which has been developed in X; the K modifier makes it a test
for a negative sign.  For this to work, the X field must have at least one
more character of storage reserved for it than the larger of A and B.  It
is assumed that all relevant word marks have been set in the memory in
advance. 

Lastly, here's a version coded up in my best impression of SOAP, for the
IBM 650:

        RAL    A
        SL     B
        MIN    STOA       STOB
STOA    AL     8001
        STL    RESULT     OUT
STOB    STD    RESULT
OUT     ...

Note that each 650 instruction has two addresses.  In most cases, these
are the address of an operand, and the address of the next instruction.
(The assembler defaults the latter so that straight-line code proceeds
in sequence, but the programmer can set it explicitly to force an 
unconditional branch).  However, in the case of conditional branch 
instructions (e.g. the "MIN" above, a branch conditional on the sign of
the accumulator), they are the addresses to use in the "true" and "false" 
cases.

Users should note that this routine leaves the result in the distributor (a
machine register which gets a copy of almost any word transferred between
the drum and the CPU under program control, whose contents can be read at
address 8001); fetching it from there may be much quicker than getting it
back from address 'X', because it avoids the latency inherent in the 650's
drum memory.  (Arithmetic overflow in the computation of the difference of
A and B is not an issue, btw, since overflow in the lower accumulator will
simply result in the extra digits appearing in the upper half).

At this point, it ought to be crystal clear that the real problem with
"MC.BER"'s request is that it wasn't nearly specific enough.  However,
there is another issue here which might affect answers even if it were;
information on IBM machines of these early vintages is scarce enough that
even if "MC.BER" had posed the question properly, the most charitably
inclined reader might have trouble responding.  A while ago, someone was
trying to start a project to put together a library of simulators for
historic hardware (of which the 709/0 and the 650 are certainly examples);
has anything happened on this?  Failing that, would there be any interest
at all in detailed textual technical summaries?

(He couldn't possibly have been interested in current IBM hardware...
just look where he posted the article!)

rst

Newsgroups: alt.folklore.computers