I am amazed at how computers work and have a few questions about Assembly and other low level languages.

What is C converted to?
Well, it is converted to assembly, but what kind of assembly?

Binary/Hex Programming
Let's say I'm a Windows user. If I want to make a program, I could code exe files in hexadecimal. But that's not a good approach right? So how can one do it?

How do OSs work?
I am familiar with the functions and how most computer components work (RAM, CPU, HDD, Graphics Card, Input, Output, ...). However, I can't even grasp the concept of OSs and how they work.


Can any of you try and help me with these questions? Thanks Smile [/list]
ScoutDavid wrote:
What is C converted to?
Well, it is converted to assembly, but what kind of assembly?
Any kind is possible! Well, it depends on the compilers... For example, compilers that compile PC programs obviously compile to x86 machine code (or the 64-bit version of it), and ones that compile Prizm programs obviously compile to SH3 machine code.
ScoutDavid wrote:
Binary/Hex Programming
Let's say I'm a Windows user. If I want to make a program, I could code exe files in hexadecimal. But that's not a good approach right? So how can one do it?

You could use that C compiler you mentioned.. or an assembler (say, NASM, or MASM)
Or C++ or C# or D or any of the hundreds of programming languages for which compilers that target windows are available.

ScoutDavid wrote:
How do OSs work?
I am familiar with the functions and how most computer components work (RAM, CPU, HDD, Graphics Card, Input, Output, ...). However, I can't even grasp the concept of OSs and how they work.

It depends. There are monolithic kernels and nanokernels and everything in between. Most of them have in common that they abstract the hardware away from programs, and restrict normal programs from directly mucking around with the hardware as "protection". Then again, some make no such effort (DOS for example) or protect only some of the hardware (TI-OS for example)
Coding a .exe in hEx is a terrible idea. You can make .exe programs using almost any programming language, such as C, C#, and Visual Basic.
I'll be watching this topic since I too have unvoiced questions about the complexities of writing and compiling a program...
1. Any possible assembly language that supports at least a MISC instruction set Smile C can be used for an 8080, z80, SH3, x86-64, you name it Very Happy

2. Souvik++ - it's a bad idea scout. if you're going to write in x86 assembly at all, I would at least suggest using MASM as an assembler, it makes it MUCH EASIER.

3. And OS basically provides the framework for all other software applications on a device. Basically, so you don't have to rewrite TONS of routines every time you make a simple program, the OS provides you with tons of already-defined things so that software can be written easily (like, in windows case, it defines like 99.999% of what 99.99% of most programs use) and without an OS it would be a pain to even write a hello world program.
Thanks everybody, I have a new question:

Where does the console come from?
When I make a C program it'll be ran in a console (probably, let's say it's a printf("Hello World");, no GUI). Python programs will too, since the interpreter was made in C.

So what about C# and other languages? Is the console made in Assembly?

Maybe I'm confusing the whole thing...


@Ashbad, Souvik: I was not not planning to do so, I've seen their hex code and it's impossible to comprehend.

I got a bit more of OSs, but am still confused with the kernel thing. Perhaps I need to understand calculator OSs and then try to understand computer OSs, since doing that helped me for all other components.
Scout, coding .exe's in hex isn't impossible if you understand their weird formatting. It's just not recommended, because the headers are so bizarre. My personal opinion is that they were either high on something when they came up with the format or using way too many 512 KB HDDs.

Now, onto the questions:

From what I can tell, your primary confusion is how OSes work. First, you have to recognize that the primary purpose of the OS is to manage the hardware and get it to work together properly. To do this, the OS controls and works with the hardware CPU. However, as you know, programs written in machine code (which is what C and other similar languages compile to) are not terribly portable across different chips. This is why most computers use x86 processors. The standard assembly language allows multiple OSes to be run on the processor. Things like graphics chips and wireless adapters though, are not as standardized. To control these peripherals (in computer OSes), things called Drivers are used which act as add-ons to the OS. The OS talks to the drivers and sends requests to them. The drivers then control the physical hardware, including all of the device specific stuff that the OS doesn't know how to use, and report back when they've finished whatever they were asked to do.

