开发者

16 bit asm instruction set

What set of instructions is used in COM files? I assumed it was 8086, but it开发者_运维知识库 seems that I was wrong. In a 8086 manual I found, shl can only accept 1 or cl for its second argument, while immediate values other than 1 work fine for me. In case it matters, I'm using NASM.

Thanks for your time.


This is one of those funny questions and as always the answers are misleading.

a true DOS COM file has no headers and has to fit inside a single segment of memory, because it had no relocation information, DOS had to put the file where it needed, and so the only true way of being compatible (with x86) was to use 8086 compatible assembly. Edit: To clarify the above, this is because the 8086 didn't have memory pages.

You could certainly compile in 286/386 operands in, as once the program is running, there's no executive runtime in DOS to stop you and say 'no you can't do that, it's a 386 instruction'.

Which, funnily enough, is part of the reason why COM files don't work very often in Windows7 x32 or at all in Windows7 x64.

Because of way DOS worked, command.com was unloaded when you execute your .com file, and reloaded afterwards, so essentially your .com file could access all memory of the system, and in theory use DOS memory extenders like Phar lap's DOS/4GW and CWSDPMI come to mind.

Long story short; you could use any sort of commands that the current system could support, but you should only use 16-bit x86 compatible commands to be sure.

If the above sounds like a PITA, it's because it was, I remember :) It's also why the .EXE format got very popular very quickly.


A true COM (I won't get into COMs that are actually EXEs, etc) just means it's a simple DOS executable. Whatever instruction set is supported is available. I used to do DOS programming (both COM and EXE) on 8088 up through i486 back in the day, and whatever instructions are legal in that mode, you can use. For example, I often used 32-bit string instructions and immediate pushes when my target was "16-bit" (technically should be called "real mode") DOS.


There are two main types of COM files. One was designed to run in MS-DOS, the other was designed to run in the CP/M OS. As far as I know, the DOS COM files should be x86 based. CP/M COM files could potentially be 8085, 8080, or Z80 instructions according to Wikipedia. As another answer mentioned, COM is just a simple executable format, and can use any supported underlying instruction set.

In terms of the SHL instruction, it seems that modern x86 hardware (perhaps x64) supports using an immediate value for this instruction. I couldn't find reference to it when looking just at 8086 docs, though, so it must have been added at some point. Here's a couple of references which go into some detail on this instruction:

http://siyobik.info/main/reference/instruction/SAL%2FSAR%2FSHL%2FSHR

http://ref.x86asm.net/coder32.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