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).

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.

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

Assembly is a waste of time. Don't learn it. If you need something in assembly, just get a complier which literally translate the code of a higher language down to their respective assembly language. 

 

https://godbolt.org

 

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, wasab said:

Assembly is a waste of time. Don't learn it. If you need something in assembly, just get a complier which literally translate the code of a higher language down to their respective assembly language. 

 

https://godbolt.org

 

If I ask where to learn assembly, DONT tell me NOT to learn it.

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

2 minutes ago, EvilCat70 said:

If I ask where to learn assembly, DONT tell me NOT to learn it.

Suit yourself. And it's not like you mentioned what assembly you plan on learning so we point you in the right direction. 

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, wasab said:

Suit yourself. And it's not like you mentioned what assembly you plan on learning so we point you in the right direction. 

If I ask where to learn something and then you just tell me not to learn it, it kind of just defeats the whole purpose. I want to learn x86 or x64. But if you're just going to tell me not to learn something, don't bother replying. It's a waste of time.

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

2 minutes ago, EvilCat70 said:

If I ask where to learn something and then you just tell me not to learn it, it kind of just defeats the whole purpose. I want to learn x86 or x64. But if you're just going to tell me not to learn something, don't bother replying. It's a waste of time.

First of all, do you know how ASCII system works? How hexidecimal works? How you do bit manipulation and complements? You are literally and directly working with 1s and 0s here and doing bit manipulation without any higher abstraction. Get yourself familiar with the binary and hexadecimal system first else you will have a hard time debugging. 

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

Just now, wasab said:

First of all, do you know how ASCII system works? How hexidecimal works? How you do bit manipulation and complements? You are literally and directly working with 1s and 0s here and doing bit manipulation without any higher abstraction. Get yourself familiar with the binary and hexadecimal system first else you will have a hard time debugging. 

I know how binary and hexadecimal work. I've done quite a bit of reading on topics before heading into writing Assembly, it's just that I can't find any tutorial where the code actually works.

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

10 minutes ago, EvilCat70 said:

I know how binary and hexadecimal work. I've done quite a bit of reading on topics before heading into writing Assembly, it's just that I can't find any tutorial where the code actually works.

That will be difficult to find indeed. Pure assembly is not that common. People will more often use a higher level that will compile to assembly but do not write assembly directly. You are probably better off using a higher level language then compile it and then learn from the assembly VS the higher language so you understand why it optimized it that way and not another.

 

Here a site i just found that look correct if i go by their sample on the first page.

https://www.tutorialspoint.com/assembly_programming/assembly_basic_syntax.htm

 

 Their hello worlds seems it would work for i386 (this is using my i haven't worked with assembly in 20 years + eye)

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, Franck said:

That will be difficult to find indeed. Pure assembly is not that common. People will more often use a higher level that will compile to assembly but do not write assembly directly. You are probably better off using a higher level language then compile it and then learn from the assembly VS the higher language so you understand why it optimized it that way and not another.

I did find a tutorial that worked, but it was extremely simple. It let me write text in to memory and set a register to a number. I wanted to move onto a Hello World program, but I can't because absolutely nothing I've found works.

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

12 minutes ago, EvilCat70 said:

I know how binary and hexadecimal work. I've done quite a bit of reading on topics before heading into writing Assembly, it's just that I can't find any tutorial where the code actually works.

Buy a book since resources for x86 is scarce on the internet. 

https://www.amazon.com/Assembly-Language-x86-Processors-7th/dp/0133769402/ref=mp_s_a_1_2?crid=2YHFOHPWQMV7O&keywords=x86+assembly&qid=1556817694&s=gateway&sprefix=x86+&sr=8-2

 

Don't bother looking on stack overflow. Assembly is unreadable so it will be difficult to understand others code. 

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

36 minutes 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.

You might have a good chance if yiu search for a 8031 series microcontrollers, and a compiler/linker to go with it.

These are really easy to learn, 8 bit, and using emulator allows to step through codd seeing the effects of instructions.

Yiu can likely find the instruction sets descriptions online as well.

 

X86 and up is 16/32/64 bit, and to really run it "on windows" involves "a lot" and isnt trivial at al.

 

Do note that once you "get it" the instructionset only applies per model, so on a different architecture the basics are the same but as for instructions you are back to square one (but once youve seen a few, youll pick up on new ones real fast).

 

 

Link to comment
Share on other sites

Link to post
Share on other sites

4 minutes ago, wasab said:

Buy a book since resources for x86 is scarce on the internet. 

https://www.amazon.com/Assembly-Language-x86-Processors-7th/dp/0133769402/ref=mp_s_a_1_2?crid=2YHFOHPWQMV7O&keywords=x86+assembly&qid=1556817694&s=gateway&sprefix=x86+&sr=8-2

 

Don't bother looking on stack overflow. Assembly is unreadable so it will be difficult to understand others code. 

That's a little pricey? $167 for a book?

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 minute ago, EvilCat70 said:

That's a little pricey? $167 for a book?

not that much of you consider it's very rare people go into that direction. as @Bartholomew said, sticking to a 8 bit system will simplify everything by magnitude. I originally learned the basics of assembly on a proprietary language that emulated assembly in school and they used 8 bit controller. Was much easier than 16bit +

Link to comment
Share on other sites

Link to post
Share on other sites

17 minutes ago, EvilCat70 said:

I did find a tutorial that worked, but it was extremely simple. It let me write text in to memory and set a register to a number. I wanted to move onto a Hello World program, but I can't because absolutely nothing I've found works.

https://montcs.bloomu.edu/~bobmon/Information/LowLevel/Assembly/hello-asm.html

 

This is hello world. You allocated on memory a space to hold the starting address of your string aka char array. Assembly should automatically allocated enough memory to hold the entire string. 

 

Load the address containing the address of your string to an input register associated with system call. 

 

Load the kernel operation you want to call to a return register associated with system call. 

Next call operating system kernel.

 

Thats pretty much  what the code in the links did in a nutshell. 

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

1 minute ago, wasab said:

https://montcs.bloomu.edu/~bobmon/Information/LowLevel/Assembly/hello-asm.html

 

This is hello world. You allocated on memory a space to hold the starting address of your string aka char array. Assembly should automatically allocated enough memory to hold the entire string. 

 

Load the address containing the address of your string to an input register associated with system call. 

 

Load the kernel operation you want to call to a return register associated with function call. 

Next call operating system kernel.

 

Thats pretty much  what the code in the links did ina nutshell. 

I saw that page earlier and tried the code, it did not work.

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

5 minutes ago, EvilCat70 said:

That's a little pricey? $167 for a book?

If you wNt a head start in understanding "why" assembly instructions are eally simple/tiny - ( basically all you can do is move/set/clear/shift/compare bits, and subtract/multiply, plus (conditional) jumps and push/pop from stack) first look into von nuemann machine (take a example or vid that explains full cycle of a few instructions). That helps a lot to understand thorougly first before embarking on assembly.

 

And kudos for having an interest in that low level of computing, its a skill not often needed but understanding the concepts is often helpfull even when tackling things at much higher level languages later.

Link to comment
Share on other sites

Link to post
Share on other sites

7 minutes ago, EvilCat70 said:

I saw that page earlier and tried the code, it did not work.

And what error does the assembler spit out? Chances are you simply make a sytnax mistake. 

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

7 minutes ago, wasab said:

And what error does the assembler spit out? Chances are you simply make a sytnax mistake. 

kabHNGJcwD.png

 

Even with just copy pasting it, the code doesn't work. I added the ".386" and ".model flat, stdcall" as most tutorials I've seen have used this.

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:

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).

