CS222 Lecture: Introduction to the VAX Assembler and Debugger   revised 1/12/96

Materials: Sample MACRO program handout - source, list, map
           Source of above to reassemble with debugger (in COURSES.CS222.DEMOS)

I. The MACRO Assembler
-  --- ----- ---------

   A. By now, our experience with coding in machine language has made us
      painfully aware of two difficulties:

      1. The need to constantly look up (or memorize) numeric codes for
         operations and addressing modes.

      2. The need to know the addresses of data and branch targets as we
         write code - compounded by the problem of having to insert or
         remove code later.

   B. To address these problems, very early in the computer era (1950's),
      ASSEMBLERs were introduces as software tools to assist in writing
      programs.  All assemblers do at least two things:

      1. Translate SYMBOLIC op-codes into numerical equivalents.

      2. Allow the use of symbolic LABELS for data and branch targets, which
         the assembler translates into actual addresses.  Along with this,
         the assembler includes PSEUDO-OPS that allow the programmer to call
         for memory to be set aside to hold various data items.

      3. Many assemblers (including VAX MACRO) do much more.

   C. An example of a complete MACRO program

        HANDOUT: MACRO_DEMO.MAR (go over)

   D. MACRO programs go through an Edit/Assemble/Link cycle similar to the
      Edit/Compile/Link cycle used with Pascal:

      1. Assembly: Commands:

         MACRO filename
         MACRO/LIST filename
         MACRO/DEBUG filename
         MACRO/LIST/DEBUG filename

         - Source file should have .MAR filetype
         - Results in a .OBJ file
         - List option produces a .LIS file as well

         To assemble our demo and produce a listing, we would use

         MACRO/LIST MACRO_DEMO

         HANDOUT: listing of MACRO_DEMO

      2. Linking: Commands

         LINK filename [ otherfiles ]
         LINK/MAP filename [ otherfiles ]
         LINK/DEBUG filename [ otherfiles ]
         LINK/MAP/DEBUG filename [ otherfiles ]

         HANDOUT: map for MACRO_DEMO

         - Results in a .EXE file
         - Map option produces a .MAP file as well
         - This program depends upon a library of simple IO routines, since 
           writing code to do IO is very complex.  We need to include this 
           library in our link command as an additonal file.

         To link our demo and produce a map, we would use

         LINK/MAP MACRO_DEMO, CS222:SIMPLEIO

         HANDOUT: map for MACRO_DEMO

      3. The program is run with the RUN command as always

         DEMO: RUN MACRO_DEMO

      4. Alternately, we can use EXECUTE

         EXECUTE filename otherfiles

         - /LIST can be optionally placed after filename
         - /DEBUG can be optionally placed after filename (affects both
           assemble and debug)
         - /MAP can be optionally placed after otherfiles, or (if there
           are none) alone after a space separating it from filename

        DEMO: EXECUTE MACRO_DEMO.MAR, CS222:SIMPLEIO

II. Using the VAX debugger with MACRO

   A. The VAX debugger can be used with programs written in MACRO to
      examine and modify individual memory locations containing code or
      data; to examine and modify registers; and to execute a program one
      instruction at a time.

   B. For lab 1, we will use an empty workspace linked to a copy of
      the debugger, which will allow us to type programs in machine
      language directly into memory.

      DEMO: The following machine language program adds the value 11 to
            memory location 1000.  It includes an entry mask and a return
            instruction to allow it to be called as a procedure.

                       00 00 ; Mask
                
        00001000 9F 11 8F D0 ; MOVL #11, @#1000

                          04 ; RET

        $ RUN CS222:DEBUGGER

        SET TYPE LONG
        DEPOSIT 200 = 0
        DEPOSIT 202 = 9F118F80
        DEPOSIT 206 = 1000
        DEPOSIT 20A = 04

        EXAMINE 1000
        CALL 200
        EXAMINE 1000

   C. More typically, we link the debugger with an assembly language program
      and use it to monitor program execution.

      DEMO: EXEC MACRO_DEMO.MAR/DEBUG CS222:SIMPLEIO

            SET MODE SCREEN
            Step through
            - Use EXAMINE/R0 to show R0 before and after call to RNUM
            - Use EXAMINE/ASCII:10 to show BUFFER before and after call to RLINE

            HELP

Copyright ©1999 - Russell C. Bjork