4 ms·
> assume ah=0; assume bx=0 Hmm. So the second time this program is run, it will fail?
by stuartmalcolm 8y ago
> assume ah=0; assume bx=0
Hmm. So the second time this program is run, it will fail?
- chris_overseas 8y agoNo, AFAIK MS-DOS always initialises it to zero before starting the program. I'm trying to find a better reference, but I think this[0] effectively explains what state the registers are in on entry to your program. Edit: I take that back. According to [1]: .COM-format executables begin running with the following register values: AL = 00h if first FCB has valid drive letter, FFh if not AH = 00h if second FCB has valid drive letter, FFh if not [0] https://thestarman.pcministry.com/asm/debug/debug.htm#INIT https://thestarman.pcministry.com/asm/debug/debug.htm#INIT [1] http://www.delorie.com/djgpp/doc/rbinter/id/51/29.html http://www.delorie.com/djgpp/doc/rbinter/id/51/29.html
- boomlinde 8y agoThe value of BX is however strictly undefined, but practically always 0. Potentially some DOS will load this register with a different value, but probably no version of MS-DOS.
- freefal 8y agoBut why not explicitly set the register to 1 rather than assume its 0 and increment it by 1?
- boomlinde 8y agoSaves one byte, I assume. Register targets are typically encoded in the opcode while direct values follow the opcode byte.
- amenghra 8y agoOn x86, some instructions are longer than others. Incrementing is a single byte. Setting the value 1 if you don’t assume anything is going to be 2 bytes (al, ah, bl, etc.) or 4 bytes for (ax, bx, etc.) This online x86/x64 assembler is great: https://defuse.ca/online-x86-assembler.htm https://defuse.ca/online-x86-assembler.htm
- kevinmhickey 8y agoProbably because (IIRC) mov is 2 bytes and inc is only 1 byte and they're optimizing for minimum size.