About me
Home
Resumé
CV
Pictures

Course Work
CSE300-FA98

Teaching
Portfolio
CSE240-SP99
CSE207-FA03

Misc
eHarmony
Documents

Tools

Optimizations

Okay, so you've got the hang of coding in assembly. Let's try to make your code more efficient


if you want to print the string (which is what it looks like you are trying to do)

   mov    ah, 09h
   lea    bx, FirstNum
   add    bx, 2
   mov    dx, bx
   int    21h

but this could be shortened to

   mov    ah, 09h
   mov    dx, OFFSET FirstNum + 2  ;all done by preprocessor
   int    21h

Analysis: 24 cycles, 10 bytes verses 18 cycles, 6 bytes


Any time you need to pass over a structure (like converting a string to a list of numbers)

   mov    bx, 0
 loop_top:
   inc    bx
   sub    [bx], '0'
   cmp    bx, 10
   je     done
   jmp    loop_top

but this can be shortened slightly by reversing directions - it makes no difference from the standpoint of the final result, but this is faster and smaller

   mov    bx, 10
 loop_top:
   sub    [bx], '0'
   dec    bx
   jz     done
   jmp    loop_top

Analysis: 414 cycles, 12 bytes verses 374 cycles, 10 bytes

Last Modified: January 26, 1999 - Barry E. Mapen