I said you this answer because Schol-R-LEA and DavidCooper said the following answers:
manhobby wrote:
I want to learn machine code and assembly language programming as a hobby.
OK, then. Fair enough.
Now that we have that settled, which system do you mean to learn assembly (or machine code) for? Each processor family (x86, x86-64, ARM, MIPS, PowerPC, Itanium, AVR, 8051, 6502, etc.) has its own machine code and corresponding assembly language instructions, and different models within a family might not support everything that others in their family do (e.g., the current
Xeon Phi, and
Skylake-X CPUs have the
AVX-512 SIMD math instructions, but most of the other x86 CPUs don't, including the
Coffee Lake models released last fall, even though they came out a year after Skylake-X).
Also, writing assembly code that uses any kind of operating system facilities will depend on the OS it is written for, as well; an assembly program for Linux won't run on Windows, and vice versa, even when they are both running on the same hardware.
Conversely, if you intend to write for bare metal, either in the form of a self-booting PC program or something running bare on an
SBC such as a
Raspberry Pi,
Libre Renegade,
Imagination Creator Ci40,
Onion Omega2, or any of the myriad
Arduino systems (or retro-computing boards such as the
COSMAC Membership Card or the
PE6502), then you would have to write
everything yourself, and know enough about the hardware and firmware to do that
before you begin. For any sort of bare-metal programming, I would recommend using an
emulator or virtualizer when developing the program, and waiting until it works in the emulator before trying to run it on live hardware.
For some operating systems - including Windows and most Unix-like systems such as Linux or MacOS - writing machine code directly isn't really feasible at all, as the systems' program loaders will expect the program to be in a loadable
Executable Format such as ELF, PE, or Mach-O - and as complex as writing a program in raw machine code is, writing a loadable executable file in hex would be far worse. Machine code programming is really only something you would want to do on bare metal, if at all.
Finally, for assembly language, it will
depend on which assembler you are using - most of the common platforms have at least two or three different assemblers targeting them, and the syntax they accept can be very different from each other.
My recommendation is to settle on a specific hardware and software target, and development toolchain, before proceeding. You will probably want to find a book that covers those specifically, rather than trying to translate one book's information to a different system - and trust me, this is one topic you will want at least one good book on. For example, IMAO one of the best books for programming x86 assembly for Linux using the Netwide Assembler (
NASM) is Jeff Duntemann's
Assembly Language Step By Step, but it won't do you much good if you are targeting an
ODROID (which uses an ARM processor), or an x86 system that is running Windows, or even x86 Linux if you are using
GAS.
There are plenty of
online assembly language tutorials as well (such as
these ans
these), and even some for
machine code programming, but the quality of them is going to be more variable than that of the books - while terrible books can sometime slide by the editors, most online tutorials don't
have editors to fix the author's mistakes.
manhobby wrote:
Who here who would help me with that?
Hmmmn... not sure, really. While most of the assembly programmers here are going to be focused on their OS dev projects, if you post
specific questions (not general, open-ended ones like you've been doing) or ask help in debugging something you wrote, I and several others will probably give what advice we can. I couldn't promise any specific individuals other than myself.
Machine code programming, meh, not many here or anywhere else will be able to help with that, really. If you ask a specific question about a specific problem, some of us might try to help, but it would be hit or miss.
manhobby wrote:
Which are several more specialized message boards where they certainly would?
I don't know of any machine-code programming fora offhand, and I have no idea if there are any at all, but there are several for different assembly languages.
Let Me Google That For You... OK, here are a few I found. Now, most of these are specific to a particular system or assembler, but they might be a few places to try, depending on what you what to target.
Hope this helps.
manhobby wrote:
I want to learn machine code and assembly language programming as a hobby.
If you really want to work in machine code as a hobby, you'll need some kind of program to start with which will let you type your machine code numbers into memory and then run your code. You should maybe start by looking at a single-sector OS like BwtSecOS (see the tenth post in
https://forum.osdev.org/viewtopic.php?f=15&t=26339) or Selfer (
viewtopic.php?f=2&t=26446) - these are self-hosting development systems that fit in a sector and can boot a PC, modify themselves and save themselves back to disk. You could use either of those programs, or write your own single-sector OS based on the same idea, and then try to extend it to add more functionality.
You'll soon find out that to build anything of any size with it, you'll need to automate the repairs to your code whenever it's edited. When you need more space in a routine (to fix a bug or improve its functionality in any way), you have to move parts of it around to make room for the extra code, and that breaks things like jump and call distances. Any variables that are moved will also lead to the parts of code that point at them pointing at the wrong place. Without an automated system to do these repairs, you will waste most of your time fixing them manually (and frequently failing to do so correctly, resulting in crash after crash after crash). That is the main reason that assembler was invented, and it's also why you should put most of your time into learning assembler instead.
Schol-R-LEA gave you links to possible places to find help, such as the NASM forum. However, I don't know which is the best assembler for you to use. If you're working in a high-level programming language and need to use a bit of assembly for something, you need to use an assembler that integrates well with that high-level language, and that's something I have no experience of, so you need to ask other people for advice on that.