Download ibm pc assembly language - Ron Burkey`s Project Page

Transcript
IBM-PC ASSEMBLY-LANGUAGE LECTURE NOTES
PAGE 214/361
Pascal algorithm required 14 lines of code (one of which was simply a
label), while the "supporting" assembly code defining the procedure and
setting up the BP register and the variables, etc. was 17 lines (not
including comments or an INCLUDE statement). This is not what we would
ordinarily think of as being a very desirable situation (except that
it's better than 45 lines of algorithm and 17 lines of supporting
code).
Fortunately, there is nothing to keep us from inventing algorithms
to do away with the complex supporting code. To see how this might be
done, let's start with the code that we have to use to terminate our
assembler routine. This code looks something like this:
POP
ADD
RET
name ENDP
CODE ENDS
END
BP
SP,2*NUMBER_OF_LOCAL_VARIABLES
2*NUMBER_OF_ARGUMENTS
If we introduce a macro like
RETURN MACRO
POP
ADD
RET
NAME ENDP
CODE ENDS
END
ENDM
NAME,NUMVARS,NUMARGS
BP
SP,2*NUMVARS
2*NUMARGS
then we can simply terminate our separately assembled routine with the
line
RETURN
PROCNAME,NUMVARS,NUMARGS
assuming that this was the only procedure in the file.
Similar comments apply if we try to invent a macro to begin our
program and a macro to define our variables. Such macros are slightly
tricky to write (and there's no particular reason to discuss them in
detail), so let's just assume from now on that there is a macro
BEGIN
PROCNAME,NUMVARS
which can be used at the beginning of the procedure to eliminate the
PUBLIC, SEGMENT, ASSUME, and PROC statements, as well as the
initialization of BP and SP. The definition of such a macro is posted
on my office door. Similarly, let's suppose that there is a macro
VAR
VARNAME[,TYPE]
which defines a local variable or a procedure argument, and replaces
the EQU statement we have been using so far. In this case, the TYPE
argument is either BYTE or WORD (with the default being WORD). Such a
macro must clearly maintain an internal counter so that successive uses
of the macro will define variables at successive locations on the
CLASS 12