Reputation: 1021
1) I would like to know if we could write a C program to know about the instruction set architecture of the machine.
2) How does the operating system figure out what Instruction Set Architecture(ISA) the computer runs on during installation? If the OS was to support two different ISA, does the installation file contains assembly code for both the architectures??
Upvotes: 4
Views: 10359
Reputation: 19158
1) I would like to know if we could write a C program to know about the instruction set architecture of the machine.
A C program needs some compiler to compile which will convert the code into machine language which is different for different architectures like Sparc, x86, ARM
,etc. So,you won't be able to run C program if you don't know about the instruction-set of the architecture. C binaries are different for different architectures.
But, one thing you can do if you're sure about the system architecture and if you're using a compiler on that system. You can try executing these instructions on different operating systems to get details about different architectures.
You can get system architecture details(not the instruction set details) of that machine by using
set
on Windows command prompt(cmd)
cat /proc/cpuinfo
on unix/linux terminal
Now write a C program to execute this command in cmd/terminal depending on the OS of system.
2) How does the operating system figure out what Instruction Set Architecture(ISA) the computer runs on during installation? If the OS was to support two different ISA, does the installation file contains assembly code for both the architectures??
The OS itself consists of pre-compiled binaries which are run on specific architectures. Almost initialising files of OS are all direct executables. If the architecture's instruction set is not compatible for the binaries of Operating system, then an installation error will be reported! The architecture's primary job is to just run those binaries,and do nothing else.
If the OS was to support two different ISA, then also the architecture on which it is getting installed has to just run those binaries as per instructed in the OS code.
An analogy approach is tried below. I am just a learner, so I don't have much assembly/machine level coding experience. I have attempted this question only with my knowledge of Computer Architecture And 8086-programming.
Ex :-
MOV AX,[76h] // lets' say opcode is 1001010 10011001, but it is probably wrong
Here, this is for x86-systems/architecture! It won't fit for Sparc processors as it has different instruction-set and hence, your OS will not install on Sparc processors.
I hope this much is clear. If you still have queries, please leave a comment below!
Upvotes: 5