Writing Faster Macro Assembler Programs

This article was previously published under Q31810
This article has been archived. It is offered "as is" and will no longer be updated.
The Microsoft Macro Assembler is useful for writing fast programs.For example, the following is a fast method to take the absolutevalue of a number held in the AX register:
   cwd          ; replicate the high bit into DX   xor  ax, dx  ; take 1's complement if negative; no change if positive   sub  ax, dx  ; AX is 2's complement if it was negative The standard                : absolute value method works on any register but is much                ; slower:   or   bx, bx  ; see if number is negative   jge  notneg  ; if it is negative...   neg  bx      ; ...make it positivenotneg:         ; jump to here if positive				
More information
This method achieves part of its speed by avoiding the use of ajump instruction to keep the 8086's pre-fetch queue full.

To save time while a program is running, the 8086 tries to fetch thenext instruction from memory while it is processing the currentinstruction. However, a jump instruction moves the location of thenext instruction to fetch, making invalid the instruction that the8086 just fetched into its pre-fetch queue.

This process forces the 8086 to spend time fetching the correctinstruction from memory after the jump. Whenever possible, avoidjumps to increase the execution speed of Macro Assembler programs.
4.00 5.00 5.10 6.00

Article ID: 31810 - Last Review: 10/26/2013 11:04:00 - Revision: 3.0

  • Microsoft Macro Assembler 6.0 Standard Edition
  • kbnosurvey kbarchive KB31810