   Programming in machine code
  Just curious. Is there any difference between programming in machine code and in native assembly? Or is assembly effectively just machine code with keywords? Is there anything that can be done in the former but not in the latter (even if it would only be destructive or nonsensical, like for example trying to call an instruction that doesn't exist)? Could there theoretically be anything to gain (in speed?) from coding in binary rather than assembly, if coded ideally?[Edit] A somewhat clearer question: can you literally do anything with assembly? Can you with assembly produce 2^32 different "programs" for a 32 bit long file?[edited by - eighty on July 30, 2003 10:31:30 PM]
  Usually you can''t even code in machine code period. The processor usually reads assembly language straight from memory.If you were on some weird platform, say, programming for cellphones or some weird console or something, there is a SLIGHT chance that you might be able to.Machine code is usually just an intermediate step for the processor. Or maybe between the processor and motherboard... ;quote:Original post by eighty  Or is assembly effectively just machine code with keywords? Yep.quote:Could there theoretically be anything to gain (in speed?) from coding in binary rather than assembly, if coded ideally?Nope. all that would happen is you''d make yourself more confusedquote:A somewhat clearer question: can you literally do anything with assembly? Can you with assembly produce 2^32 different "programs" for a 32 bit long file?Yep... basically anything that your machine can do can be done in assembly ;Assembly language is simply a textual way of representing machine language in a somewhat readable form.  It uses mnemonics such as ''mov'' or ''push'' to represent opcodes in machine language.  Opcodes are the processors instructions.However, assembly language does a few other things like allowing you to define labels.  This lets you write a program without calculation offsets or locations in code.  It also gives you macros  similar to c macros.You could create a 32-bit long program, however the range in instruction size varies a lot.  The instruction set doesn''t have 2^32 different instructions, more like around 150 or so.  However each of these have parameters that affect their encoding.  So mov eax, edx is the same basic instruction as mov ecx, edx, but has a different encoding.Assembly language is essentially useless these days if you''re not a system level programmer.  Its not cross platform, it can be slower than the compiler generated code, etc, etc.>"Is there anything that can be done in the former but not in the latter "Sometimes when new instructions like mmx are introduced but the assemblers aren''t updated yet, programmers resort to coding with machine code bytes representing those instructions.  Some c compilers allow you to emit machine code bytes using _emit.;  I took a computer architecture class where we wrote in machine code.  First we wrote it in ASM on paper, then translated it to machine code to enter it into the computer.  We had a table of all ASM commands, and there hex counterpart that the computer understood (it was a 1 MHz Motorola CPU stuck on a little panel thing with a breadboard and a hex keyboard (0-9, A-F).Assembly and machine code have a one-to-one exchange.  One asm command per machine code instruction.  You just have to convert everything to hex (including parameters). ;  I have typed in machine code once, TI calculators (i believe TI-83+ and above have an "assembler" but all it does is convert your hex code to real machine code.  So you tediously sit with pen and paper converting the commands by hand, and then typing them in.  One error, your calculator resets, you lose the program. ;  if you specifiy the assembler neumonics completely and correctly, then they will directly transform into machine code.for the x86 architecture (pentium pro and above [perhaps even before?]) these machine code instructions will get split into "micro-ops" and get executed differently anyway, as far as i know, you cant get down to that level anyway, so there is no point in writing anything in machine code, other than it might make you feel a little more elite. (read: go for it.)i imagine that it would come in handy if you want to write self modifiying code and stuff like that.. ;quote:Original post by MaulingMonkeyUsually you can't even code in machine code period. The processor usually reads assembly language straight from memory.If you were on some weird platform, say, programming for cellphones or some weird console or something, there is a SLIGHT chance that you might be able to.Machine code is usually just an intermediate step for the processor. Or maybe between the processor and motherboard...   GDI, you can code any friggin’ processor in machine code (kids, I tell ya’).  Ironically machine code is an intermediate step for the processor, which takes the op codes (assembly instructions) executes sequences of so-called micro-code that actually make things happen (enable gates, toggle flip-flops, jam bits on a bus).The processor does not read assembly language straight from memory - assembly is a language and it must be compiled before it can run.  If you directly machine code, it's executable as-is.  In machine code, moving a word is a different instruction from moving a dword - an assembler can infer out how much data there is, so they use the same mnemonic (mov):Assembly    Machine Code x86 (hex)x86 (bin)mov eax, 1 B8010000 10111000 00000001 00000000 00000000 00000000mov ax, 1  66B80100 01100110 10111000 00000001 00000000mov al, 1  B00110110000 00000001    [edited by - Magmai Kai Holmlor on July 31, 2003 2:31:03 AM];quote:Original post by eighty   [Edit] A somewhat clearer question: can you literally do anything with assembly? Can you with assembly produce 2^32 different "programs" for a 32 bit long file?Yes but no.  You can make 2^32 different bit sequences and call it code, but only some of the combinations would actually do something other than crash.Also, files have headers in them before the code starts - Windows uses a format called 'PE' or portable executable.   [edited by - Magmai Kai Holmlor on July 31, 2003 2:34:12 AM];quote:Original post by Magmai Kai Holmlor  Assembly    Machine Code x86 (hex)x86 (bin)mov eax, 1 B8010000 10111000 00000001 00000000 00000000 00000000mov ax, 1  66B80100 01100110 10111000 00000001 00000000mov al, 1  B00110110000 00000001    My bad, when I think of "Assembly", I usually think of ''plain'' (aka not MASM or anything like that)... and well, to me, the bytecodes are just as much ''assembly'' as is the written version (that''s per our convinience) as they corelate directly...And then when I think of "Machine Code" I usually think of things such as those processors which convert the assembly bytecodes into a different internal representation before actually executing them... which would be the layer you can''t program on in the first place.