Help and Support
 

powered byLive Search

Writing Faster Macro Assembler Programs

Article ID:31810
Last Review:November 19, 2003
Revision:2.1
This article was previously published under Q31810

SUMMARY

The Microsoft Macro Assembler is useful for writing fast programs. For example, the following is a fast method to take the absolute value 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 positive
notneg:         ; jump to here if positive
				

MORE INFORMATION

This method achieves part of its speed by avoiding the use of a jump instruction to keep the 8086's pre-fetch queue full.

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

This process forces the 8086 to spend time fetching the correct instruction from memory after the jump. Whenever possible, avoid jumps to increase the execution speed of Macro Assembler programs.

APPLIES TO
Microsoft Macro Assembler 4.0
Microsoft Macro Assembler 5.0
Microsoft Macro Assembler 5.1 Standard Edition
Microsoft Macro Assembler 6.0 Standard Edition

Back to the top

Keywords: 
KB31810

Article Translations

 

Other Support Options

  • Need More Help?
    Contact a Support professional by E-mail, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.