That's an overview of the lowest level of the OS. It simply controls the hardware. When you think about it though, controlling the hardware is difficult and it gives programs a lot of power. What if you don't want to write for every possible computer system out there or you don't trust other people' software with absolute control over your system? That brings us to the next level of the OS which is hardware abstraction. The main point of hardware abstraction is that you can write a program for a Windows computer and as long as the other computer is running the same version of Windows (or Linux, Mac OS X, etc), the program will probably work. The OS provides what is called an Application Program Interface (API) to programs where it gives them access to OS functions (as TI-OS does) to do certain common things like print text on the screen. This means that the OS takes care of the system specific stuff like talking to the screen driver so the program just has to do printf("Hello World") or whatever the syntax is in that language (which is then compiled to a series of system calls). The other consequence is that the OS retains absolute control over the system. Since applications aren't directly talking to the hardware, the OS can shut them down without too much effort if it needs to (threading offers another way to do this by simply terminating execution of the thread using the OS thread handler. I'd be happy to explain threading if you'd like).

On top of the API lies the user interface, which is essentially what you see when you interact with it.

That's a quick and *very* simplified description of how OSes generally work. It's really much more complicated once you get into the "how's" of the matter.

As for the console, it's part of the OS. Somewhere on your hard drive, there's a bunch of code to talk with the screen and display a console. It's the OSes' job to manage all of that so that you don't have to write a thousand lines of code just to print Hello world. The bulk of a computer OS is generally written in C or C++ and compiled to machine code for the target processor type. The OS just contains those hundred lines of C or whatever ridiculous amount of code it takes to print the stuff on the screen and calls that code whenever your hello world program tells it that it needs to print the string (which the OS knows should be printed inside of a console).

Interpreted languages like C# (actually CIL, since C#, Visual BASIC, Visual C, etc all compile to the same machine code) and Java are really big and very different kettle of fish, though. What the interpreter does is look at the file, parse the code into machine code for the processor that's running the interpreter, execute that code and then go onto parsing the next piece of the code. There are ways of doing this in order to make it more efficient, but they're kind of painful to explain in any detail.

Hope that helps Smile
ScoutDavid wrote:
What is C converted to?
Well, it is converted to assembly, but what kind of assembly?


Depends entirely on the target platform.

Quote:
Binary/Hex Programming
Let's say I'm a Windows user. If I want to make a program, I could code exe files in hexadecimal. But that's not a good approach right? So how can one do it?


You don't.

Also, you can't program in binary/hex - neither of those are languages. You can program in assembly represented as hex, but you cannot program in hex.

Ignoring all that, exes have a *ton* more metadata than a TI assembly program. Coding an exe directly is going to be extremely difficult and is very OS specific.

Quote:
How do OSs work?
I am familiar with the functions and how most computer components work (RAM, CPU, HDD, Graphics Card, Input, Output, ...). However, I can't even grasp the concept of OSs and how they work.


What do you not understand? The OS manages hardware, memory, processes, threads, and provides standard libraries.

Quote:
Where does the console come from?
When I make a C program it'll be ran in a console (probably, let's say it's a printf("Hello World");, no GUI). Python programs will too, since the interpreter was made in C.


The console usually comes from the OS, kind of. printf and friends are part of the standard C library. However, what they actually "write" to are 3 file descriptors - stdin, stdout, and stderr. These can be routed at will on all the major platforms. The consoles you are familiar with actually operate using the ability to redirect those 3 - none of them are part of the kernel or standard library.

Quote:
So what about C# and other languages? Is the console made in Assembly?


All languages that write to the console use the stdin, stdout, and stderr. The console is most likely not written in assembly, it is probably C. In fact, very little in the OS is written in assembly (what little assembly there is is concentrated in the kernel).

