Assembly programming : NASM VS MASM code
Solution 1
MASM is not just 16 bit. You can also get 32 bit assember MASM:
DOS assembly and Linux Assembly are completely different. There is no automated way to port. You will have to write separate code for each since assembly is most close to the metal.
Solution 2
NASM can handle x86 from 8bit to 64 bit, don't worry about it. NASM is a good all around assembler.
They both use Intel style assembly code, which is nicer in my opinion than AT&T style assembly code, you should do fine.
They are assemblers, as long as you understand the interrupts you call, they will accept your code, turn it into binary, and send it off merrily to be executed.
Oh yeah, to generate a dos executable place ORG 100h above the entry point you want, and that's why dos was good for assembly programmers.
Edit: This was only one of the reasons, the others were that dos was heavily interrupt based, so knowing where the arguments go and what they are allowed for relatively easy system calls.
PE format is what you want to look for, I think there's a bit more manual footwork to do in NASM to make it work properly on windows...
Comments
-
Md. Al-Amin over 1 year
I am just started learning Assembly programming. So far I know, NASM is the best assembler for linux. And its 32-bit assembler.
On the other hand, MASM is a DOS assembler and its 16 bit.
Now I want to know how to port from 16-bit x86 DOS assembly code to 32-bit x86 Linux assembly code or 32-bit x86 Windows assembly code
Thanks in Advance.
-
Jongware over 10 yearsNASM is not "32-bit": Chapter 8: Writing 16-bit Code (DOS, Windows 3/3.1). Also, MASM is not "16-bit": "Beginning with MASM 8.0 there are two versions of the assembler - one for 16-bit and 32-bit assembly sources" wikipedia
-
nrz over 10 yearsYour question is unclear. Whether the code is 16-bit/32-bit/64-bit is only one thing affecting the porting, the other is the OS. Do you mean how to port from 16-bit x86 DOS assembly code to 32-bit x86 Linux assembly code or 32-bit x86 Windows assembly code or something else? Please specify.
-
Md. Al-Amin over 10 yearsYes, I want to know ow to port from 16-bit x86 DOS assembly code to 32-bit x86 Linux assembly code or 32-bit x86 Windows assembly code.
-
Peter Cordes over 6 years
-
-
Peter Cordes about 8 years"since the system call APIs are completely different" would be a more specific way to state that last point. If it was just different ABIs for the same API, the porting effort might be much smaller, and maybe some of it could be automated. Being close to the metal means that it's more work to port to a different API/ABI, of course, but a C program would need a major rewrite for Linux vs. DOS.
-
Peter Cordes about 8 yearsLinux 32bit syscalls can be made with
int 0x80
. (But calling into the userspace side of thesysenter
code in thevdso
is faster). All registers are preserved, except eax (return value). The ABI is just as "interrupt based" as DOS, if that's what you mean. 64bit is also similar: usesyscall
, which preserves all registers exceptrcx
andr11
, and the return value. Windows code OTOH should not use kernel system calls directly, but rather use the win32 API through function calls into DLLs. So yes, you're stuck with the function call ABI. -
Pacerier almost 7 years@Madhur, Do you recommend MASM or NASM?