Jump to content

Where to learn Assembly?

RileyTheFox
Go to solution Solved by Mira Yurizaki,
1 hour ago, EvilCat70 said:

Hey. I'm wanting to learn Assembly but I can't find anywhere on where to do it. I've been searching for hours on tutorials but none of the code they wrote actually works. I use Visual Studio 2019 and MASM to write in Assembly and nothing is working at all. I just want to write a Hello World program, but I can't even seem to do that. Where can I find a source of tutorials that actually work. It's frustrating to learn something if none of the sources of information are actually correct.

The first thing you need is the programming manual for the ISA the CPU uses. I'm going to assume you're using x86, so here's the programming manual for that: https://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-instruction-set-reference-manual-325383.pdf. There may be some implementation differences between Intel and AMD processors, but you'll largely never encounter this for casual programming.

 

As for programming in assembly itself, this may help https://www.tutorialspoint.com/assembly_programming/. And they're using x86 so it should be useful for your specific case.

 

Also writing "Hello world" in assembly isn't going to be as easy as most other languages, mostly due to the fact that the input/output is not as abstracted and is dependent on the OS. For example, this is how to do it in Linux (and BSD and BeOS): http://asm.sourceforge.net/intro/hello.html

 

I highly recommend learning assembly outside of an OS environment, i.e., on bare metal. When you're talking in the hardware's language, it helps if you can directly manipulate it without constraint. Modern OSes will do everything they can to prevent you from doing this (at least, if you're running your app with userland privileges).

35 minutes ago, EvilCat70 said:

Is there any way I could get this to work on Windows?

Use Linux subsystem for windows I guess. That things should be enough to run any native Linux binary. 

 

Why don't you just write your execution code in C btw? The complier should allow you to link any asm files you wrote and allow you to call assembly code in your c program. 

 

https://www.devdungeon.com/content/how-mix-c-and-assembly

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

12 minutes ago, wasab said:

Use Linux subsystem for windows I guess. That things should be enough to run any native Linux binary. 

So I have a VPS running Ubuntu, and if I do the assembler commands on there and run the file, it will say "Hello, world!", but using the Linux Subsystem on W10, I get this error:

 

image.png.5be4b2ebbb052bc1feef64859950cb1d.png

CPU: Intel Core i7 8700  

GPU: Gigabyte GeForce GTX 1070

MOBO: ASUS Z370-F STRIX  

RAM: 16GB Corsair Vengeance DDR4 2133MHz

Link to comment
Share on other sites

Link to post
Share on other sites

58 minutes ago, EvilCat70 said:

So I'm following the page you sent (https://www.tutorialspoint.com/assembly_programming/) and I'm having trouble at this part:

 

YL4emCQ07u.png

 

I can't link the object file using elf_i386. I have to use i386pe. Also when I run the executable, it doesn't say "Hello, World!". It runs (I think), but nothing actually happens.

 

I don't know if it's the assembling, the linking or the actual code itself. I have written it out exactly how the demo says to do.

Use 

nasm -f elf64 yourasmfile.asm yourasmObjectfile.o

 

to create a C object file from your assembly code.

 

Use 

gcc your_code_file.c yourasmObjectfile.o -o compiledbinary

 

To linked and compiled your C program and assembly code. 

 

Use

chmod +x compiledbinary

To give it execute permission. 

 

Then 

./compiledbinary

To run. 

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

3 minutes ago, wasab said:

Use 


nasm -f elf64 yourasmfile.asm yourasmObjectfile.o

 

to create a C object file from your assembly code.

 

Use 


gcc your_code_file.c yourasmObjectfile.o -o compiledbinary


 

To linked and compiled your C program and assembly code. 

 

Use

chmod +x compiledbinary

To give it execute permission. 

 

Then 

./compiledbinary

To run. 

image.png.b37b51538e86182ec1d9f89f278bcd0c.png

Am I really stupid or is this just not working?

CPU: Intel Core i7 8700  

GPU: Gigabyte GeForce GTX 1070

MOBO: ASUS Z370-F STRIX  

RAM: 16GB Corsair Vengeance DDR4 2133MHz

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, EvilCat70 said:

image.png.b37b51538e86182ec1d9f89f278bcd0c.png

Am I really stupid or is this just not working?

Use Windows instead of Linux subsystem for max support. Find whatever windows equivalent of nasm is. Find whatever linking and compiling commands of your windows complier is. 

 

Pretty sure you can just move your mouse around and click something in visual studio that does this automatically for you. Just google around a bit.

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

5 hours ago, EvilCat70 said:

Hey. I'm wanting to learn Assembly but I can't find anywhere on where to do it. I've been searching for hours on tutorials but none of the code they wrote actually works. I use Visual Studio 2019 and MASM to write in Assembly and nothing is working at all. I just want to write a Hello World program, but I can't even seem to do that. Where can I find a source of tutorials that actually work. It's frustrating to learn something if none of the sources of information are actually correct.

@Mira Yurizaki has already answered your question pretty well, but I think there is an angle missing here:

What is your goal with learning assembly?

I ask because x86 may not be the best platform to learn on. If all you want is to learn the basics of how processors work through programming, I would argue that you would be much better served by using an AVR or PIC microcontroller than by using a PC, whichever tactic you take with the PC. The reason is that the documentation is more thorough, and still comes in at roughly 1/10th the size. Additionally, the instruction set is much simpler and there isn't an OS that you have to interface with, allowing you to focus on what you are doing.

ENCRYPTION IS NOT A CRIME

Link to comment
Share on other sites

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

×