3 Laws of Modular Design for Assembler program

These laws are summarized below. They aren't really laws, they're
suggestions. But we'll u e them throughout thi book. Define your own laws if
you like, but either way, stick to the ame one all the time. Your job will be
much easier if you're consistent.

3 Laws of Modular Design

  1. Save and restore all register , unless the procedure returns a value in
    that register.
  2. Be consistent about which register you use to pass information. For ex-

    • DL DX-Send byte and word value .
    • AL, AX-Return byte and word value
    • BX:AX-Return double-word values.
    • DS:DX-Send and return addre es.
    • CX-Repeat count and other count .
    • CF-Set when there is an error; an error code should be returned in
      one of the registers, such as AL or AX.
  3. Define all external interactions in the comment header:
    • Information needed on entry.
    • Information returned (registers changed).
    • Procedures called.
    • Variables used (read, written, and so on).
      There's an obvious parallel between modular design in programming and
      modular design in engineering. An electrical engineer, for example, can build
      a very complicated piece of equipment from boxes that perform different func-
      tions, without knowing how each box works. But if each box uses different
      voltages and different connections, the lack of consistency creates a major
      headache for the poor engineer, who must somehow provide a different volt-
      age for each box and create special connections between boxes. Not much fun,
      but fortunately for the engineer, there are standards providing for only a
      small number of standard voltages. So, perhaps only four different voltages
      need to be provided, instead of a different voltage for each box.
      Modular design and standard interfaces are just as important in assembly-
      language programs, and that's why we'll lay down the laws (so to speak), and
      use those laws from here on. As you'll see by the end of this book, these rules.
      will make our task much simpler.