non os-specific assembly

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
CoolnessItself

non os-specific assembly

Post by CoolnessItself »

I know theres DOSSEG for DOS and SECTION for linux and all that stuff, but how do you make code that can be run in any OS?
pskyboy

Re:non os-specific assembly

Post by pskyboy »

Correct me if im wrong, but i would guess what you wish to acheive would only be possible if you don't call any operatying specific calls. So you would have to directly access the hardware (which would mean you would have to write your program for a specific platform) or you will have to use interupts only.

Peter
CoolnessItself

Re:non os-specific assembly

Post by CoolnessItself »

Im wondering what the format of the asm file to make would be. (Correct me if im wrong:) I cant have dosseg at the top, that need dos. I cant have SECTION, that requires linux

So what do I use?
Tim

Re:non os-specific assembly

Post by Tim »

What assembler are you using? No assembler I know of inserts OS-specific code into its output, although all assemblers will write to a specific object format if asked.
frank

Re:non os-specific assembly

Post by frank »

assembly is always os-specific,
in linux you can only use syscalls (ok, libs too :))
in dos you can directly access the hardware (ugh!, what's the use of an os then ? ;)) and use syscalls.
The syscalls differ on both systems, dos uses int 21h, linux uses 80h.
That's why C is "invented", on both systems it makes different binaries.

Code: Select all

 int main()
 {
  exit(0); // syscall
 }
will make 2 different binary files on both systems.
(check using ndisasm)
Tim

Re:non os-specific assembly

Post by Tim »

No, assembly is always processor-specific. Example: the INT instruction is available on the x86 regardless of whether you're programming for DOS, Windows or Linux. What happens when you execute the INT instruction depends on what OS you run your code under, but the instruction set (and hence the assembler) is the same under each OS.

Conversely, if you changer processor but keep the OS the same, the assembly code you write will be completely different. A Linux program written in ARM assembly looks completely different to the same program written using x86 assembly.
Post Reply