r/AskComputerScience • • Sep 03 '19

How to get started with learning Assembly Language?

Greetings,

I am a CS student and am on summer vacation. I was thinking of using this time to learn something new and am interested in assembly (as it also will be a part of my career later on as well).

The problem is that I'm having trouble getting started with it i.e: choosing an architecture and mainly finding learning material such as books, documentation, courses, forums etc. If anyone could give me some advice and general direction, I would be very thankful.

Regards,
Abraxas

31 Upvotes

24 comments sorted by

16

u/cogman10 Sep 03 '19

https://godbolt.org/

Set optimization to two. Write some simple functions, look up the assembly commands you don't understand.

Sure, x86 is vast, however the compilers out there only use a small portion of it.

This will give you a better idea for what assembly looks like and what the compiler is doing for you.

1

u/guardianabraxas Sep 03 '19

Thanks a lot, I'll take a look at it.

4

u/[deleted] Sep 03 '19

Learn C. Compile Hello World. Run binary through a disassembler. Study results.

1

u/guardianabraxas Sep 04 '19

I already know C. This is useful.

9

u/011101000011101101 Sep 03 '19

Not really sure on resources to help, but picking a risc architecture seems like a good place to start. It has fewer instructions and is easier to understand than others. Plus all smartphones use a variant of it so it's widely used today.

3

u/visvis Sep 03 '19

The disadvantage of RISC is that it wasn't designed to be written by humans but by compilers. x86 may be more complex, but it's also more human-friendly. It's also less of a hassle to run since it will execute on your PC.

8

u/011101000011101101 Sep 03 '19

When I was learning risc i remember it being easier to understand than x86 or any other architecture, but i might be a robot

5

u/visvis Sep 03 '19

Relevant username :)

The inline pointer computations, lack of separate load/stores, and longer immediate values means that RISC uses more instructions to achieve the same thing. I'd say this makes it harder to read and more work to write. Moreover, you need to plan your register use more carefully.

1

u/011101000011101101 Sep 04 '19

I don't really remember any details.. it's been almost a decade since I've looked at ISAs

5

u/claytonkb Sep 03 '19

Visual Studio allows you to view the assembled code after compiling from your favorite language. You can also halt using the debugger and view the exact assembly instruction you halted at. Unless you're going to be doing embedded design, there is very low ROI on learning assembly.

1

u/[deleted] Sep 03 '19

Can you share more about your background? What classes have you taken? Which programming language do you feel most comfortable with?

1

u/guardianabraxas Sep 04 '19

I'm doing my Bachelors in Computer Science and know C, C++, Java and Python (and a few other unrelated ones). I feel quite comfortable with C++.

The reason I want to learn a bit of Assembly is for a final project I want to do. I can write it in another language but just want to do it in Assembly for the challenge and because I want to peruse it.

1

u/[deleted] Sep 04 '19

Perfect!

Now...i'v read all the answers written so far. I'm very suprised that non of them tell the whole story. Someone even linked some compiler page(come on dude, really?!). That being said, lemme tell you that as a CS student you have to know enough about assembly to read it, writing it is totally different story.

In my opinion, and many studies(i could find one i was looking) show this, one of the most difficult subject for self-taught programmers(most of them give up in 2-3 hours) is machine organization. Learning assembly language is part of this course(as stated by ACM and IEEE computing society), which gives you totally different view of computation, no more abstractions! no more bullshit! let's get real!

Back to the point, i strongly recommend reading 'Computer systems programmer's perspective(3ed)'. It has absolutely everything you need to get started. Additionally here is class website from the authors themselves, to be honest i don't really enjoy watching the videos but these guys are legends -> https://www.cs.cmu.edu/afs/cs/academic/class/15213-f15/www/index.html . You can find video lectures here as well https://www.youtube.com/watch?v=4CpHpFu_KYM&list=PLbY-cFJNzq7z_tQGq-rxtq_n2QQDf5vnM.

After reading that book, you will be able to read assembly code generated by GCC from C code(which you stated you're familiar with). You'll learn to optimize your C code based on assembly code, learn about processor architecture, linkers, virtual memory, memory hierarchy, parallel programming and networking.

Let me state it again, STOP everything, leave this thread, start reading the book! don't stop!

Cheers

edit: oh...yes, forget about windows if your using it right now. Linux will be your best friend!

2

u/guardianabraxas Sep 04 '19

Thanks a lot! This is a very detailed answer and just what I was looking for. I've asked many people and all have given me a vague different answer each time so I don't know which one to do. Thanks for recommending the book as well as links to the videos as well as they can be a great help. I'll start right away.

Thanks again!

2

u/[deleted] Sep 04 '19

My pleasure. I'm going though it right now as well. Don't hesitate to ask me anything, will be glad to help if i can.
Cheers

1

u/[deleted] Sep 03 '19 edited Sep 03 '19

We are following this website for my assembly language class http://chortle.ccsu.edu/AssemblyTutorial/index.html

1

u/guardianabraxas Sep 04 '19

Thanks, I'll have a look at it.

1

u/[deleted] Sep 04 '19

The following is a free course hosted on YouTube about reverse engineering but it contains a large section that teaches assembly and covers also stack buffer overflow and other important it concepts

https://www.youtube.com/playlist?list=PLMB3ddm5Yvh3gf_iev78YP5EPzkA3nPdL

I hope it helps

2

u/guardianabraxas Sep 04 '19

Thanks, every bit helps

6

u/themeaningofhaste Sep 03 '19

I'm not sure this is the best way but it's a fun way to get an introduction: pick up the game TIS-100. It's literally an assembly language puzzle game, which sounds lame but it actually a lot of fun. It at least gets you thinking about a lot of the important concepts and is a very simple language versus real assembly.

1

u/WikiTextBot Sep 03 '19

TIS-100

TIS-100 is a puzzle video game and programming game developed by Zachtronics Industries. The game has the player develop mock assembly language code to perform certain tasks on a virtualized 1970s computer that has been corrupted. The game was released for Microsoft Windows, OS X, and Linux personal computers in July 2015.


[ ^PM | Exclude ^me | Exclude from ^subreddit | FAQ / ^Information | ^Source ] Downvote to remove | v0.28

2

u/[deleted] Sep 03 '19

Ghidra is kind of nice because you get the asm juxtaposed with the decompilation.

2

u/yendrdd Sep 03 '19

My machine language class wasn’t very good (the average of the two exams were below 50% without the curve.)

I recommend starting with a *NIX distro and convert common C programs into assembly with the -S command. Ie, gcc -S HelloWorld.c o- asm.s. This will help introduce how assembly programs are structured. From here you can make small modifications and learn how to manually store data into registers for arithmetic, for example.

0

u/[deleted] Sep 03 '19

[deleted]

1

u/visvis Sep 03 '19

Your best bet is picking a CISC architecture.

Agreed. For better or worse, x86 is much more like a higher-level language than RISC assemblies.