Hardware Reference
In-Depth Information
When the tracer window appears, type the command
/vecmul+7b
followed by a return to put a breakpoint at the line containing the LODS . From now
on, we will not mention that all commands must be followed by the return key.
Then give the command
g
to have the tracer execute commands until the breakpoint is encountered.
It will
stop at the line containing the LODS .
On line 29, the value of AX is multiplied to the source operand. The memory
word for the MUL instruction is fetched from the data segment through the DI in
register indirect mode. The implied destination of MUL is the DX : AX long register
combination which is not mentioned in the instruction but which is implied by it.
On line 30, the result is added to the local variable at the stack address 2(BP) .
Because MUL does not autoincrement its operand, that must be done explicitly on
line 31. Afterward, DI points to the next entry of vec2 .
The LOOP instruction finishes this step. Register CX is decremented, and, if it
is still positive, the program jumps back to the local label 1 on line 28. The use of
the local label 1b means the closest label 1 looking backward from the current
location. After the loop, the subroutine pops the return value into AX (line 33),
restores BP (line 34), and returns to the calling program (line 35).
Then the main program is resumed after the call with the MOV instruction on
line 12. This instruction is the start of a five-instruction sequence whose goal is to
print the result. The printf system call is modeled after the printf function in the
standard C programming library. Three arguments are pushed onto the stack on
lines 13-15. These arguments are the integer value to be printed, the address of the
format string ( pfmt ), and the function code for printf (127). Note that the format
string pfmt contains a % d to indicate that an integer variable can be found as argu-
ment to the printf call to complete the output.
Line 17 cleans up the stack. Since the program started on line 5 by saving the
stack pointer in the base pointer, we could also use the instruction
MOV SP,BP
for a stack cleanup. The advantage of this solution is that the programmer does not
need to keep the stack balanced in the process. For the main program this is not a
big issue, but in subroutines this approach is an easy way to throw away garbage
such as obsolete local variables.
The subroutine vecmul can be included in other programs. If the source file
vecprod.s is put on the command line behind another assembler source file, the
subroutine is available for multiplying two vectors of a fixed length. It is advisable
to remove the constant definitions EXIT and PRINTF first, in order to avoid their
being defined twice. If the header file syscalnr.h is included somewhere, then there
is no need to define the system call constants anywhere else.
Search WWH ::




Custom Search