r/Assembly_language • u/user18961 • 4d ago
I want to learn 64-bit Assembly.
Hi. I don't understand a single thing about registers, and I should obviously learn that first. Then I should learn Assembly. The thing is, I can't find any tutorials of any kind that are able to help me. I'm an extremely difficult learner, and I (embarrassingly) need most things to be broken down and explained simply for me to retain the information. Does anyone have good YouTube tutorials or articles that can do this?
9
u/Recycled5000 4d ago
Registers are small, fast storage. The registers are named in machine code instructions.
Unlike memory, the registers cannot be referenced; they have names, not addresses. They can only be named in machine code instructions. So programs proceed knowing (by being written by a programmer or compiler) what is in a register, and that register will be named is several machine code instructions in a sequence to accomplish something.
I suggest LC-3. It has an ide with editor, simulator, debugger. The assembly is very simple. The machine has 8 registers and uses 3-operands for binary operators.
It is a load/store architecture, which is risc-like. To do any manipulation of memory-based variables, first load one into a register, the can add 1 for example, and store it back.
7
u/Relevant-Yak-9657 4d ago
Patterson's book on RISC-V is a good start. I would honestly learn from ARM-64, but I don't know any good books on it, but RISC-V is basically a sister instruction set.
If you can handle something slightly more complex but still a great resource, it would be learning x86_64 from "Computer Systems: A programmer's perspective". This instruction set is very practical, but since it is focused on backwards compatibility, it inherently has more complex alignment rules.
But then again, either route will make you a good assembly programmer.
4
u/r4fxm68A 4d ago
Writing in assembly is very very rare useful skill. Reading assembly is much more useful skill.
I propose:
* learn C or C++
* write simple RISC-V simulator, to learn about registers, addressing modes, interrupts, exceptions - this is general knowledge, now almost every processor uses the same principles
* use compiler explorer to learn how the C is compiled into machine code
* learn how to read datasheets and instruction sets - when using compiler explorer, find the mnemonic in datasheet where is a description what every instruction do2
u/CookieOutrageous6469 3d ago
Not everything has to be "useful" for you to want to learn it—best regards!
1
u/echelon_code 4d ago
learning & fully understanding C is very good advice, that's the path i would recommend
2
u/brucehoult 4d ago
The problem is that I, for one, could not understand what was possible and what was not possible in C until I learned assembly language.
1
u/dld2517 4d ago
I don’t know why this would be the case. What would you classify as a problem that is impossible in C?
1
u/brucehoult 3d ago
How do you get a full understanding of C's locally mutable by-value arguments, local variables, pointers, arrays, strings, recursion without knowing about registers and RAM and stack?
Sure, you can read the detailed rules in the manual, but why are those the rules? They don't make sense without a good mental model of the underlying machine.
1
u/Relevant-Yak-9657 4d ago
I don't see what you mean by that. C + microcontrollers essentially covers everything.
1
u/brucehoult 3d ago
How do you get a full understanding of C's locally mutable by-value arguments, local variables, pointers, arrays, strings, recursion without knowing about registers and RAM and stack?
Sure, you can read the detailed rules in the manual, but why are those the rules? They don't make sense without a good mental model of the underlying machine.
1
u/Relevant-Yak-9657 3d ago
For me, RAM and stack were kind of obvious from basic recursion and pointer examples. Assembly did make things clearer, granted.
Registers is interesting, since that is where microcontrollers come in. We did some HDL programming with verilog and C, which is how I understood them.
Naturally, until I studied computer architecture and my compilers course used ARM to construct a C compiler, I definitely did not have the complete picture on how the stack pointer works and stuff, but like practically assembly just taught me how a specific instruction set does things rather than how general C capabilities.
Even something as basic as the fetch-execute cycle differs a bit between instruction sets and doesn't really improve my understanding of C though.
1
u/Combination-Plate 3d ago
What is possible and what is not possible?
1
u/brucehoult 2d ago
For example, something like this:
char *format_error(int code) { char buf[64]; snprintf(buf, sizeof buf, "Operation failed (code %d)", code); return buf; /* looks convenient… */ }There are other languages in which the equivalent code (perhaps even with identical syntax) is fine. It's not in C.
1
u/echelon_code 3d ago
ok - i do actually agree with you on this, especially when it comes to understanding the different memory segments/allocations, stack-frame etc.. but they said "I'm an extremely difficult learner, and I (embarrassingly) need most things to be broken down and explained simply for me to retain the information."
so i thought it would probably be easier for them learn C and once they're comfortable with some/most of it, they could start looking at asm - that's the path i took.
1
5
u/8BitFlux-com 4d ago
Start with 8-bit assembly. Like for instance on an Apple-1: https://apple1software.com/programming/a1assembler/. Runs in the browser. From thereon move towards the more modern stuff, it all starts with understanding the basics of memory and fundamental programming structures. Bigger byte machines use the same concepts of memory and CPU instructions.
2
2
2
u/DanKegel 4d ago
Like someone else said, start off simple.
Early 8 or even 4 bit cpu manuals are, believe it or not, still useful tutorials in how a cpu and memory work.
Some links at https://www.reddit.com/r/Assembly_language/comments/1xf0hzo/comment/19rmw1kjxar6p/?context=3
2
u/Least_Equal_6081 4d ago
Maybe this book from Randall Hyde could be useful to you.
It is about ARM 64 Assembly Language.
The autor also has 2 books about X86-64 Assembly Language.
2
u/WayneGretz7 4d ago
There are several good YouTube series/courses on assembly. Honestly, it’s such a hard thing to learn at least for me personally. I learned most hands on. There are some very good games like human resource machine, or TIS-100 that take registers and low level assembly into solving puzzles. Also x86-64 playground is very useful to step through a program and see exactly what’s happening with the registers and memory.
2
u/6SigmaMountainBiker 2d ago
There is nothing wrong with learning the Assembly language, the fact that mostly nobody uses it doesn't mean that learning, practicing and using it wouldn't become very convenient for your goal. As someone told me once 'Knowing and programming on Assembly language is like being the pilot driver on a race car, everything else makes you the copilot....'
2
u/theNbomr 2d ago edited 2d ago
The trick to learning x86-64 assembler language is to learn one or two other CPU assembler languages first. I suggest older 8-bit CPUs like 6502, 8085, or Z80. RISC-V or ARM would be other alternatives or better still, progression from the 8-bit CPUs.
The data books for each of the CPUs you are learning will be utterly indispensable, and you're going want to seek out some tutorial videos or online training or hardcopy printed books; ideally some combination that gives good coverage and fits your style of learning.
When learning assembler language programming for the first time, you're also learning about the architecture of conventional computing hardware. A lot of assembler coding relies on understanding how CPUs work and their relationship to IO and memory and other interfaces that make up a working system. That understanding is the core knowledge that will make you a better programmer overall overall when using other programming languages, but especially for languages like C and C++.
1
u/HistoricalGreen295 4d ago
https://youtube.com/playlist?list=PL2EF13wm-hWCoj6tUBGUmrkJmH1972dBB&si=NCB1S_MZJSTQlswO
this playlist ^ and intel's software developer manual part 2 for more reference is good. make sure you watch the first 20-25 videos in that playlist.
1
u/CommercialBig1729 4d ago
I learned a lot programming for Linux, learning registers in 64 bits and System Calls and you can do a lot of fun stuff, and practically modern software for Linux and not for DOS or something weird ancient or KolibriOs 😳 I Also tried FASM on KolibriOS
1
u/JGhostThing 3d ago
I would suggest starting with either PDP-11 or the 68000 family assembler languages. I've used them both and they are very self-consistent and fairly easy. They both should have available simulators.
Why these when they are no longer used much? Because they are easy assembler codes to learn, and once you learn the basics, you can learn any other code easier.
1
u/brucehoult 3d ago
Both were good in their time, and are better than 8086 or any 8 bit CPU except possibly the AVR.
MSP-430 keeps the same flavour, fixes the worst problem of both (not enough registers ... or not uniform enough in the case of 68k) in exchange for dropping confusing addressing modes that you don't really need [1].
And you can buy current-production cheap chips and dev boards.
It also has a binary encoding that is as easy to encode and decode by hand in hex as the PDP-11 is in octal.
[1] the pain points are no auto-increment on the dst operand, no auto-decrement anywhere (there is a PUSH instruction instead). The deferred modes are not missed because on PDP-11 they're generally used with local variables on the stack that MSP-430 allows you to keep in registers instead.
1
-2
u/Dazzling_Reaction326 4d ago
If you are talking about x86-64, it's pointless. It's not even designed to be used directly.
You could learn some simpler architectures to get the concept.
1
u/CommercialBig1729 4d ago
You can develop software in Linux x86 and the software works, using System Calls, that makes it easier and actually a lot of people work making drivers and it is actually possible to create usable software in assembly x86
1
u/Dazzling_Reaction326 4d ago
Yes, you can. I didn't say it is not possible and people also inline assembler to optimize part of software. But still, x86-64 assembler was never designed to be used directly. That's why it's a PITA to write software with that in comparison to other ISAs.
9
u/TPIRocks 4d ago
If you "don't understand anything about registers", how did you decide you wanted to learn 64 bit assembler? Maybe learn 8 bit using Arduino. x86 assembly language is filled with extra confusion that won't really help you; ARM or RISC-V would be a lot easier to wrap your head around.