Page 1 of 3

Should I learn Assembly?

Posted: Sun Oct 18, 2009 10:15 am UTC
by LakatosIstvan
Hi. I'm a budding computer scientist. I have gotten my hands in a lot of programming languages, and now that I'm comfortable with coding, I was thinking maybe I should Assembly, mainly the x86 type. My question is: Is it worth it? Do I gain something from it?

Re: Should I learn Assembly?

Posted: Sun Oct 18, 2009 12:43 pm UTC
by Parsifal
Absolutely. It will give you a basic understanding of computer architecture and primitive data types. You will also get to take a nice nap in CSCI class while your friends are trying to wrap their heads around the concept of pointers. Plus, it's a fun hobby. On the other hand, I wouldn't look forward to getting a job in x86 assembly language coding right out of school. I think everyone should learn assembly language first.

Re: Should I learn Assembly?

Posted: Sun Oct 18, 2009 1:32 pm UTC
by LakatosIstvan
I hope it will be an enlightening experience like LISP was :)

Now, if only I could find a book or a tutorial to teach me... Any suggestions?

Re: Should I learn Assembly?

Posted: Sun Oct 18, 2009 2:43 pm UTC
by Berengal
LakatosIstvan wrote:I hope it will be an enlightening experience like LISP was :)

It'll be mind-boggling, but not the way LISP is.

Still, fun, in it's own kind of way.

Re: Should I learn Assembly?

Posted: Sun Oct 18, 2009 3:05 pm UTC
by Briareos
Sure, do it. Learning assembly was instrumental in helping me understand, to give one example, the call stack. I think a lot can be gained from studying it.

