Sign in to follow this  
v0dKA

Assembly Language

Recommended Posts

v0dKA    568
I recently started learning assembly language for my calc, but I'd really like to try it on the computer. But I may have some wrong ideas that I'd either like to correct, or make sure they're really wrong: 1) Does every CPU have a seperate assembly language? I got this idea from the fact that the assembly language for my calc is "z80", and I think the CPU goes by the same name. Would that mean that what I write on my Intel machine wouldn't work on someone's AMD machine? 2) Are all assembly languages somewhat similar? Do they all have pretty much the same idea, with jumps, calls, and working up close and personal with individual bits and bytes?

Share this post


Link to post
Share on other sites
Kelly G    358
1) Mostly but AMD and Intel PCs should be the same, since the run the same software.

2) Yes, on the surface all assembly languages look the same but they are different as far as different machines do things differently from one another.

Share this post


Link to post
Share on other sites
abeylin    304
Assembly language for Pentium and Itanium (both Intel) is different, since they got different registers.
AMD and Intel can't run the same programs if you compile your application with Intel-specific instructions. In fact, I had a commercial game fail on me because I had Cyrix CPU. That game was Might and Magic 6, I believe, and the company had to issue a patch for non-Intel CPUs.

In fact if you optimize for Pentium 4, you probably won't be able to run on Pentium 3, because they likely added registers.

But all those cases are extreme (except for Pentium and Itanium, they really have a separate Assembly language), because they involve optimizations, which you don't need to use.

If you want your program to be cross-platform, you can't use assembly, because its completely different on Unix platforms.

Share this post


Link to post
Share on other sites
NoSuchMethod    169
To answer your first question, you need to write different assembly for each TYPE of processor. So the same generic code will compile on both intel and AMD x86 processors, like the pentium or athlon (although each company added their own features too, which you could take advantage of at the cost of losing compatability for the other), but not on say, an AMD64 or an ARM. And your calculator assembly code probably wont work on either, unless it was heavily modelled after them.
To the second query, YES. The foundations of computer science don't evolve as quickly as the higher level stuff, and pretty much any system you write assembly for will have registers, a stack, and a heap, as well as instructions like mov, add, jump and all the rest. As stated above though, many processors will also have their own specialized functions - creating truly optimized machine code for a specific processor will almost certainly require reading up on these.
One other thing. There is one area in games where assembly code is currently on the cutting edge - writing shader code for programmable GPU's. So if you have any interest in writing assembly and working in a fresh new area of game programming at the same time, you might consider getting into shader stuff.

Share this post


Link to post
Share on other sites
Onemind    265
1)
You may be able to find a "Cross-Assembler" for Z80 to x86 (a cross assembler generates byte-codes for one platform from the assembly languge of another platform). In general though, you'd be better off rewriting the assembly language yourself.

2)
There are 2 schools of thought on chip design (and thus on assembly language programming). Chips are generally either CISC (complex instruction set chips) or RISC (reduced instruction set). x86 chips are CISC, and have 200+ instructions. ARM and PowerPCs are RISC chips, and have 50+ instructinos. CISC instructions generally take longer to execute, but fewer of them are needed. RISC instructions execute more quickly, but it takes more of them to do the same job. People argue that CISC or RISC is better, but it really doesn't make a difference (flame sheild up).

Share this post


Link to post
Share on other sites
v0dKA    568
Hmm... aren't all programs made out of assembly language? When you ship an executable, isn't the program in assembly language format? Wouldn't that mean that I have the same restrictions in C++ as I do with assembly? Am I totally getting the wrong idea [smile]?

Also, what exactly should I learn then? What is the name of the most generic, cross-platform (or otherwise good) assembly language?

Share this post


Link to post
Share on other sites
Kelly G    358
Commercial software is machine instructions. Assembly language is not written quite the same (though conceptually it is mostly the same). That is why if you write in assembly language, you still need to use an assembler to translate into machine code.
When you write in C or C++ it is translated by the compiler into assembly language and then assembled into machine code by an assembler, there for C/C++ is definitively no more expressive than assembly language.

Share this post


Link to post
Share on other sites
Kelly G    358
Not really. I think you'll find that many fundamental opertations are machine specific, though in high-level languages this fact is hidden. When you compile C/C++ there is a different version of the compiler on each machine that produces different assembly language. If you want to write cross-platform software, you'll need to use a high-level language.

Share this post


Link to post
Share on other sites
davedx    166
AMD and Intel CPU's are both based on the 80x86 architecture, which means they both share a base set of instructions. However, each vendor adds specific 'extra' instructions - e.g. 3DNow!, MMX, etc. to their CPU's.

Regarding compilers, a quick glance at the available compiler settings in VS.NET gives me optimisations for Pentium, P-Pro PII & PIII, or P4 and above. I can also 'Enable Enhanced Instruction Set' for SSE or SSE2. Hmmm.

But yeah, all assembly languages follow the same patterns, because humans prefer comfortable similarity to lateral thinking. ;) Maybe one day someone will build a massively parallel neural-net based CPU though, and assembly language will undergo a radical change...... :D

Share this post


Link to post
Share on other sites
Woodsman    426
Quote:
Original post by abeylin
If you want your program to be cross-platform, you can't use assembly, because its completely different on Unix platforms.
Huh?

