Page 30 - DCAP210_INTRODUCTION__TO_MICROPROCESSORS
P. 30

Introduction to Microprocessors


                  Notes                         END does not stop the program during execution. In fact, .END does not even
                                                exist at the time of execution. It is simply a delimiter; it marks the end of the
                                                source program.
                                 2.1.4 Comments

                                 Comments are messages intended only for human consumption. They have no effect on the
                                 translation process and indeed are not acted on by the LC-3b Assembler. They are identified in
                                 the program by semicolons. A semicolon signifies that the rest of the line is a comment and is to
                                 be ignored by the assembler. If the semicolon is the first non-blank character on the line, the
                                 entire line is ignored. If the semicolon follows the operands of an instruction, then only the
                                 comment is ignored by the assembler.
                                 The purpose of comments is to make the program more comprehensible to the human reader.
                                 They help explain a nonintuitive aspect of an instruction or a set of instructions. In line 0A, the
                                 comment “Clear R3; it will contain the product” lets the reader know that the instruction on line
                                 0A is initializing R3 prior to accumulating the product of the two numbers. While the purpose of
                                 line 0A may be obvious to the programmer today, it may not be the case two years from now,
                                 after the programmer has written an additional 30,000 lines of code and cannot remember why
                                 he/she wrote AND R, R3, 0. It may also be the case that two years from now, the programmer no
                                 longer works for the company and the company needs to modify the program in response to a
                                 product update. If the task is assigned to someone who has never seen the code before, comments
                                 go a long way to helping comprehension.
                                 It is important to make comments that provide additional insight and not just restate the obvious.
                                 There are two reasons for this. First, comments that restate the obvious are a waste of everyone’s
                                 time. Second, they tend to obscure the comments that say something important because they add
                                 clutter to the program. For example, in line 0F, the comment “Decrement R1” would be a bad
                                 idea. It would provide no additional insight to the instruction, and it would add clutter to the
                                 page.
                                 Another purpose of comments, and also the judicious use of extra blank spaces to a line, is to
                                 make the visual presentation of a program easier to understand. So, for example, comments are
                                 used to separate pieces of the program from each other to make the program more readable. That
                                 is, lines of code that work together to compute a single result are placed on successive lines, while
                                 pieces of a program that produce separate results are separated from each other. For example,
                                 note that lines 0E through 10 are separated from the rest of the code by lines 0D and 11. There is
                                 nothing on lines 0D and 11 other than the semicolons. Extra spaces that are ignored by the assembler
                                 provide an opportunity to align elements of a program for easier readability. For example, all the
                                 opcodes start in the same column on the page.




                                          Prepare a program and use some of the instructions.


                                 2.1.5 Pseudo-ops (Assembler Directives)
                                 The LC-3b assembler is a program that takes as input a string of characters representing a computer
                                 program written in LC-3b assembly language, and translates it into a program in the ISA of the
                                 LC-3b. Pseudo-ops are helpful to the assembler in performing that task. Actually, a more formal
                                 name for a pseudo-op is assembler directive. They are called pseudo-ops because they do not refer
                                 to operations that will be performed by the program during execution. Rather, the pseudo-op is
                                 strictly a message to the assembler to help the assembler in the assembly process. Once the assembler
                                 handles the message, the pseudo-op is discarded. The LC-3b assembler contains five pseudo-ops:



        24                               LOVELY PROFESSIONAL UNIVERSITY
   25   26   27   28   29   30   31   32   33   34   35