(I'm waiting for EduardoLeon to show up and say, "You should have been studying x86 assembly all along!")

Re: Should I learn Assembly?

Posted: Sun Oct 18, 2009 4:20 pm UTC
by Earlz
Yea.. assembly, though it may not give you any direct skills... it's definitely a learning experience to be able to look at

Code: Select all

*a=(*a)+1

and be able to say.. hmm

Code: Select all

mov ebx,[a] ;or esp+4 or somethign like that for local variables
inc [ebx]

and realize it's just 2 instructions.. so optimizing to use less pointer lookups is usually pointless..

I say the best way to get started with assembly is either write your own OS, or run your code in a DOS.. (both should be using only 16 bit code as a baby step)[and for that, http://osdev.org is a great reference]

It's really fun work to be in complete control of the computer.. though it can be a bit mind boggling when you have trouble debugging.. if your OS stays fairly simple though, bochs debugger should work fine..

edit:
Oh and please do us all a favor and just use yasm as your assembler.. don't for a second consider emu8086.. Oh.. and I wouldn't recommend fasm either because it doesn't support much.. I don't even think it has 64 bit support, and it isn't portable..

Re: Should I learn Assembly?

Posted: Sun Oct 18, 2009 4:53 pm UTC
by Briareos
Earlz wrote:Oh and please do us all a favor and just use yasm as your assembler.. don't for a second consider emu8086.. Oh.. and I wouldn't recommend fasm either because it doesn't support much.. I don't even think it has 64 bit support, and it isn't portable..
I've always used nasm ...

Re: Should I learn Assembly?

Posted: Sun Oct 18, 2009 6:51 pm UTC
by Goplat
Earlz wrote:and I wouldn't recommend fasm either because it doesn't support much.. I don't even think it has 64 bit support
Actually, fasm has had x86-64 support since version 1.60, released in March 2005.
and it isn't portable..
It supports DOS, Windows, Linux, and Unix (if it uses ELF objects and libc is available). What else would you be running on an x86?

Re: Should I learn Assembly?

Posted: Sun Oct 18, 2009 8:00 pm UTC
by Роберт
Yes, to be a computer scientist, you should have some knowledge of assembly. It's important for understanding computers, even if you may not use it much. (Well, a web developer probably doesn't need to know it, but I don't think of web developers as computer scientists. Sorry.)

Re: Should I learn Assembly?

Posted: Sun Oct 18, 2009 8:08 pm UTC
by Dropzone
Regarding tutorials, you might want to look through this thread: Any good tutorials to learn ASM with?.

Re: Should I learn Assembly?

Posted: Sun Oct 18, 2009 8:09 pm UTC
by Xanthir
Роберт wrote:Yes, to be a computer scientist, you should have some knowledge of assembly. It's important for understanding computers, even if you may not use it much. (Well, a web developer probably doesn't need to know it, but I don't think of web developers as computer scientists. Sorry.)

It's just as important to understand the machine when you're working in Javascript as it is when you're working in C. If you don't, you'll write horrible code either way.

Re: Should I learn Assembly?

Posted: Mon Oct 19, 2009 12:54 am UTC
by poohat
you could learn a less pathological architecture like MIPS instead, youll still pick up the basic concepts and itll be less frustrating than x86.

I dont see the point in learning assembly other than to understand how computer hardware works (which is admittedly important). C is basically just portable assembler so its not like learning asm is going to make you a better programmer if you already know C.

LakatosIstvan wrote:I hope it will be an enlightening experience like LISP was :)

Now, if only I could find a book or a tutorial to teach me... Any suggestions?

This is pretty classic, uses MIPS though.

Re: Should I learn Assembly?

Posted: Mon Oct 19, 2009 4:21 am UTC
by jroelofs
poohat wrote:I dont see the point in learning assembly other than to understand how computer hardware works (which is admittedly important)


If you've ever wanted to know how a compiler works, you'll probably do so using assembly. My compilers classes have revolved around writing a subset of Java to MIPS compiler, which we built from the ground up.

Learning ASM gives you a very good sense of memory layout, as well as the structure of the run-time stack (and knowing this makes you a better programmer).

Re: Should I learn Assembly?

Posted: Mon Oct 19, 2009 5:31 pm UTC
by Xanthir
poohat wrote:you could learn a less pathological architecture like MIPS instead, youll still pick up the basic concepts and itll be less frustrating than x86.

I learned assembly on MIPS, so +1 to that suggestion. It's rarely necessary to understand *actual* assembly, so learning a toy assembly is good enough. It gives you the gist of it, which is all you need if you stick with high-level languages.

Re: Should I learn Assembly?

Posted: Mon Oct 19, 2009 10:14 pm UTC
by fleshBasedProcessor
I've also been thinking about learning assembly. I was thinking about learning assembly for AVR microprocessors, since I have one available. Should I just wait and learn it in the computer architecture class I'll be taking next year instead?

Re: Should I learn Assembly?

Posted: Mon Oct 19, 2009 11:58 pm UTC
by Earlz
fleshBasedProcessor wrote:I've also been thinking about learning assembly. I was thinking about learning assembly for AVR microprocessors, since I have one available. Should I just wait and learn it in the computer architecture class I'll be taking next year instead?


From what I've seen AVR assembly is fairly easy.. and it never hurts to be a little bit ahead of the rest of the class lol. Going from say AVR -> x86 will be a challenge enough.. you might get annoyed when they begin with "registers are like a special small memory area" though

Re: Should I learn Assembly?

Posted: Tue Oct 20, 2009 12:15 am UTC
by Nath
Xanthir wrote:
poohat wrote:you could learn a less pathological architecture like MIPS instead, youll still pick up the basic concepts and itll be less frustrating than x86.

I learned assembly on MIPS, so +1 to that suggestion. It's rarely necessary to understand *actual* assembly, so learning a toy assembly is good enough. It gives you the gist of it, which is all you need if you stick with high-level languages.

Another vote for MIPS. I wouldn't really call it a toy, though.

Re: Should I learn Assembly?

Posted: Tue Oct 20, 2009 3:20 am UTC
by LakatosIstvan
But how am I going to write programs in assembly for the MIPS architecture if I don't have one?

Re: Should I learn Assembly?

Posted: Tue Oct 20, 2009 3:20 am UTC
by Carnildo
Xanthir wrote:
poohat wrote:you could learn a less pathological architecture like MIPS instead, youll still pick up the basic concepts and itll be less frustrating than x86.

I learned assembly on MIPS, so +1 to that suggestion. It's rarely necessary to understand *actual* assembly, so learning a toy assembly is good enough. It gives you the gist of it, which is all you need if you stick with high-level languages.

Depends on what you're doing with it. If you're busy tracking down a bug in the compiler you're using, you'll need to understand the appropriate assembly language.

Re: Should I learn Assembly?

Posted: Tue Oct 20, 2009 4:32 am UTC
by Nath
LakatosIstvan wrote:But how am I going to write programs in assembly for the MIPS architecture if I don't have one?

Spell it backwards.

Re: Should I learn Assembly?

Posted: Tue Oct 20, 2009 5:14 pm UTC
by LakatosIstvan
I'm not so sure about MIPS... I might actually want to write a few nifty programs for the x86 in the future :P. Even though MIPS assembly might be simpler than the x86 one, I'll still stick to ye good ol'(or new) x86. Now, off to write my OS :P

Re: Should I learn Assembly?

Posted: Tue Oct 20, 2009 5:42 pm UTC
by Earlz
LakatosIstvan wrote:I'm not so sure about MIPS... I might actually want to write a few nifty programs for the x86 in the future :P. Even though MIPS assembly might be simpler than the x86 one, I'll still stick to ye good ol'(or new) x86. Now, off to write my OS :P

you poor brave soul.. lol

I say x86 is easier to learn with, even if its just because you can run it on your physical machine(assuming you have an archaic floppy drive)

Re: Should I learn Assembly?

Posted: Tue Oct 20, 2009 6:55 pm UTC
by LakatosIstvan
I am lucky to live in a country where let's just say technology is lagging by 5 to 10 years :P. Seriously, there are many computers in Romania which still have floppy drives, even I have in my home two older computers which I can use to practice on. One of them is even used on a day-to-day basis. We got our first computer back in 1995 I think, probably an Intel or an AMD running DOS, I'm not sure, I haven't seen that computer in years, but I'm glad I owned one back then (I was only like 4 years old) because now I'm uber proficient at using terminals, command prompts. I even did a little programming back then, messing arround with the scripts for those banana-throwing King-Kong themed cannon games... Those days were sure fun... I remember when 3D Voodoo graphics cards were considered to be the ultimate gaming experience... God I miss ye old times.
I guess it's time to dust off and plug in the old-timer. ( I'm shocked how reliable old technology is. The other computer we have that my mother uses regularly for accounting was bought in 1997 or 1998 I think, and even after more than 10 years of service it still works almost perfectly. We only updated the OS once to Windows 98, replaced an old CD reader with a DVD reader. Unfortunately all the software installed on the little 3 GB harddisk really wears down the computer, after long runs it comlains that it need more RAM, but the problem is that they don't manufacture these types anymore :P )

Re: Should I learn Assembly?

Posted: Tue Oct 20, 2009 10:56 pm UTC
by EduardoLeon
Briareos wrote:(I'm waiting for EduardoLeon to show up and say, "You should have been studying x86 assembly all along!")


I'm too busy with the Forum Games. :)

Re: Should I learn Assembly?

Posted: Wed Oct 21, 2009 3:26 pm UTC
by Earlz
LakatosIstvan wrote:I am lucky to live in a country where let's just say technology is lagging by 5 to 10 years :P. Seriously, there are many computers in Romania which still have floppy drives, even I have in my home two older computers which I can use to practice on. One of them is even used on a day-to-day basis. We got our first computer back in 1995 I think, probably an Intel or an AMD running DOS, I'm not sure, I haven't seen that computer in years, but I'm glad I owned one back then (I was only like 4 years old) because now I'm uber proficient at using terminals, command prompts. I even did a little programming back then, messing arround with the scripts for those banana-throwing King-Kong themed cannon games... Those days were sure fun... I remember when 3D Voodoo graphics cards were considered to be the ultimate gaming experience... God I miss ye old times.
I guess it's time to dust off and plug in the old-timer. ( I'm shocked how reliable old technology is. The other computer we have that my mother uses regularly for accounting was bought in 1997 or 1998 I think, and even after more than 10 years of service it still works almost perfectly. We only updated the OS once to Windows 98, replaced an old CD reader with a DVD reader. Unfortunately all the software installed on the little 3 GB harddisk really wears down the computer, after long runs it comlains that it need more RAM, but the problem is that they don't manufacture these types anymore :P )


crap. A lot of the "newer" computers still have room for a floppy disk.. Like my dual-core AMD machine I bought 2 years ago.. it didn't have a floppy drive. But recently when I was switching out it's harddisk, I realized there was a little port on the mobo for floppy drive(but only 1 IDE channel port) so I kicked out a 3.5" piece of the case and stuck one in it..

Also, if you happen to be stuck on a computer without a floppy drive, if you stick to 16bit real mode, then flash drives are just as easy to use.. (just make sure to double check DL when your using int 0x13!)

Re: Should I learn Assembly?

Posted: Wed Oct 21, 2009 3:30 pm UTC
by lulzfish
Floppy drive?

I thought for OS dev you could just test on a virtual machine?

Re: Should I learn Assembly?

Posted: Wed Oct 21, 2009 3:34 pm UTC
by Briareos
It's certainly way faster when you only have one machine to work with.

/me considers going to RW to start a "bochs vs. qemu" thread

Re: Should I learn Assembly?

Posted: Wed Oct 21, 2009 4:34 pm UTC
by LakatosIstvan
So basically I could also use let's say Virtaul Box to test my OS in it? Neat!

Re: Should I learn Assembly?

Posted: Wed Oct 21, 2009 5:18 pm UTC
by lulzfish
Probably.

You could at least write your files to a floppy image, use V-Box to mount that on a VM, then test it in there.
Should be faster than shuffling floppies around, and you can move right up to LiveCDs and hard disk images without any effort.

Re: Should I learn Assembly?

Posted: Thu Oct 22, 2009 5:22 pm UTC
by Earlz
lulzfish wrote:Probably.

You could at least write your files to a floppy image, use V-Box to mount that on a VM, then test it in there.
Should be faster than shuffling floppies around, and you can move right up to LiveCDs and hard disk images without any effort.


Yea, I wasn't saying do all your work on a physical machine. Rather that having a few physical machines to test it on is valuable

Re: Should I learn Assembly?

Posted: Fri Oct 23, 2009 2:08 am UTC
by fazzone
But...although it may certainly be a learning experience (I found it so) to write assembler on the bare metal, though it's not necessary to do so to be able understand assembly.

Re: Should I learn Assembly?

Posted: Fri Oct 23, 2009 6:21 am UTC
by '; DROP DATABASE;--
poohat wrote:you could learn a less pathological architecture like MIPS
<3 R4300.

Z80 is nice too; make some Game Boy games. That was how I learned it.

Learning assembly is worth the bragging rights if nothing else. :D

Re: Should I learn Assembly?

Posted: Fri Oct 23, 2009 5:27 pm UTC
by You, sir, name?
LakatosIstvan wrote:Hi. I'm a budding computer scientist. I have gotten my hands in a lot of programming languages, and now that I'm comfortable with coding, I was thinking maybe I should Assembly, mainly the x86 type. My question is: Is it worth it? Do I gain something from it?


I'm not sure if it actually helps you with computer science, but it will make you a better programmer, as it is a surefire way of becoming intimately accustomed with the guts of both how programs you write in higher order languages are realized, and the workings of the processor.

If you don't want to actually take the time it takes to learn to write programs in assembly (since unless you find it really fun and fascinating, you could be spending that time doing something more useful), you can get a fair deal of the benefits out of skimming through the specifications of assembly language to the extent where you roughly understand how it's made up, and then go off examining compiler-generated assembly sources of simple language constructs like function calls and so forth.

Re: Should I learn Assembly?

Posted: Fri Oct 23, 2009 6:10 pm UTC
by shieldforyoureyes
'; DROP DATABASE;-- wrote:
poohat wrote:you could learn a less pathological architecture like MIPS
<3 R4300.

Z80 is nice too; make some Game Boy games. That was how I learned it.

Learning assembly is worth the bragging rights if nothing else. :D


Aye. I've written a few graphics demo programs in LINC machine language. How many people can claim that?

Posted: Fri Oct 23, 2009 6:14 pm UTC
by Hectamatatortron
Just had to dig up my password so I could post here.

YES learn assembly. I got tired of lacking the haxpertise to reverse engineer things, so with no prior programming experience I said "I don't care if it's hard" and taught myself assembly by reading opcode documentation and hand-assembling programs in hexadecimal (couldn't figure out how to work an assembler when I first started, see >_>).

Was proficient within 2 months (read: it wasn't as hard as I expected!) and when I finally started learning a high level language (starting teaching myself C because I was "tired of lacking", heh) a year later, it all made perfect sense to me.

By the time I got to Java I was like "oh lawdy this is too easy".

Now I'm in an assembly CLASS and made a perfect score on the midterm, which is where the "nap in class while friends wrap their heads around pointers" part comes in. In my Computer Architecture class we're going over the function of a CPU and seeing how assembly instructions are broken down into opcodes and operands, how they are reformed into the "control word", and how the control word's bits are plugged into various circuit inputs to bring about the intended effect of the original instruction. This, too is insanely easy to comprehend because of prior knowledge with assembly.

tl;dr learning assembly ahead of time just makes everything much easier. More fun, too, if you put it to use in hacking various applications (video games in my case; that link is to a video of some GameShark codes I made in action on some old N64 game - required lots of assembly programming to complete).

As was said, assembly isn't exactly practical for the job market (that I know of, though perhaps supreme proficiency is?). But if you learn Z80, for example, you can do things like program your calculator with more control over it than using its BASIC language (talking TI calculators, here) and do various other things to already-compiled programs that aren't quite up to par (such as modifying an application's code such that an external debugger that only has break-on-execute functionality can simulate behavior of break-on-read or break-on-write functionality).

It's like carrying a roll of virtual duct tape everywhere you go.

Edit: @shieldforyoureyes: I haven't done anything quite that impressive, but I have written a lot of custom graphical display code for the Gameboy Advance in good ol' Thumb assembly (first assembly language I learned). ARM cores are my favorite. <3

Edit: HyperHacker/Drop Database, how did I not foresee you posting in this thread? :P

Oh, also, to be more accurate, Drop Database is the one who taught me C. Not myself. >_>

Re:

Posted: Sat Oct 24, 2009 4:58 am UTC
by Earlz
Hectamatatortron wrote:Just had to dig up my password so I could post here.

YES learn assembly. I got tired of lacking the haxpertise to reverse engineer things, so with no prior programming experience I said "I don't care if it's hard" and taught myself assembly by reading opcode documentation and hand-assembling programs in hexadecimal (couldn't figure out how to work an assembler when I first started, see >_>).

Was proficient within 2 months (read: it wasn't as hard as I expected!) and when I finally started learning a high level language (starting teaching myself C because I was "tired of lacking", heh) a year later, it all made perfect sense to me.

By the time I got to Java I was like "oh lawdy this is too easy".

Now I'm in an assembly CLASS and made a perfect score on the midterm, which is where the "nap in class while friends wrap their heads around pointers" part comes in. In my Computer Architecture class we're going over the function of a CPU and seeing how assembly instructions are broken down into opcodes and operands, how they are reformed into the "control word", and how the control word's bits are plugged into various circuit inputs to bring about the intended effect of the original instruction. This, too is insanely easy to comprehend because of prior knowledge with assembly.


This!!

I actually taught myself C and assembly at about the same time.. but by the time I fully understood assembly, I fully understand C also. (including pointers and all that.. didn't figure out variable size structs and unions and enumerations until I started learning java and C# and thought C for surely must have this)

dang it.. I kinda wanna do some assembly hacking just for the heck of it now.. lol

Re: Should I learn Assembly?

Posted: Sat Oct 24, 2009 9:27 pm UTC
by Rysto
If you're going to be programming in C or C++, learning assembly has another benefit. This may be different on Windows, but all too often I find that gdb does a terrible job at working out the value of a critical variable(this may be gcc's fault, not gdb's). When that happens, the only recourse is often to look at the disassembly and work it out from that.

Re: Should I learn Assembly?

Posted: Sun Oct 25, 2009 4:57 am UTC
by poohat
LakatosIstvan wrote:But how am I going to write programs in assembly for the MIPS architecture if I don't have one?

You arent likely to write programs in either MIPS or x86, youre probably going to use them to learn how computer architecture works and then go back to using C for anything low-level.

Re: Should I learn Assembly?

Posted: Thu Oct 29, 2009 5:54 pm UTC
by Earlz
poohat wrote:
LakatosIstvan wrote:But how am I going to write programs in assembly for the MIPS architecture if I don't have one?

You arent likely to write programs in either MIPS or x86, youre probably going to use them to learn how computer architecture works and then go back to using C for anything low-level.


believe it or not, sometimes you need to go lower than C, it's a nifty skill that I think the OP is asking us about. (ever tried writing an OS? Sure you could generate HEX from C when you need to write interrupt stubs or a LGDT instruction, but thats just stupid.)

And if you want to write for MIPS, grab an emulator.. thats what you should always be doing anyway is emulating code except for everyone in a while, or if the actual device has something not easily emulated

Re: Should I learn Assembly?

Posted: Fri Oct 30, 2009 5:23 pm UTC
by chocolate.razorblades
I'm inspired to write my own OS as well!

Not right now, though. Not right now.