home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols100 / vol173 / 8080.hlp < prev    next >
Encoding:
Text File  |  1984-07-15  |  40.0 KB  |  977 lines

  1. Introduction.
  2. 8080 Registers.
  3. 8080 Flags.
  4. 8080 Instructions.
  5. Data Movement.
  6. Assembler Organization.
  7. Assembler Directives.
  8. Comments.
  9. First Pass.
  10. Second Pass.
  11. Intel HEX Files.
  12. Listing of the Object Code.
  13. Bibliography.
  14. :Introduction.
  15.  
  16. This Help File is is intended to supplement 8080.CNV, an assembler for the
  17. Intel 8080 written in CNVRT. Half of the file contains a description of the
  18. registers, flags, and instructions of the 8080; the other half contains an
  19. introduction to assemblers and their operation.
  20.  
  21. The 8080 architecture is one of the architectures, like that of the PDP-8
  22. or the PDP-11, which deserves to be called "classic." This is not to say
  23. that it is free of compromises or without criticism. Rather, it is 1) Free
  24. of major blunders, and 2) Extremely logical and selfconsistent. This it turn
  25. implies that considerable care and expreience went into its original design.
  26.  
  27. There exist various assemblers for the Intel 8080, coinciding in the majority
  28. of their notation, but differing slightly in details and the number of user
  29. conveniences which they offer. 8080.CNV will assemble code written for the
  30. Digital Research ASM.COM, provided that all references to the same symbol are
  31. given with the same case combination (label, Label, LABEL are all distinct).
  32. It accepts "dc" as well as "db" to introduce ASCII character strings, the
  33. former terminated by a sign-flagged byte. Operation codes must be lowercase.
  34.  
  35.  
  36. -
  37. :8080 Registers.
  38. Compared to previous architectures in which the only active registers were the
  39. accumulator and program counter, the Intel 8080 has a fairly large assortment
  40. of active registers. Many are one byte registers, some of these can be used as
  41. pairs, and some are exclusively two byte registers. The following diagram shows
  42. the possible pairings, which makes it a useful representation to remember.
  43.  
  44.         -----------------
  45.         |   A   |   F   |
  46.         --------+--------
  47.         |   B   |   C   |
  48.         --------+--------
  49.         |   D   |   E   |
  50.         --------+--------
  51.         |   H   |   L   |  ------->  M
  52.         -----------------
  53.         |       PC      |
  54.         -----------------
  55.         |       SP      |
  56.         -----------------
  57.  
  58. "M" is not a specific register; it is the byte in memory that HL designates.
  59. -
  60. Six of the registers, B, C, D, E, H, L can be combined into pairs as well as
  61. being used individually. There is only one combination to which each one can
  62. belong when it is paired, namely B with C, D with E, and H with L. Two more
  63. eight bit registers exist - the accumulator A and the flag register F. They
  64. are also paired for the purpose of pushes and pops.
  65.  
  66. A: The accumulator is the site of all binary arithmetic and logical operations
  67.     except for four two-byte additions in which the pair HL is one of the
  68.     participants.
  69.  
  70. F: The flag register contains five one-bit status registers: zero, sign, carry,
  71.     half-carry, and parity. The bits are set according to the results of
  72.     arithmetic and logical operations, or by some explicit instructions.
  73.     The status bits are consulted for all the conditional calls, jumps,
  74.     and returns; but neither they nor the "F" register they can be accessed
  75.     directly. The register "F" is paired with the accumulator A for pushes
  76.     and pops; so it may be put in another register and consulted indirectly
  77.     using pushes and pops.
  78.  
  79.     The flag register does not reflect the instantaneous state of the
  80.     accumulator; rather the bits are determined by certain instructions
  81.     and are unaffected by others.
  82. -
  83. B and C: This pair is the hardest to load, typical loading sequences being
  84.     <lxi b,xxxx>, <lhld xxxx>, <mov c,l>, <mov b,h>, or <pop b>. It is
  85.     frequently used as a counter, but it is a memory pointer when the
  86.     ldax and stax instructions are used.
  87.  
  88. D and E: Since <xchg> can be used to exchange this pair with the pair HL, it
  89.     is relatively easy to load. A typical usage is for holding two-byte
  90.     arguments which have to be fetched from the memory, because of the
  91.     convenience of the sequence <lhld xxxx>, <mov e,m>, <inx h>, <mov d,m>,
  92.     <xchg>. The same sequence permits indirect address chains. <ladx d>
  93.     and <stax d> make it a useful memory pointer; a short loop generating
  94.     a block move uses the sequence <xxxx: ldax d>, <mov m,a>, <inx h>,
  95.     <inx d>, <dcr b>, <jnz xxxx>. In this loop, DE is the source pointer,
  96.     HL is the destination pointer, with register B as a byte counter.
  97.  
  98. H and L: A two-byte accumulator of limited capacity is formed by this pair. It
  99.     can be loaded and stored in one instruction by lhld and shld; some of
  100.     the other two byte registers can be added to it (BC, DE, HL, SP). In
  101.     addition it functions as a memory pointer. This use is important enough
  102.     that the byte to which it points is accorded the status of "register"
  103.     in all the instructions which deal with single-byte registers.
  104.  
  105. -
  106. PC: The Program Counter is found in all computer architectures; it allows the
  107.     serial use of the contents of memory as program instructions by always
  108.     pointing to the next instruction in sequence and incrementing by the
  109.     required amount during the fetching of that instruction. It cannot be
  110.     used directly by the programmer, however its use is implicit in every
  111.     jump, call or return instruction and likewise in every "immediate"
  112.     instruction.
  113.  
  114. SP: The stack pointer is a recent acquisition of computer architecture, whose
  115.     incorporation in the register complement of the Intel 8080 was one of
  116.     the innovative features of its design. Although it participates in all
  117.     pushes and pops, the fact that it gives the <call> instruction a place
  118.     to deposit its return address without interference from successive
  119.     there is hardly a CPU that does not have at least one stack pointer.
  120.     calls is the foundation of convenient recursive programming. Nowadays
  121.     there is hardly a CPU which does not have at least one stack pointer.
  122.  
  123.     The Intel 8080's stack pointer runs downward in memory, so that the
  124.     stack of a program can be started at the top of memory. <push> first
  125.     decrements the stack pointer, then stores the high order byte of its
  126.     register pair, decrements again and stores the low order byte. <pop>
  127.     follows the same sequence in reverse.
  128. -
  129. :8080 Flags.
  130.  
  131. The Intel 8080 uses five flags to indicate the status of the CPU. These are
  132.  
  133.         ---------------------------------
  134.         | s | z | . | h | . | p | . | c |
  135.         ---------------------------------
  136.  
  137.         s    sign of the accumulator
  138.         z    zero/nonzero accumulator
  139.         h    half carry - used by DAA
  140.         p    parity of the accumulator
  141.         c    carry from the accumulator
  142.  
  143. In a departure from previous practice, the flag bits bits do not reflect the
  144. instantaneous state of an extended accumulator; rather they are given values by
  145. only certain instructions, and conserve the previous state of the accumulator
  146. while the remaining instructions are executed. Data can be loaded or stored
  147. during multiple byte arithmetic, pointers modified and counters adjusted, all
  148. without interfering with the fact that the flags bear the state of the last
  149. arithmetic or logical operation.
  150.  
  151. -
  152. The collection of flags lacks the "overflow" bit which appears in later designs
  153. such as the Intel 8086 and in the Motorola 6800 series. Since an overflow bit
  154. is merely convenient, but not logically necesssary, it is not clear whether it
  155. was omitted for economy of design or because its convenience was not generally
  156. appreciated at the time. It is not needed for pure address arithmetic, but is
  157. very useful for computing with signed integers.
  158.  
  159. We can only speculate as to why the flag bits are arranged into a byte as they
  160. are. Save for the sign flag, which occupies the same position as the sign bit
  161. in an ordinary byte, the significant bits alternate with "undefined" bits which
  162. may or may not have an actual internal use within the CPU. Carry falls in a
  163. natural place were there multibyte arithmetic; however the placement of flag
  164. bits is only meaningful within the byte which is brought into existence when
  165. it is combined with the accumulator for <push psw> and <pop psw>.
  166.  
  167. Pushing and popping "PSW" has two evident purposes. The most likely is to
  168. save a previous state of the CPU, as during the servicing of an interrupt.
  169. Since the flags can change at any time, and since the accumulator is often
  170. used in the execution of an instruction, they are a good pair to save together.
  171. They are usually saved at once; additional registers can be saved as needed.
  172.  
  173.  
  174. -
  175. The only effective way to read or set the flag bits - certainly the only way
  176. that they can all be gotten at once - is to use some sequence like <push psw>
  177. <pop b> <mov a,b>, and then extract the desired bit with an <ani xx>. Using
  178. <push psw> and <pop psw> to access the flag bits is the other common use of
  179. these instructions, but much less frequent than for saving the machine state.
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197. -
  198. In detail, the characteristics of the flags are the following:
  199.  
  200. S - sign: Most integer arithmetic in computers is modular arithmetic, whose
  201.     modulus corresponds to the word length; in the case of bytes it is
  202.     arithmetic modulo 2**8 or 256. It is not an intrinsic property of
  203.     modular arithmetic that some numbers are positive, others negative.
  204.     Only the full set of natural integers can be ordered in the strict
  205.     mathematical sense - it is notorious that "large" integers turn out
  206.     to be "negative" in computer arithmetic.
  207.  
  208.     Nevertheless the convention exists that the cycle of modular integers
  209.     should be split in the middle, using the high order bit to distinguish
  210.     "positive" and "negative" integers from one another; the convention
  211.     works well enough if "large" integers are not used. The creation of
  212.     the concept of overflow was a response to the need to determine quite
  213.     accurately where the frontier of largeness yields to negativity.
  214.  
  215.     For all practical purposes, the sign bit is simply the high order bit
  216.     in the byte. The value that it acquired at certain moments can be
  217.     ascertained by testing the sign flag.
  218.  
  219.  
  220. -
  221. Z - zero: That the accumulator is zero is definite enough - all its bits have
  222.     to be zero. The zero flag preserves this information from the time that
  223.     certain specific instructions were executed.
  224.  
  225. H - half carry:  Half carry or auxiliary carry is an artifact of the relation
  226.     of bytes to decimal numbers, namely that it requires a minimum of four
  227.     bits to represent a single decimal number, that there is an excess over
  228.     ten digits that four bits can represent, and that two four-bit numbers
  229.     can be packed in a byte. If the CPU worked with nibbles - four bits -
  230.     rather than bytes, half-carry would be full-carry.
  231.  
  232.     The only instruction which uses half-carry is DAA [Decimal Adjust
  233.     Accumulator], and its presence is due to the prospect of employing
  234.     the CPU in commercial applications requiring a large amount of simple
  235.     decimal arithmetic. However, the half-carry bit must be set by the
  236.     arithmetic instructions before DAA can be used to compensate the gap
  237.     between ten and sixteen resulting from the difference in number bases.
  238.  
  239.     Although half-carry can be read from the flag byte, it can also be
  240.     set or tested by adding the hexadecimal number 66 or AA.
  241.  
  242.  
  243. -
  244. P - parity: The parity of a byte is the number of ones which it contains,
  245.     modulo 2; in other words whether it has an even or an odd number of
  246.     ones. This is a concept rarely used in computations, but it is a
  247.     quantity that was apparently included among the flags of the 8080
  248.     because of the liklihood that that microcomputer would be used in
  249.     communications equipment. Bytes transmited according to the 8 channel
  250.     teletype code include a parity bit whose automatic computation can
  251.     be convenient in the proper context.
  252.  
  253.     In any event, parity gives an alternative to the sign but for dividing
  254.     the universe of bytes into two equal halves, and so can sometimes be
  255.     used for classifying data.
  256.  
  257. C - carry: The carry bit is as extension of the accumulator.  Because it is
  258.     an extension, it is usually dropped after each arithmetic operation is
  259.     completed - otherwise the length of data would keep growing. Given that
  260.     carry is an essential part of an arithmetic calculation, it has to be
  261.     preserved long enough that it can be definitively saved, or for it to
  262.     affect the subsequent course of the computation. The carry flag does
  263.     just this. Kept transiently, carry helps determine the result of a
  264.     comparison, to continue a multibyte arithmetic operation, or many
  265.     other things.
  266. -
  267. Distribution of z, s, and parity over 256 possible bytes.
  268.  
  269.         \    00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
  270.        00   ze  o  o  e  o  e  e  o  o  e  e  o  e  o  o  e
  271.        01    o  e  e  o  e  o  o  e  e  o  o  e  o  e  e  o
  272.        02    o  e  e  o  e  o  o  e  e  o  o  e  o  e  e  o
  273.        03    e  o  o  e  o  e  e  o  o  e  e  o  e  o  o  e
  274.        04    o  e  e  o  e  o  o  e  e  o  o  e  o  e  e  o
  275.        05    e  o  o  e  o  e  e  o  o  e  e  o  e  o  o  e
  276.        06    e  o  o  e  o  e  e  o  o  e  e  o  e  o  o  e
  277.        07    o  e  e  o  e  o  o  e  e  o  o  e  o  e  e  o
  278.        08   so se se so se so so se se so so se so se se so
  279.        09   se so so se so se se so so se se so se so so se
  280.        0A   se so so se so se se so so se se so se so so se
  281.        0B   so se se so se so so se se so so se so se se so
  282.        0C   se so so se so se se so so se se so se so so se
  283.        0D   so se se so se so so se se so so se so se se so
  284.        0E   so se se so se so so se se so so se so se se so
  285.        0F   se so so se so se se so so se se so se so so se
  286.  
  287.  
  288.  
  289. -
  290. :8080 Instructions
  291.  
  292. The Intel 8080 has a very systematic instruction format, in which the
  293. 8 bit instruction code is divided into three fields of 2, 3 and 3 bits.
  294.  
  295.         -----------------
  296.         |q|q|d|d|d|s|s|s|
  297.         -----------------
  298.  
  299. The first two bits define a "quadrant" within each of which there is a
  300. greater or lesser degree of uniformity. Quadrants 1 and 2 are extremely
  301. uniform; quadrants 0 and 3 are best subdivided into octets. There is
  302. still a variation within the octets although the majority of them show
  303. high internal consistency. For example, the conditional calls, returns,
  304. and jumps follow the same ordering according to the condition tested.
  305.  
  306. The second field is the "destination" field, the third is the "source"
  307. field. In quadrant 1, the quadrant of movements between registers, these
  308. names are quite literally descriptive. In quadrant 2, the quadrant of
  309. arithmetic-logical operations, the source still refers to the register
  310. from which an operand will be taken, but the "destination" is poetic,
  311. since the field is used to enumerate the operations in a certain order.
  312. -
  313. The quadrants can be characterized as follows:
  314.  
  315.         0    movement from registers to memory
  316.         1    movement from one 8-bit register to another
  317.         2    arithmetic and logic between register and accumulator
  318.         3    movement of data to and from program counter
  319.  
  320. The 8-bit or one byte registers are numbered as follows:
  321.  
  322.         0    B
  323.         1    C
  324.         2    D
  325.         3    E
  326.         4    H
  327.         5    L
  328.         6    M    M = (HL)
  329.         7    A    accumulator
  330.  
  331. "Memory" is not a single register, but it is the byte in memory designated
  332. by the register pair HL. This was one of the innovative concepts that made
  333. its appearance in the 8080 instruction set.
  334.  
  335. -
  336. The arithmetic-logical instructions are systematically numbered.
  337.  
  338.         0    add    add
  339.         1    adc    add with carry
  340.         2    sub    subtract
  341.         3    sbb    subtract with borrow
  342.         4    and    logical and
  343.         5    xor    logical exclusive or
  344.         6    or    logical or
  345.         7    cmp    compare (subtraction preserving accumulator)
  346.  
  347. Conditional instructions can be enumerated according to the condition:
  348.  
  349.         0    nz
  350.         1    z
  351.         2    c
  352.         3    nc
  353.         4    po
  354.         5    pe
  355.         6    p
  356.         7    m
  357.  
  358. -
  359. The instructions which affect the accumulator and the flags form an octet
  360.  
  361.         0    rlc
  362.         1    rrc
  363.         2    ral
  364.         3    rar
  365.         4    daa    decimal adjust accumulator
  366.         5    cma    complement accumulator
  367.         6    stc    set carry
  368.         7    cmc    complement carry
  369.  
  370. The register pairs are naturally numbered by the high order member of the
  371. pair, but whether sp or psw is assigned the number 6 depends on whether the
  372. instruction lies in quadrant 0 or quadrant 3
  373.  
  374.         value        quad 0        quad 3
  375.  
  376.           0          bc          bc
  377.           2          de          de
  378.           4          hl          hl
  379.           6          psw          sp
  380.  
  381. -
  382.  
  383. Quadrant 0:
  384.  
  385.        00       01       02       03       04       05       06       07
  386.     -----------------------------------------------------------------
  387.    00   |nop    |lxi b,    |stax b    |inx b    |inr b    |dcr b    |mvi b,    |rlc    |
  388.    01    |...    |dad b    |ldax b    |dcx b    |inr c    |dcr c    |mvi c,    |rrc    |
  389.    02    |...    |lxi d,    |stax d    |inx d    |inr d    |dcr d    |mvi d,    |ral    |
  390.    03    |...    |dad d    |ldax d    |dcx d    |inr e    |dcr e    |mvi e,    |rar    |
  391.    04    |...    |lxi h,    |shld    |inx h    |inr h    |dcr h    |mvi h,    |daa    |
  392.    05    |...    |dad h    |lhld    |dcx h    |inr l    |dcr l    |mvi l,    |cma    |
  393.    06    |...    |lxi sp,|sta    |inx sp    |inr m    |dcr m    |mvi m,    |stc    |
  394.    07    |...    |dad sp    |lda    |dcx sp    |inr a    |dcr a    |mvi a,    |cmc    |
  395.     -----------------------------------------------------------------
  396.  
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404. -
  405.  
  406. Quadrant 1:
  407.  
  408.        00       01       02       03       04       05       06       07
  409.     -----------------------------------------------------------------
  410.    00    |mov b,b|mov b,c|mov b,d|mov b,e|mov b,h|mov b,l|mov b,m|mov b,a|
  411.    01    |mov c,b|mov c,c|mov c,d|mov c,e|mov c,h|mov c,l|mov c,m|mov c,a|
  412.    02    |mov d,b|mov d,c|mov d,d|mov d,e|mov d,h|mov d,l|mov d,m|mov d,a|
  413.    03    |mov e,b|mov e,c|mov e,d|mov e,e|mov e,h|mov e,l|mov e,m|mov e,a|
  414.    04    |mov h,b|mov h,c|mov h,d|mov h,e|mov h,h|mov h,l|mov h,m|mov h,a|
  415.    05    |mov l,b|mov l,c|mov l,d|mov l,e|mov l,h|mov l,l|mov l,m|mov l,a|
  416.    06    |mov m,b|mov m,c|mov m,d|mov m,e|mov m,h|mov m,l|hlt    |mov m,a|
  417.    07    |mov a,b|mov a,c|mov a,d|mov a,e|mov a,h|mov a,l|mov a,m|mov a,a|
  418.     ----------------------------------------------------------------
  419.  
  420.  
  421.  
  422.  
  423.     mov m,m is replaced by hlt, perhaps to avoid the circuitry
  424.     for making a double memory reference in a single instruction.
  425.  
  426.  
  427. -
  428.  
  429. Quadrant 2
  430.  
  431.        00       01       02       03       04       05       06       07
  432.     -----------------------------------------------------------------
  433.    00    |add b    |add c    |add d    |add e    |add h    |add l    |add m    |add a    |
  434.    01    |adc b    |adc c    |adc d    |adc e    |adc h    |adc l    |adc m    |adc a    |
  435.    02    |sub b    |sub c    |sub d    |sub e    |sub h    |sub l    |sub m    |sub a    |
  436.    03    |sbb b    |sbb c    |sbb d    |sbb e    |sbb h    |sbb l    |sbb m    |sbb a    |
  437.    04    |ana b    |ana c    |ana d    |ana e    |ana h    |ana l    |ana m    |ana a    |
  438.    05    |xra b    |xra c    |xra d    |xra e    |xra h    |xra l    |xra m    |xra a    |
  439.    06    |ora b    |ora c    |ora d    |ora e    |ora h    |ora l    |ora m    |ora a    |
  440.    07    |cmp b    |cmp c    |cmp d    |cmp e    |cmp h    |cmp l    |cmp m    |cmp a    |
  441.     -----------------------------------------------------------------
  442.  
  443.  
  444.  
  445.  
  446.  
  447.  
  448.  
  449.  
  450. -
  451.  
  452. Quadrant 3
  453.  
  454.        00       01       02       03       04       05       06       07
  455.     -----------------------------------------------------------------
  456.    00    |rnz    |pop b    |jnz    |jmp    |cnz    |push b    |adi    |rst 0    |
  457.    01    |rz    |ret    |jz    |...    |cz    |call    |aci    |rst 1    |
  458.    02    |rnc    |pop d    |jnc    |out    |cnc    |push d    |sui    |rst 2    |
  459.    03    |rc    |...    |jc    |in    |cc    |...    |sbi    |rst 3    |
  460.    04    |rpo    |pop h    |jpo    |xthl    |cpo    |push h    |ani    |rst 4    |
  461.    05    |rpe    |pchl    |jpe    |xchg    |cpe    |...    |xri    |rst 5    |
  462.    06    |rp    |pop psw|jp    |di    |cp    |pushpsw|ori    |rst 6    |
  463.    07    |rm    |sphl    |jm    |ei    |cm    |...    |cpi    |rst 7    |
  464.     -----------------------------------------------------------------
  465.  
  466.  
  467.  
  468.  
  469.  
  470.  
  471.  
  472.  
  473. -
  474. Quadrant 0 - multiple byte instructions:
  475.         ---------------------------------
  476.         | . | 3 | . | . | . | . | 2 | . |
  477.         | . | . | . | . | . | . | 2 | . |
  478.         | . | 3 | . | . | . | . | 2 | . |
  479.         | . | . | . | . | . | . | 2 | . |
  480.         | . | 3 | 3 | . | . | . | 2 | . |
  481.         | . | . | 3 | . | . | . | 2 | . |
  482.         | . | 3 | 3 | . | . | . | 2 | . |
  483.         | . | . | 3 | . | . | . | 2 | . |
  484.         ---------------------------------
  485. Quadrant 3 - multiple byte instructions:
  486.         ---------------------------------
  487.         | . | . | 3 | 3 | 3 | . | 2 | . |
  488.         | . | . | 3 | . | 3 | 3 | 2 | . |
  489.         | . | . | 3 | 2 | 3 | . | 2 | . |
  490.         | . | . | 3 | 2 | 3 | . | 2 | . |
  491.         | . | . | 3 | . | 3 | . | 2 | . |
  492.         | . | . | 3 | . | 3 | . | 2 | . |
  493.         | . | . | 3 | . | 3 | . | 2 | . |
  494.         | . | . | 3 | . | 3 | . | 2 | . |
  495.         ---------------------------------
  496. -
  497. :Data Movement.
  498.  
  499. Aside from memory registers, which can be indicated in various ways by
  500. two-byte pointers, the Intel 8080 has an assortment of one- and two-byte
  501. active registers whose designation is an implicit part of most instructions.
  502. Some one-byte registers are simply the high or low bytes of some of the
  503. two-byte registers; alternatively it may be said that some of the one-byte
  504. registers may be combined to form two-byte registers. However, there is no
  505. flexibility in this arrangement, as only certain pairs of single byte registers
  506. can be combined into double byte registers, and none of these overlap.
  507.  
  508. The ports are also single byte registers which should be included in any
  509. enumeration of registers, but they interact only with the accumulator which
  510. leaves them at the margin of most discussions.
  511.  
  512. It is instructive to form a matrix, whose rows and columns are labelled by
  513. the different one- and two- byte registers, pointers, and memory locations
  514. which the latter can designate.  Much of the Intel 8080 instruction set can
  515. be illustrated by filling this matrix with the instructions which result in
  516. the movement of data in the directions indexed by the rows and columns.
  517.  
  518.  
  519. -
  520. Using (HL) to denote the memory location addressed by the register pair HL
  521. and similarly for other registers, we have to consider all the following
  522. locations:
  523.  
  524.         B    BC    (BC)
  525.         C
  526.         D    DE    (DE)
  527.         E
  528.         H    HL    (HL)=M
  529.         L
  530.         A    AF
  531.         F
  532.         port
  533.             PC    (PC)
  534.             SP    (SP)
  535.  
  536.  
  537. Altogether, this calls for a twenty by twenty matrix. On examination, much
  538. of the matrix will be empty, because the only registers for which systematic
  539. movement is possible are the single-byte registers in the instructions of
  540. quadrant 1. The remaining movement goes mostly on a case by case basis.
  541.  
  542. -
  543. dest:        B        C        D        E        H        L        M        A
  544. source:\|-------|-------|-------|-------|-------|-------|-------|-------|
  545.   B    |mov b,b|mov c,b|mov d,b|mov e,b|mov h,b|mov l,b|mov m,b|mov a,b|
  546.   C    |mov b,c|mov c,c|mov d,c|mov e,c|mov h,c|mov l,c|mov m,c|mov a,c|
  547.   D    |mov b,d|mov c,d|mov d,d|mov e,d|mov h,d|mov l,d|mov m,d|mov a,d|
  548.   E    |mov b,e|mov c,e|mov d,e|mov e,e|mov h,e|mov l,e|mov m,e|mov a,e|
  549.   H    |mov b,h|mov c,h|mov d,h|mov e,h|mov h,h|mov l,h|mov m,h|mov a,h|
  550.   L    |mov b,l|mov c,l|mov d,l|mov e,l|mov h,l|mov l,l|mov m,l|mov a,l|
  551.   M    |mov b,m|mov c,m|mov d,m|mov e,m|mov h,m|mov l,m|mov m,m|mov a,m|
  552.   A    |mov b,a|mov c,a|mov d,a|mov e,a|mov h,a|mov l,a|mov m,a|mov a,a|
  553.  (BC)    |                            |ldax b |
  554.  (DE)    |                            |ldax d |
  555.  (HL)    |same as M                            |
  556.  (PC)    |mvi b,%|mvi c,%|mvi d,%|mvi e,%|mvi h,%|mvi l,%|mvi m,%|mvi a,%|
  557.   port    |                            |in port|
  558.     |-------|-------|-------|-------|-------|-------|-------|-------|
  559.  
  560.  
  561.  
  562.  
  563.  
  564.  
  565. -
  566. dest:       BC       DE       HL       AF       SP       PC
  567. source:\|-------|-------|-------|-------|-------|-------|
  568.   DE    |    |    |xchg    |    |    |    |
  569.   HL    |    |xchg    |    |    |sphl    |pchl    |
  570.   SP    |    |    |dad sp    |    |    |    |
  571.  (SP)    |pop b    |pop d    |pop h    |pop psw|    |    |
  572.  (SP)    |        |xthl    |            |
  573.     |-------|-------|-------|-------|-------|-------|
  574.  
  575.  
  576.             |same as|
  577.             |M - see|
  578.             |above. |
  579. dest:      (BC)      (DE)    | (HL)    | (SP)      (PC)      port
  580. source:\|-------|-------|-------|-------|-------|-------|
  581.   A    |stax b    |stax d    |mov m,a|    |    |out p    |
  582.   BC    |    |    |    |push b    |    |    |
  583.   DE    |    |    |    |push d    |    |    |
  584.   HL    |    |    |    |push h    |    |    |
  585.   AF    |    |    |    |pushpsw|    |    |
  586.     |-------|-------|-------|-------|-------|-------|
  587.  
  588. -
  589. :Assembler Organization.
  590.  
  591. Assemblers vary greatly in complexity, according to the services which they
  592. offer. The simplest assemblers are not very useful, although they have their
  593. role in envoironments like DDT. They simply translate the mnemonics of some
  594. particular CPU into the binary code which corresponds. According to the degree
  595. to which both the instruction set of the machine and the choice of menmonics
  596. is logical and systematic, even this task will vary in complexity. This is why
  597. there is a tendency to claim a copyright on a well laid out set of mnemonics,
  598. for their design is every bit as important as the selection of the instructions
  599. in the first place.
  600.  
  601. An assembler crosses the threshold of usefulness when it can construct a symbol
  602. table, allowing points in the program and locations in memory to have symbolic
  603. designations. This is one of those routine tasks which computers are supposed
  604. to perform well - to figure out how long each instruction or other structure
  605. is, and so to calculate the address of all the components of the program in
  606. relation to an assumed starting point. Not only is much tedious work avoided,
  607. but it doesn't have to be repeated each time an insertion or deletion is made
  608. in the program. That is, it doesn't have to be repeated by the programmer,
  609. because it has to be done somehow.
  610.  
  611. -
  612. Beyond the ability to translate menmonics and calculate symbolic addresses,
  613. most of the additional services that an assembler can perform tend to lie in
  614. the class of luxuries. Some of the essential services include the definition
  615. or redefinition of the program origin, skipping space, and allocating space
  616. for specific constants, be they numerical or textual.
  617.  
  618. Some modest arithmetic is convenient; at the least, addition or subtraction
  619. which allows placement relative to symbolic addresses. The evaluation of
  620. general formulas will occupy space in the assembler, and soon creates the
  621. temptation to introduce special functions - maximum, minimum, shifts and
  622. rotations, and boolean operations. Some of this capacity is required by the
  623. desire to organize tables and organize programs by page and parity boundaries,
  624. all of which is characteristic of CPU's which have special requirements for
  625. word placement and work with a variety of data formats. Some vestiges of this
  626. are evident in the 8080, but can largely be avoided. The principal intrusion
  627. of alignment problems arises from the possibility of splitting a two-byte
  628. address in half, and working with 256-byte pages. The fact that <inr> and <dcr>
  629. set the zero flag, while <inx> and <dcx> modify no flags, generates a strong
  630. temptation to align data along page boundaries and work with pages.
  631.  
  632. Addressing relative to a location counter is not much favored, either for the
  633. Intel 8080 or other microcomputers, because of the variability of word length.
  634. -
  635. Some assemblers have elaborate features for formatting the assembly listing.
  636. These can include skipping lines, skipping up to a new page, suppressing code
  637. listing over certain parts of the assembly, and showing various degrees of
  638. detail in the process of macro expansion.
  639.  
  640. Macro assemblers form a class apart, considering the degree to which they are
  641. allowed to carry out symbolic manipulation. Not only do they tend to permit
  642. advanced formulations of algebraic formulas and functional notation; their
  643. primary usage is to set up complicated structural elements into which selected
  644. substitutions can be made each time they are used. They greatly simplify coding
  645. because of the concise way that they express program configurations which are
  646. frequently used. Their indiscriminate use is a hazard, just because of the ease
  647. with which they can multiply voluminous code.
  648.  
  649. Careful planning of an assembler will enhance the services which are rendered
  650. to the programmer. Since the construction of a symbol table is an inherent
  651. part of the assembly process, there is no reason that it cannot be presented
  652. as one of the byproducts of assembly. With some additional effort, it is even
  653. possible to produce a cross reference listing, in which each symbol is indexed
  654. by all the references to it throughout the program.
  655.  
  656. Its degree of error detection and analysis affects the utility of an essembler.
  657. -
  658. :Assembler Directives.
  659.  
  660. An assembler needs additional information, beyond labels and instructions. At
  661. the least, an indication of where the program begins and ends is needed. Data
  662. is part of most programs, both numerical and textual. There could be cosmetic
  663. instructions: start on a new page or suppress part of the program listing.
  664.  
  665. The most essential directives are:
  666.  
  667.         org    define initial program address
  668.         end    no more source code follows
  669.         equ    assign a value to a symbol
  670.         db    one or more bytes of ASCII text
  671.         dc    ASCII text terminated by a flagged byte
  672.         ds    reserve space, perhaps label first byte
  673.         dw    one or more addresses or two-byte data
  674.  
  675. Beyond bare essentials, assemblers can grow to have considerable complexity.
  676. For example, "include" can incorporate supplementary files in the text, while
  677. "link" can allow the program to be written on a series of independent files.
  678. Conditional assemblies, macros, or conditional macros are other possibilities.
  679.  
  680. -
  681. :Comments
  682.  
  683. Programs lose most of their value without written descriptions of their purpose
  684. and contents. The discipline required to prepare a separate document is a very
  685. great obstacle to its realization, so that often the user is satisfied to have
  686. a well commented program listing. Such a listing may have half of its volume or
  687. more in comments, which in turn can be seen as a drawback. Any overhead takes
  688. up disk space, and it consumes assembly time, so that all comments should be as
  689. terse as possible.
  690.  
  691. Full lines can be dedicated to comments, especially as paragraph headings of as
  692. introductions to subroutines. Such lines are conveniently marked by a semicolon
  693. in column 1, and can be dedicated to a general description of the content of
  694. the programming material which follows. If it is kept sufficiently general, it
  695. will not have to be revised when minor alterations or corrections are made to
  696. the program itself.
  697.  
  698. It is a good idea to introduce each program with a section stating its purpose,
  699. its requirements for such system resources as memory, disk space, or running
  700. time, and a history of its authorship and evolution. All this material would
  701. take the form of initial comments.
  702.  
  703. -
  704. Major sections can be set off by ornamental comments, such as a line of stars
  705. or a line of dashes, which can also be used to frame headings. Given that such
  706. embellishment uses up three or four score bytes at a time, it should be used
  707. sparingly.
  708.  
  709. Other comments apply to individual instructions, explaining them or some
  710. special characteristic of their use. Likewise, constants or parameters may be
  711. identified. It is particularly important to identify the use of each location
  712. used for temporary storage, each area used for a table or a buffer, and so on.
  713. These comments are set off from the rest of the code line by a semicomon, which
  714. can follow immediately the last field of the instruction. More commonly one or
  715. more tabs are used to align all the in-line comments in a single column towards
  716. the right hand side of the page.
  717.  
  718. Comments should convey as much relevant information as possible. Ofter a few
  719. extra words will make a comment much more significant. For example the z/nz
  720. comment in the following sequence is much more informative than a comment
  721. like "output file open." It tells the alternatives and their meaning.
  722.  
  723.         mvi   a,flag
  724.         ora   a        ;z/nz = file not/open
  725.         jz    open    ;open input file
  726. -
  727. The same type of detail should accompany the place where the flag is stored:
  728.  
  729.     flag:    ds    1        ;z/nz = input file not/open
  730.  
  731. It would be even better if a more suggestive name than "flag" were chosen.
  732.  
  733.  
  734.  
  735.  
  736.  
  737.  
  738.  
  739.  
  740.  
  741.  
  742.  
  743.  
  744.  
  745.  
  746.  
  747.  
  748.  
  749. -
  750. :First Pass.
  751.  
  752. Unless an assembler is simultaneously a loader, which will greatly restrict
  753. the size of program which it can handle, it needs two passes through the
  754. source code to complete the assembly. On the first pass, the length of each
  755. instruction, data block, or reserved area is calculated. While this is being
  756. done the labels can be assigned values as they are encountered, forming the
  757. symbol table. On the second pass, the actual code is substituted for each
  758. instruction and defined data is converted to binary form or its equivalent.
  759.  
  760. If the assembler did not permit multiple origin statements, the second pass
  761. would not have to calculate any lengths anew. The second pass is sometimes
  762. distinguished from a "third pass" in which an annotated listing is produced;
  763. the third pass displays program locations and so must keep a running count of
  764. lengths. Often the third pass is produced simultaneously with the second pass,
  765. either as an option or as a requirement.
  766.  
  767. Assemblers tend to produce an intermediate "hexadecimal" listing rather than
  768. a binary object code file. Partly the reason is historical, there being many
  769. uses for the paper tape that usually contained the hex-file. Practically, the
  770. reason is that the allocation of blank space implied by multiple origins or
  771. data reservation statements can be deferred to loading time.
  772. -
  773. The First Pass must then take one of the following actions for each
  774. possible constituent of the listing:
  775.  
  776.     action        line        affects
  777.     ------        ----        -------
  778.     quit        end
  779.     ignore        null line
  780.     ignore        comment line
  781.     record        equ        symbol table
  782.     record        label        symbol table
  783.     add 3        3-byte instr    program counter
  784.     add 2        2-byte instr    program counter
  785.     add 1        1-byte instr    program counter
  786.     add n        db        program counter
  787.     add n        dc        program counter
  788.     add 2n        dw        program counter
  789.     add n        ds        program counter
  790.     set pc        org        program counter
  791.     error        other
  792.  
  793.  
  794.  
  795. -
  796. Several choices can affect the completeness or the elegance of the assembler
  797. even in the first pass. For example, it is convenient to treat an error as
  798. though it were the longest instruction - three bytes - and place three NOP's
  799. in its place. It can be patched with DDT at run time without reassembly. This
  800. feature is obviously most likely to be used when patching is simple compared
  801. with running the assembly over again.
  802.  
  803. Of more importance is the treatment of symbolic expressions which occur as
  804. addresses, or as arguments of such directives as "org" or "ds." If all of
  805. the symbols in a directive have not been defined by the time the directive
  806. has been encountered, it will not be possible to decide how much space to
  807. allocate or where to allocate it. Supposing that the program is processed
  808. in its natural reading order, we find the rule that a symbol must be fully
  809. defined before it is used in an expression - particularly org or ds.
  810.  
  811. This rule does not have to be rigid, it is merely the simplest which will
  812. get the job done. If enough symbols have been acquired and possibly evaluated
  813. on the first pass that all the remaining symbols can be evaluated in time on
  814. the second pass, the assembly can still be carried through. To permit that an
  815. assembly extend beyond two passes is usually forsaken in favor of requiring
  816. more discipline in the program layout. Equivalences concentrated near the
  817. beginning of a program satisfy this requirement and are easier to locate.
  818. -
  819. :Second Pass.
  820.  
  821. The second pass of an assembler, which is the one in which the bulk of the
  822. work is to be done, can be undertaken once sufficient information is available
  823. to evaluate all the symbols that will be encountered in the process. Simplest
  824. of all is the case where the symbols were labels, and were defined on the first
  825. pass. The most difficult combination arises when blocks of reserved space are
  826. defined by formulas which involve other symbols, reaching its greatest degree
  827. of complexity when space allocated to some parts of the program depends on the
  828. amount allocated to other parts, and this somehow reacts to affect the original
  829. allocation.
  830.  
  831. The same sequence of actions arise in the second pass as in the first pass,
  832. but the response to each type of source line must be more detailed. Not only
  833. the length of each instruction is involved, but a determination of the data
  834. fields which it requires and their evaluaton.
  835.  
  836. The equivalences and labels should not have to be repeated in the second pass.
  837. To do so gives an error check, that the definitions are consistent between the
  838. two passes. Divergences generate a "phase" or "pass" error in some assemblers.
  839. Not ordering the sequence of definitions, or deliberately making them implicit
  840. rather than explicit, will surely allow the passes to differ sometimes.
  841. -
  842. The second pass has to evaluate symbolic expressions. They include
  843.  
  844.         component     defined by
  845.         ---------    ----------
  846.  
  847.         constant    decimal or hexadecimal number
  848.         constant    quoted ASCII string
  849.         constant    equivalence
  850.         label        program location
  851.         label        equivalence
  852.         formula        algebraic combination
  853.  
  854.  
  855.  
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.  
  863.  
  864. -
  865. :Intel HEX File.
  866.  
  867. There is hardly any assembler which produces a binary .COM file directly.
  868. A relocating assembler would be expected to defer the production of binary
  869. code until loading time, but assemblers which produce absolute code often
  870. produce a file with the extension .HEX, with the explanation that it contains
  871. an Intel HEX file. Historically, this is a file that was produced on paper
  872. tape, and which could be used for ordering PROMS, as well as for transferring
  873. assembled code from a cross assembler located on a mainframe computer to the
  874. microcomputer development system that one was presumably using.
  875.  
  876. There are good, although not overwhelming, technical reasons to work with the
  877. .HEX file. If a .COM file is generated at once, it must contain provision for
  878. multiple origins and the reservation of blocks of uninitialized code. If this
  879. causes gaps in the compiled code, they will have to be filled with zeroes, or
  880. spaced out somehow. If some care is not used, this can lead to the generation
  881. of a very large binary file holding a lot of space filler. When care is used,
  882. truly large reserved areas are placed at the end of the program, and can simply
  883. be ignored in the binary file.
  884.  
  885. Another convenience of a HEX file is that, as an ASCII file representing a
  886. binary file, it can be listed on a printer and checked over as needed.
  887. -
  888. In spite of all, it is a very strong presumption that the usage of HEX files is
  889. a relic of the days of paper tape, IBM 80 column punched cards, and primitive
  890. peripherals in general. Still, as a standard part of the assembly process, it
  891. behooves us to understand their layout.
  892.  
  893. A typical line of a HEX file has the following form:
  894.  
  895.     :NNAAAA00DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDCC
  896.  
  897. in which
  898.         :        signals the start of a data line
  899.         NN        is the number of bytes represented by the line
  900.         AAAA    is the initial address to store the line
  901.         00        has internal significance at the Intel Corp.
  902.         DD        is two ASCII hexadecimal nibbles per data byte
  903.         CC        is a checksum making the line sum to zero
  904.  
  905. The full line, from : to CC, including CC but excluding :, is to be made
  906. into a byte two nibbles at a time and summed modulo one byte; if the sum
  907. is zero the line is accepted as being without error. This protection is
  908. important when programming a high volume PROM run, less so in the disk
  909. storage now used to hold programs.
  910. -
  911. Information preceding the colon and following the stated number of bytes is
  912. ignored. This presumably permits errors in paper tape to be corrected with
  913. rubouts, pieces of tape to be spliced, leader and trailer to be placed on the
  914. tape, and similar housekeeping.
  915.  
  916. Usually a maximum of sixteen data bytes is placed on a single line, making
  917. NN equal to 10 (hexadecimal), but a greater or lesser number is possible.
  918. The latter accomodates a short line due to the presence of a "ds" statement
  919. or an "org" statement in the source code, or the simple fact that the program
  920. was not a multiple of sixteen bytes long.
  921.  
  922. Each line bears its initial address, AAAA.
  923.  
  924. The zero byte which follows the address seems to be a type code, the details
  925. of which are not available in the literature which we have seen. LOAD, the
  926. loader in DDT, and other programs seem to ignore it (except in the checksum).
  927.  
  928. The checksum arranges that a zero test on the sum of the bytes constructed
  929. since the preceding checksum indicates an acceptable transferrence of data.
  930.  
  931. If the bytecount field is zero, the end of the file is signalled, and the
  932. address as taken as the address to start execution (except CP/M uses 0100H).
  933. -
  934. :Listing of the Object Code.
  935.  
  936. For reference purposes, most assemblers offer the option of annotating the
  937. source listing with some indication of the object code which they have just
  938. generated. Usually, each line is extended by 20 columns or so, to make room
  939. for notations on the left hand side of the page. At the least, this notation
  940. will consist of the address at which each line of code is to be placed, plus
  941. the hexadecimal equivalent of the code that it generates.
  942.  
  943. To make error notations available for ready reference, the first column is
  944. often kept blank, except when the line is in error and a letter identifying
  945. the error is placed in the first column. Naturally assemblers differ greatly
  946. in the kinds of errors that they suspect and report.
  947.  
  948. Given the additional columns inserted in the annotated listing, precautions
  949. are needed to print it. The simplest solution is to make the source listing
  950. 20 columns less than the normal printer width; this works out well enough if
  951. 64 columns is allowed to pass 80 a bit.  All works well for a printer capable
  952. of 132 columns, even beginning with 80 columns. Such widths can be attained
  953. either by using compressed printing on letter size paper, or printing letter
  954. sized paper crossways. Of course, regular computer sized paper can substitute
  955. for letter sized paper if the printer has a wide enough carriage.
  956. -
  957. :Bibliography.
  958.  
  959.     Intel Corporation
  960.     8080/8085 Assembly Language Programming
  961.     Intel Corporation 1979
  962.     #9800940
  963.  
  964.     A. Osborne and G. Kane
  965.     Osborne 4- and 8-Bit Microprocessor Handbook
  966.     Osborne/McGraw-Hill 1981
  967.     ISBN CC 931988-42X
  968.  
  969.     Lance Leventhal
  970.     8080A-8085 Assembly Language Programming
  971.     Osborne/McGraw-Hill 1978
  972.     ISBN CC 931988-10-1
  973.  
  974. :[8080.HLP]
  975. [Harold V. McIntosh, 10 April 1984]
  976. [end]
  977.