Advertisement

ASM? what is it?!

Started by September 05, 2000 03:50 AM
6 comments, last by stevenmarky 24 years, 3 months ago
I''ve heard about asm (assembly) a couple of times before - I''ve heard programming in it makes your programs run faster, why is this? - I only know it is something to do with the cpu. is it worth learning? Also how do you learn asm ( i have''nt seen any asm books)? and is it only used in C++, or other languages as well? DX++ The DirectX Programming Site
ASM is a programming language... its one level lower than c/c++
actually, c++ code turns into asm when it is compiled, before being turned into actual machine code and the .exe you end up with.
you can use inline asm in your c++ with visual c++, and it can speed up the program, but programming in pure asm is much more time consuming than programming in c.

as for how to learn it, try this tutorial:

Gamedev.net - Assembly Tutorial

Advertisement
ASM is not actually a programming language as such. Asemblers allow programmers to write machine code direct which unlike languages like C/C++, which are translated into an intermediate language before being converted into binary at the linking stage.

If you wish to entre ASM programming and collect the benifits from it, go to the intel site they have some nice documentation on there, but remember to get your processors full speed you have to know how the processor chache''s memmory and how the duel pipeline works because there are a lot of ASM programmers who beleave if they code a programme in straght it will out perform C/C++ code most of the time don''t because the compiler is aware of processor slow downs and speed up''s as well as some nice shortcuts and make use of them giving a definate edge.

An example is alot of people use the ''rep movsd'' command to copy memmory which is actually is not the fastest way to copy memory!
I program therefore can''t spell!
An assembly language is a low-level language that defines a computer architecture. By low-level I mean that lines of code in assembly language are much closer to the machine language that is understood directly by the hardware. When you compile a program written in a high-level programming language like C, what you're doing is translating your C code into assembly. The compiler will then invoke a program called an assembler, which converts the assembly language into the final machine code.

Writing assembly language code has the potential for speed because it's 'closer' to the hardware; that is, you have more control over the code that will ultimately be generated. High-level languages are more abstract, so you don't have as much control over the assembly that will be generated from your programs. You can't combine many operations on one line in assembly language, as you can in a high-level language. Each arithmetic operation is carried out on its own line.

I say that writing in assembly language has the potential for speed because in order to make it run faster than a C implementation of the same code, you need to make sure you squeeze out every optimization that you can. You can write assembly code that will be slower than the equivalent in C, if you do a lousy job writing the assembly. Back when compilers were not as good as they are now, knowledge of assembly language was a lot more important. But now that compilers are generating better assembly language, fewer people are learning and using it. Except of course, compiler writers, people writing operating systems (probably, for some parts), and us crazy game programmers.

Going back to earlier when I said that an assembly language defines an architecture... this means that different platforms have different assembly languages. They vary in a couple of different ways. First you have RISC and CISC architectures. RISC stands for Reduced Instruction Set Computer. Basically this means that the assembly language has a relatively small set of opcodes (an opcode is like a keyword in C), with few addressing modes (ways to specify an address within an instruction). There's probably a much better, more strict way to define RISC, but that's the general idea. CISC stands for Complex Instruction Set Computer, one that has a considerably larger instruction set. Generally, assembly programs written on CISC machines are harder to optimize because there will end up being a lot of ways to implement the same effects. There are a couple of other things that distinguish one assembly language from another, but I won't get into them... I have a feeling I've already said enough things that people are going to correct me on.

Even if you're not going to use it in your programs, I would say it's worth it to learn assembly language. Studying a low-level language will give you a better idea for what elements of high-level languages are fast, and which are not. It'll give you a lot of insight into optimizations you can make to your code, whether you're writing code in assembly or a high-level language. And if you're going to be going into game programming, there will probably be a few times when it will come in handy. In any case, it's good to at least be familiar with it. "Familiar with it" is about all I can say about my assembly language skills, hehehe. But I still think it was well worth learning. I think there is a series of articles here on GameDev that covers assembly language for Win32 programs.

Now, gurus of GameDev, feel free to point out all of the mistakes I have made.

-Ironblayde
 Aeon Software

EDIT: I always wondered... why does everyone capitalize ASM? It doesn't stand for anything.

Edited by - Ironblayde on September 5, 2000 5:46:42 AM
"Your superior intellect is no match for our puny weapons!"
Everyone capitalizes ASM to make it stand out.....they look important that way . "I use ASM" is better than "I use asm".

Or maybe not....

I have another ASM-related question: Would it be possible to actually code in machine language? That is, is it possible to think in opcodes, without worrying at all about their ASM representations? I mean, I know the first ASM compilers were written in machine code, but did they write it out by hand in ASM, figure out what the opcodes were, and then put it in the computer?

Martee
Magnum Games
ReactOS - an Open-source operating system compatible with Windows NT apps and drivers
It is possible to code in HEX, yes, but a lot of mnemonics in ASM translate into many different opcodes depending on their arguments, and RDTSC and CPUID are two opcodes in a row anyway. You also need to understand the way the instructions are arranged, and you wouldn''t get any of those benefits of Macro ASM.

------------------------------
#pragma twice


sharewaregames.20m.com

Advertisement
Martee -
Yes, it is. In mainframe assembler, when we write bug fixes, they are written directly in machine code. (actually the hex representation). Also, when writing licensing code, that you don''t want anyone to be able to find, it is common to hard-code the hex versions of different parts of the instructions in various places in a program, then copy the instruction pieces into an area of acquired storage, essentially building the instructions at run-time, and then hard branching into the constructed code.
"It's obvious isn't it Miller? Curiosity killed these cats!"
It''s definately worth learning an assembly language (there are many differant ones) thouroughly. In the process you will learn how computers *really* work.


Mike
"Unintentional death of one civilian by the US is a tragedy; intentional slaughter of a million by Saddam - a statistic." - Unknown

This topic is closed to new replies.

Advertisement