Assembly For My Mac

Luminary
Posts: 5,143
Joined: 2002.04
Post: #16
"assembly" is machine code presented in a human-readable form... nothing more, nothing less. There's no implication about whether there is or isn't an operating system involved, for example.

You can see the assembly code for any existing application or library by running otool -tV on it in the terminal.
Quote this message in a reply
Member
Posts: 198
Joined: 2005.01
Post: #17
In fact if you look out on the web, some crazies have written things like web CGI scripts for Win32 using assembly. Smile

Also most operating systems are not written in assembly. The last modern one I know of to have a significant amount was OS/2. Most these days have a very tiny amount of assembly for things like low-level task switching and the initial booting. The rest is usually C or C++. Though you can go to a ludicrous extreme here too -- I've heard of an OS written in Perl...

Cryptic Allusion Games / Cryptic Allusion, LLC
http://www.cagames.com/
Quote this message in a reply
Jones
Unregistered
 
Post: #18
I asked, because it's always been a dream of mine to make a simple OS. Just something that would boot and print out "Hello, World!".

Any tutorials you know of?
Quote this message in a reply
Member
Posts: 198
Joined: 2005.01
Post: #19
This is x86-centric but has some good stuff.

http://www.nondot.org/sabre/os/articles

Cryptic Allusion Games / Cryptic Allusion, LLC
http://www.cagames.com/
Quote this message in a reply
Moderator
Posts: 3,573
Joined: 2003.06
Post: #20
>>Any tutorials you know of?

The underlying electronics is just too complicated to access on a casual hobbiest level anymore. You could look up kernel design or something like that, but be prepared for stuff that'll get complicated quickly. There are some tiny projects laying around here and there that do that but the last one I ever saw for the Mac was InfiniteOS (IOS) several years ago. I don't know what's out there now. If you're really interested in what makes computers tick at their core, maybe to get a better idea of what an operating sytem does, there are only a few recommendations that I can think of. One, think retro. Older computing books can be gold mines of knowledge. Things are moving so fast now that the language in modern low-level books has become quite cryptic IMHO. Older literature is more accessible I think; if you can find it. There is a nice modern book for the layman called simply, "CODE" by Charles Petzold from Microsoft Press that I thought was a great read. Not anything that'll make an operating system, but nice reading on the general subject. Studying basic digital electronics will also get you much closer to understanding the underlying complexities that an OS does. It's not a whacky dream, you'll just have to aim lower and go retro if you want to see results. http://www.xgamestation.com/index.php is another possible direction to take. Whatever the case, you'll find a lot more available info on the PC side of things than the Mac, without a doubt.
Quote this message in a reply
Member
Posts: 70
Joined: 2002.07
Post: #21
Jones Wrote:Excuse my noobieness, but am I correct in assuming that assembly is the "art" or "task" of writing base code for a machine? Something that won't need an operating system, or be dependant on frameworks?

For example, you would start an Operating System from scrath using assembly programming, right?

You can use higher level languages without frameworks or APIs. Assembly is just the commands the CPUs in the machine understands. Languages, like C, are compiled into assembly, from where they are run.

Some languages, like JavaScript, Java, or .NET is compiled into byte code, which is compiled on the fly (it's a bit more complicated then this) into assembly.

No need to write operating systems in assembly, anymore. Just write them in a higher level language.

[>] Brian
Quote this message in a reply
Moderator
Posts: 3,573
Joined: 2003.06
Post: #22
ggadwa Wrote:Languages, like C, are compiled into assembly, from where they are run.
You mean they are compiled from high level languages like C into assemby, which is in turn assembled into machine code (1's and 0's), from where they run. Computers don't do assembly, they do binary. Down, down, down the hole them thar bits tumble! Maybe Lua within C, called from Cocoa, called from Carbon, using C/C++, assembled to PPC instructions, being 32 bits, which might be something whacky like 01011100011010101010001100101011 (I'm making that up, but still). For one single cycle. Pretty incredible?
Quote this message in a reply
Member
Posts: 198
Joined: 2005.01
Post: #23
Even more incredible is that many modern CPUs have lower levels than machine code. You just can't access them as a user. A really obvious example is the Transmeta Crusoe. It has its own whole supervisor written in VLIW that does JIT on x86 code to turn it into VLIW and execute it. Modern Intel/AMD processors also have many more than the standard 8 or so x86 registers, and they re-order your code on the fly, re-order registers to make use of the extra ones to do more than one instruction at once, etc. Desktop PPCs do this also, though they have more registers to begin with.

