Originally Posted by
lruc
Is machine code more or less portable than asm? I would imagine asm is more portable among operating systems but machine code is more portable among hardware.
Assembler and machine code have a 1:1 relationship. One instruction [as long as we stay with one processor architecture, e.g. X86] will produce one set of instruction bytes. There are some instructions that have synonyms (that is, there are more than one way to form a valid instruction that does this thing), but the output from the assembler will have the exact same meaning for either of those synonyms - it may be a byte or two longer, but other than that, it's the same result.
Sure, NASM, MASM and CPP + GAS have slightly differnet syntax for Macros and other pseudo-operations [pseudo-ops are things that aren't actual machine-code instructions, but rather instructions to the assembler as to what you want done, where you want it [e.g. .data, .code are instrucitons to the assembler that "what comes next should go in the data section or the code section].
Also, if you use gas on windows, the code will work on Windows, and as long as you don't call the OS, you can assemble the same thing in Linux and get the same result.
There is absolutely no meaning in remembering that 8B is MOV, 75 is JNZ, 90 is NOP, EA is a JMP, CC is INT3, etc. [But if you want to check those out, I think I got most of them about right]. That is of course x86. On 68000 the instructions have somewhat differnet names, and completely different opcodes.
The following code should assemble, and make an executable file that works, for both Linux and Windows:
Code:
.text
.globl _main
_main:
mov $hello, %eax
push %eax
call _puts
add $4, %esp
xor %eax, %eax
ret
.data
hello: .string "Hello, World!\n"
.end
Code:
as -o asm.o asm.s
gcc -o asm.exe asm.o
--
Mats