-1

first of all hello to all hope you are good and safe.

well i have some questions about machine code and hardware and operating system.

1- i was search about how is pure machine code and i find somethings in here and net but not enough to answer my questions since im new to low level programming language. so how to write a pure machine code like open just my computer with 0,1 are machine code have any file extensions like assembly and .exe i wana write code just directly get area in ram and talk with processor and do what i writed for example open my computer or open a text file for example. so i wana know how to do it are pure machine code have a file extension like .exe or .asm

2- i know each cpu have it owen machine language somethigns is different on them it could not be a way to all cpu's undrestand our machine code. also i wana know for example we have 2 cpu both of them are x64 or x32 but 1 of them are windows other is linux are machine code of x64 windows will work also on x64 cpu linux?

thank you for give your time to me and read.

for now gathering information

Mam
  • 1
  • 1

1 Answers1

1

An operating system provides the capability to run programs.  So, one program, like the desktop or command line shell, can ask the operating system to run another program.

When that happens, the operating system creates an environment to run the program called a process, and then loads a program file from disc into the process, and directs the CPU to begin executing that program file starting at its beginning.

The operating system has a loader, whose job is to load the disc-based program file into memory of the process.

The loader knows about certain executable file formats.  Different operating system have different loaders and most likely understand different executable formats.

Machine code is contained in these program files, stored on disc using those file formats.  There are other ways to load machine code into memory, though a program file stored on disc loaded by the loader is the most common approach.

Asm, .asm, is a text file, human readable, for storing program code in assembly language.  To use it, such text file is given as input to a build system, which converts that human readable program code into a program file containing equivalent machine code, for later loading into a process by the operating system.

Not only do different operating systems support different file formats for program files, they also support different ways to interact with the operating system, which goes to their programming model that is described by an Application Binary Interface aka ABI.  All programs need to interact with the operating system for basic services like input, output, mouse, keyboard, etc..  Because ABIs differ between operating systems, the machine code in a program written for one operating system won't necessarily run on a different operating system, even if the processor is exactly the same.

Most disc-based file formats for executable program files contain indicators telling what processor the program will run on, so the same operating system on different processors requires different machine code, and hence usually different executable program files.  (Some file formats support "fat" binaries meaning that the machine code for several different processors is in one program file.)

Operating systems also have features that allow execution of new machine code within an existing process.  That machine code can be generated on the fly as with JTT compilers, or loaded more informally by an application program rather than the operating system loader.  Further, most operating system loaders support dynamically loading additional program file content from executable program files.

So, there's lots of ways to get machine code into the memory of a process for execution — support for machine code is one of the fundamental features of operating systems.

Let's also note that no real program is pure machine code — programs use machine code & data together, so all executable file formats store both machine code and data (and metadata).

Erik Eidt
  • 23,049
  • 2
  • 29
  • 53
  • thank you my friend first of all for this useful informations i I understood many things from your comment. so lets now talk about that ways to get machine code into memory of process im really interest for machine language and further hardware programing i really wana get into this field but gathering informations for just now i worked with high level languages looked into assembly but i dont know it for now. so lets talk about get machine code into memory of process manuely or idk we have other ways i wana now now for example write a program with machine code that open 1 folder for example. – Mam Dec 12 '22 at 06:29
  • or show hello world or some basic stuffs i wana know how to do it just show me some little light then i will bring the sun for you – Mam Dec 12 '22 at 06:32
  • im waiting for your respond friend – Mam Dec 13 '22 at 11:58
  • Have you studied the links I provided? Which ones were of most interest to you? – Erik Eidt Dec 13 '22 at 13:44
  • well brother most interested is executable file formats link and ABI. i looked into many things about how cpu execute programs and some more things i read about ELF and PE files and some more but you know im new to this field i need more guide i still dont find a resource for how to write some basic stuff in machine code i need just guide for learn write in machine code for defined processor and execute directly i need more guide about this – Mam Dec 14 '22 at 08:53
  • We don't generally write directly in machine code, but in some programming language. Assembly language is very close to machine code, except it is human readable, and needs to be processed by an assembler to turn into a machine code binary. Are you interested in assembly language? If so, I would suggest trying one of the educationally-oriented processors like [LC-3](https://en.wikipedia.org/wiki/Little_Computer_3), and an easy to use [simulator](https://wchargin.com/lc3web/). – Erik Eidt Dec 14 '22 at 11:36
  • That simulator will translate assembly to machine code, and let you single step to execute the machine code program. You can search here and around the web for example program to try, and documentation resources about the processor and its [instruction set.](https://en.wikipedia.org/wiki/Instruction_set_architecture). – Erik Eidt Dec 14 '22 at 11:37