Quote:
|
Originally Posted by akioshin
mov bx, offset ar1
mov ah, [bx+si]
mov al, [bx+di]
cmp ah, al ; if (ar1[i] <= ar1[j]) then no swap
jle @@no_swap
|
You might want to consider using actual
int variables. With most 16-bit DOS compilers, an
int is 16 bits, so you can use the word-sized regs, rather than the byte ones. I realize you're looking to sort single-digit numbers, but more functionality is always good.
Another thing to consider is what registers are safe to clobber, if you're mixing assembly with another language, such as C. When the compiler generates code, it uses certain registers. Some are safe to modify between statements, and some are not. For many old DOS compilers, you can modify AX, BX, CX, and DX, as well as SI and DI (the latter two are only safe if the compiler isn't using register variables). BP is pretty much never safe to use; higher-level languages use it to maintain the stack frame. Of the segment registers, you should never modify SS, unless you're writing stack-switching code (a bit beyond your current skills, I expect). DS is okay to muck with, but put it back when you're done. ES may be okay, depending on the compiler, and the 386+ FS and GS registers are usually fine to use (older compilers are often oblivious to their existence). All of this is based on my experience with old 16-bit DOS compilers, and your compiler might differ. In particular, 32-bit compilers such as DJGPP have different clobber registers. If you're unsure, the safest thing is to push the regs at the start of your routine, and pop 'em off after.