Share this post


Link to post
Share on other sites
Neil Purvey    122
Quote:
Original post by Woodsman
Quote:
Original post by abeylin
If you want your program to be cross-platform, you can't use assembly, because its completely different on Unix platforms.
Huh?


huh??? Unix platforms? what has that got to do with the processor, its an operating system.

Basically, using assembler you cannot make it platform dependant because in effect you are using an assembler built for each processor.

Languages like C, C++ and several other HLL's are made so that they can be portable across platforms as long as the compiler is able to xcompile (cross-compile) into the target systems machine code.

A mixture of HLL and assembler are the best way of getting speed and re-usability out of a build of software, dependant on the application. Assembler is only really there for optimisation.

Share this post


Link to post
Share on other sites
HalfHarvest    118
Quote:
huh??? Unix platforms? what has that got to do with the processor, its an operating system.


The OS DOES have something to do with it. Tho the majority of the logic would remain the same (for subroutines doing the majority of your number crunching), you're going to become incompatible between OS' if you hook into OS specific features (i.e., Win32 API or *nix system calls). The OS will still be a consideration unless you're writing something that doesn't use system calls.

Quote:
Hmm... aren't all programs made out of assembly language? When you ship an executable, isn't the program in assembly language format? Wouldn't that mean that I have the same restrictions in C++ as I do with assembly? Am I totally getting the wrong idea ?

Also, what exactly should I learn then? What is the name of the most generic, cross-platform (or otherwise good) assembly language?


No, when you ship a program that's been compiled in a HLL, it's in machine code, not ASM. It's a real pain in the ass to derive the ASM from the machine code since the von Neumann architecture makes no distinctions between instructions and data. Things can be quite confusing when you're looking at machine code and see it using an instruction as data and data as an instruction.

You seem to have the wrong idea of what cross-platform means. AMD and Intel procs are the SAME platform (x86) with a relatively small subset of proc specific features. By and large, code written for either proc will run on the other (again, provided that you don't use proc specific features). Cross platform would mean the same code being able to be compiled on MANY differing platforms. For example, you write a console app in plain ol' ANSI C or C++, you could compile it to run on x86 and recompile it to run on a PowerPC. That is cross platform. You can't do the same with ASM.

As you can see, ASM affords you MORE restrictions than C++.

I'd recommend grabbing Randel Hyde's "The Art of Assembly" if you'd like to start learning since it's freely available (google it). You'll want the 32-bit edition.

Hope this was somewhat helpful. It's probably cryptic since I'm still half asleep here. Guess I'll go get some friggin' coffee! :-)

Share this post


Link to post
Share on other sites
Woodsman    426
Quote:
Original post by HalfHarvest
Quote:
huh??? Unix platforms? what has that got to do with the processor, its an operating system.


The OS DOES have something to do with it. Tho the majority of the logic would remain the same (for subroutines doing the majority of your number crunching), you're going to become incompatible between OS' if you hook into OS specific features (i.e., Win32 API or *nix system calls). The OS will still be a consideration unless you're writing something that doesn't use system calls.
True, but that can be true of a number of languages...

Anyway, I wouldn't want to call much in the Win32 API if I were number crunching, but maybe that's just me.

Share this post


Link to post
Share on other sites
Kelly G    358
Specifically I was thinking that Unix systems are often different hardware than Windows. Though there are some intel Unix machines, many are SPARC and MIPS machines. Also Mac OS obviously runs on different machines than any of these.

Share this post


Link to post
Share on other sites
Cherez    175
While there is some difference between OSes, most assembly code will still be protable between Windows and Unix on an x86. only things to watch out for wuld bel aoding external (OS specific) libraries or interrupts, if you rewrite those parts for each machine everything should work nicely. You also could research combining assembly with C/C++ so you can just write perforamnce critical parts in assembly without having to do the rest of the work keeping portability and just plain writing loads of low level code.

As for programs being in assemlby, programs are actually stored in machine code, assembly lnaguage isbasically machine code using words instead of hex digits so humans can read it more easily.

Share this post


Link to post
Share on other sites
HalfHarvest    118
Was just a for instance since I think that's what abeylin was trying to convey.

Isn't it wonderful how in my post I forgot to mention differing OS' as well in my cross-platform junk? Jeez, shouldn't post when still waking up.

Share this post


Link to post
Share on other sites
Cherez    175
Quote:
Original post by Kelly G
Specifically I was thinking that Unix systems are often different hardware than Windows. Though there are some intel Unix machines, many are SPARC and MIPS machines. Also Mac OS obviously runs on different machines than any of these.

In my experiance as a Linux user I've found the vast majority of Unixers run on x86 PCs. Now I guess it's being overtaken by OSX, but it's still much more common to find Unix on an Intel platform than most others.

Share this post


Link to post
Share on other sites
HalfHarvest    118
Quote:
Original post by Cherez
Now I guess it's being overtaken by OSX...


Only if you're counting people that don't know what a csh prompt is as Unix users. :-) Most OS X users wouldn't know what the shell was if it bit 'em on the rear.

EDIT: Was a little too general on OSX users. Some of them actually do know what it's all about and use it, just not the same quantity as Linux/BSD users since they normally installed it for the purpose of using a Unix type system.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this