Cryptic Allusion Games / Cryptic Allusion, LLC
http://www.cagames.com/
Quote this message in a reply
Member
Posts: 70
Joined: 2002.07
Post: #24
AnotherJake Wrote:You mean they are compiled from high level languages like C into assemby, which is in turn assembled into machine code (1's and 0's), from where they run. Computers don't do assembly, they do binary. Down, down, down the hole them thar bits tumble! Maybe Lua within C, called from Cocoa, called from Carbon, using C/C++, assembled to PPC instructions, being 32 bits, which might be something whacky like 01011100011010101010001100101011 (I'm making that up, but still). For one single cycle. Pretty incredible?

Assembly is 0 and 1s. A assembly instruction, like a move or an add, is a certain string of bytes (0/1s).

[>] Brian
Quote this message in a reply
Jones
Unregistered
 
Post: #25
Shock Blink Annoyed

I understand the Basic concept of binary (in fact I even used to be able count in it), and how languages like C are translated into binary when compiled.

However, what I don't get is:

If you wrote an os in c, how the heck would the OS run? An empty machine has no c frameworks installed... How would the computer understand "itself"?

Unless.. oh no... computers are self-concious... there gonna come to life! AHHH! Wacko
Quote this message in a reply
Moderator
Posts: 3,573
Joined: 2003.06
Post: #26
ggadwa Wrote:Assembly is 0 and 1s. A assembly instruction, like a move or an add, is a certain string of bytes (0/1s).

[>] Brian
Assembly is a human readable language using mnemonics to *represent* instructions. It still has to be *assembled* into 1's and 0's using an assembler. If there were no need for an assembler then I would agree with you that it's as low as it gets, but that just isn't the case.
Quote this message in a reply
Moderator
Posts: 3,573
Joined: 2003.06
Post: #27
Jones Wrote:If you wrote an os in c, how the heck would the OS run? An empty machine has no c frameworks installed... How would the computer understand "itself"?
It starts at the lowest level in hardware with machine language instructions telling the processor where to look and what to do to get started. On the PC it would use programming in BIOS to get rockin, and on the Mac it uses programming in open firmware to get going (for now at least, the newer Intel based Macs will use something else apparently). The open firmware or BIOS provide the basic "frameworks" you're talking about, except they are usually called boot code, not frameworks.
Quote this message in a reply
Member
Posts: 70
Joined: 2002.07
Post: #28
AnotherJake Wrote:Assembly is a human readable language using mnemonics to *represent* instructions. It still has to be *assembled* into 1's and 0's using an assembler. If there were no need for an assembler then I would agree with you that it's as low as it gets, but that just isn't the case.

Not to get into a giant debate, but you said "you mean they are compiled from high level languages like C into assemby, which is in turn assembled into machine code (1's and 0's)"

C is not turned into assembly, it's turned into machine code. Assembly is machine code in human readable form, but is equivalent. When you ask XCode to show the assembly, it's just showing you the mnemonics (plus some convient labels which represent addresses.) There are not two steps.

That's what I was noting Smile

[>] Brian
Quote this message in a reply
Moderator
Posts: 3,573
Joined: 2003.06
Post: #29
I was taught that it's a two step process, but I can certainly see that there is no need for the textual assembly language representation. What I was try to point out is that the machine doesn't run assembly language, it runs machine code. The two are not equivalent to the processor, but I see what your angle is.
Quote this message in a reply
DoG
Moderator
Posts: 869
Joined: 2003.01
Post: #30
Just to add to the confusion, compiled code of any language doesn't necessarily depend on external frameworks. You only have to make sure to code sits at the right memory address when the CPU is started up. In PCs (and Macs) that's the boot ROM, BIOS or OF, respectively. To use external frameworks, all the OS does is put them into memory in the right places, too.

Typically, when a CPU comes out of reset, it starts fetching instructions (for simplicity's sake) from a hardwired memory address. Because it uses memory mapped IO, it doesn't necessarily have to be RAM that's accessed, but could be whatever the memory controller maps into the accessed address, say 0x0.

The boot ROM is responsible for setting up all the buses and peripheral devices, as well as configuring the CPU for proper the proper modus operandi, and loading the OS from some storage device.
Quote this message in a reply
Post Reply