Quote:
I got a bit more of OSs, but am still confused with the kernel thing. Perhaps I need to understand calculator OSs and then try to understand computer OSs, since doing that helped me for all other components.


A calculator OS has approximately jack squat in common with a desktop OS. If you really want to understand how a desktop OS works - write your own: http://wiki.osdev.org/Main_Page
Quote:
Also, you can't program in binary/hex - neither of those are languages. You can program in assembly represented as hex, but you cannot program in hex.
I've been trying to explain this for months, but hEx coders don't listen. Wink We've generally settled at calling what they call "programming in hex" hEx as a descriptive (and slightly mocking) term.
KermMartian wrote:
Quote:
Also, you can't program in binary/hex - neither of those are languages. You can program in assembly represented as hex, but you cannot program in hex.
I've been trying to explain this for months, but hEx coders don't listen. Wink We've generally settled at calling what they call "programming in hex" hEx as a descriptive (and slightly mocking) term.


They'll learn when I start editing their posts, don't worry - I got this.
/me still likes hEx, whatever kllrnohj says
When I said 'code in hex', and I already said this, but it seems like I have to repeat myself, I mean coding x86 in hex. Cross-Platform Assembly coded in the hex form of it.

@Qwerty: Your explanation helped me tons.

New question for you (thanks!):

I kind of understand 32bit X 64 bits, do they require different assembly languages? Like x86-64 and x86-32?
I see products that work in 64 bits only, but 32 bits will work on both, I think. So is it better to code in x86-32? Is x86-64 faster?
They're practically the same language, x64 has some new stuff and drops some old stuff though.
x64 is usually not significantly faster by itself (the extra registers don't matter much, L1 cache is fast), but x64 support implies SSE2 support so you can use that without checking for support and you can use more than 2GB (3GB if booted with /3GB option or 4GB on 64bit OS and LargeAddressspaceAware bit set) RAM without having to use Address Windowing Extensions.
harold wrote:
They're practically the same language, x64 has some new stuff and drops some old stuff though.
x64 is usually not significantly faster by itself (the extra registers don't matter much, L1 cache is fast), but x64 support implies SSE2 support so you can use that without checking for support and you can use more than 2GB (3GB if booted with /3GB option or 4GB on 64bit OS and LargeAddressspaceAware bit set) RAM without having to use Address Windowing Extensions.


Is that why Vista/7 64 boots faster on 3 or more gigs of RAM than XP?
I don't know, in my experience all those OS's boot really quickly the first month or so and then just keep getting slower and slower.. even W7 x64 with 8GB ram
DShiznit wrote:
harold wrote:
They're practically the same language, x64 has some new stuff and drops some old stuff though.
x64 is usually not significantly faster by itself (the extra registers don't matter much, L1 cache is fast), but x64 support implies SSE2 support so you can use that without checking for support and you can use more than 2GB (3GB if booted with /3GB option or 4GB on 64bit OS and LargeAddressspaceAware bit set) RAM without having to use Address Windowing Extensions.


Is that why Vista/7 64 boots faster on 3 or more gigs of RAM than XP?
I wouldn't say that that is quantitatively true; as harold implies, it depends a lot on the software and hardware configuration. I'd say Vista/7 are just faster than XP in general, although that could be biased by having running Vista/7 on faster hardware.

Scout, as stated by others, the main difference in 64-bit x86 is that you have 64-bit registers, and more of them. 64-bit x86 CPUs can operate in 32-bit emulation mode, hence why 32-bit programs can still be run on them.
However, 16 bit programs, like most DOS games, cannot be run on them, unfortunately.
DShiznit wrote:
However, 16 bit programs, like most DOS games, cannot be run on them, unfortunately.
That's correct. Luckily, emulators like DOSBox support 16-bit software.
They don't support Toonstruck Sad
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
» Goto page 1, 2, 3, 4, 5  Next
» View previous topic :: View next topic  
Page 1 of 5
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement