Dark Bit Factory & Gravity

PROGRAMMING => General coding questions => Topic started by: Raizor on January 24, 2012

Title: Learning ASM
Post by: Raizor on January 24, 2012
I'm just wondering what would be the best approach to learning ASM. My aim would be to become familiar with x86 ASM but I'm wondering whether to bite the bullet and start there or spend some time on Z80 ASM or something else more simple first to get myself familiar with the basic concepts?

Any suggestions would be cool, thank you.
Title: Re: Learning ASM
Post by: hellfire on January 24, 2012
I guess a good start is to try a simple loop in inline assembly from within your favourite programming language.
Depends a bit on what you're heading for, though. If your goal is eg a 256byte 16bit dos intro, you shouldn't start in a 32- or 64-bit windows environment...

Title: Re: Learning ASM
Post by: Raizor on January 24, 2012
I hadn't thought of that Hellfire. Good idea, thank you.
Title: Re: Learning ASM
Post by: Stonemonkey on January 24, 2012
I think this could be something everyone's going to have a different opinion on.
imo it depends on why you want to learn and what you want to do with it, the only reason I can see for starting on something like the Z80 is out of curiosity, there may still be some devices in industry that require it but that's going to be very rare. If you want to try some demo coding on things like the speccy or amstrad it gets a bit more tricky as there's a lot of other things to learn about the systems as well as programming the CPU.
I don't see anything wrong with starting with x86, the concepts are the same but you have more registers and a more comprehensive instruction set, if you want to do some tiny coding then you need to learn a bit about the system too. On the other hand, if it's to write faster code sections within some project and the language you use allows inline assembly then you only really need to understand the data structures the language uses.
For inline use some might say that it's not worth it and that it's difficult to beat the modern compilers but I don't think that's always the case although it can be difficult to manage asm so it's better to keep it down to small sections of code.

Fryer
Title: Re: Learning ASM
Post by: Jim on January 24, 2012
I think Z80 is at least as hard as x86.
Jim
Title: Re: Learning ASM
Post by: Raizor on January 24, 2012
Thanks Stonemonkey and Jim.  My main reason for learning x86 ASM is to be able to hand optimize code at some point in the future and of course curiosity. It's always seemed very mysterious to me and I've been wanting to learn for many years now. I did a tiny, tiny bit of ASM coding on the PS2 quite a few years back but wasn't very comfortable with it at all back then.
Title: Re: Learning ASM
Post by: Stonemonkey on January 24, 2012
Forget about Z80 or anything like that then, do as hellfire suggests and maybe try accessing variables/arrays/structs also.

There's different syntax' too, personally I prefer intel over AT&T but I guess it's whatever you start off with and your compiler might let you choose.

Once you decide that you've got a section of code you want to optimise by writing it in assembly, be sure that you're happy that you've optimised it as much as possible in whatever language you're using first, a slow algorithm is a slow algorithm in any language but probably harder to further optimise in assembly.
Title: Re: Learning ASM
Post by: Raizor on January 24, 2012
Much appreciated Stonemonkey. I'm sure I'll hit you up for more tips later ;)
Title: Re: Learning ASM
Post by: hellfire on January 26, 2012
I did a tiny, tiny bit of ASM coding on the PS2 quite a few years back but wasn't very comfortable with it at all back then.
If you're talking about vector-unit assembly: Don't mind, it really wasn't comfortable for anyone! :)

Quote
My main reason for learning x86 ASM is to be able to hand optimize code
Asm-coding is mainly about finding the most clever, elegant and tight solution for an algorithm.
From my experience the easiest way to learn that is to look at other people's code.
Unfortunately you won't find many resources which are usable within a modern high-level-language because compilers produce good speed and nobody cares about size anymore.
But feel free to post some example code (whether asm or c) and we can try to make it cool :)
Title: Re: Learning ASM
Post by: Raizor on January 26, 2012
@hellfire Hehe, I know a couple of masochists who loved VU coding, but yeah it really had me stumped :)

Thanks for the offer, will surely take you up on that at some point.