Link to comment
Share on other sites

Link to post
Share on other sites

19 minutes ago, Mira Yurizaki said:

 There may be some implementation differences between Intel and AMD processors, but you'll largely never encounter this for casual programming.

 

 

Why would they be different? Instruction sets for both are x86 which are the same. 

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

13 minutes ago, wasab said:

Why would they be different? Instruction sets for both are x86 which are the same. 

Processors from both may accept the same instructions, but how they behave may differ. For example, Intel 64 and AMD64, the two implementations of x86-64, behave differently in certain cases: https://en.wikipedia.org/wiki/X86-64#Differences_between_AMD64_and_Intel_64

 

ISA only defines what the opcode is supposed to do. It doesn't define how it's supposed to do it. If you want another example, NVIDIA's Project Denver is an ARMv8 compatible processor, but how it processes those instructions is vastly different from how any other ARMv8 processor would typically do it.

Link to comment
Share on other sites

Link to post
Share on other sites

Also for @EvilCat70, unless x86 is a requirement, I recommend a RISC based ISA like ARM. x86 has so much complicated crap on top of it. Like for example, the ADD instruction. You'd think it'd be pretty simple, but it has two pages of content because of all of the addressing modes and processor modes that can affect how the instruction behaves.

 

Or perhaps better yet, maybe go back to the past and try 6502 assembly with a Commodore 64 emulator.

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, Mira Yurizaki said:

Also for @EvilCat70, unless x86 is a requirement, I recommend a RISC based ISA like ARM. x86 has so much complicated crap on top of it. Like for example, the ADD instruction. You'd think it'd be pretty simple, but it has two pages of content because of all of the addressing modes and processor modes that can affect how the instruction behaves.

 

Or perhaps better yet, maybe go back to the past and try 6502 assembly with a Commodore 64 emulator.

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.

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

4 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:

 

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.

Be sure to look at the environment requirements:

 

Quote

Local Environment Setup

Assembly language is dependent upon the instruction set and the architecture of the processor. In this tutorial, we focus on Intel-32 processors like Pentium. To follow this tutorial, you will need −

  • An IBM PC or any equivalent compatible computer
  • A copy of Linux operating system
  • A copy of NASM assembler program

There are many good assembler programs, such as −

  • Microsoft Assembler (MASM)
  • Borland Turbo Assembler (TASM)
  • The GNU assembler (GAS)

We will use the NASM assembler, as it is −

  • Free. You can download it from various web sources.
  • Well documented and you will get lots of information on net.
  • Could be used on both Linux and Windows.

It looks like they've written the example assuming using Linux. You can set up said environment in a VM like VirtualBox.

Link to comment
Share on other sites

Link to post
Share on other sites

6 minutes ago, Mira Yurizaki said:

Be sure to look at the environment requirements:

 

It looks like they've written the example assuming using Linux. You can set up said environment in a VM like VirtualBox.

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

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

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

×