6 ms·
Let’s Learn x86-64 Assembly: Part 0 – Setup and First Steps
- sushshshsh 6y agoA mid 90s object oriented textbook somewhere is screaming at me, "pidgeon-hole computing is dead and unappealing unless you are a pidgeon or a mailman! Don't treat computers like a list of robots and mailboxes, don't focus on the hows of computing, focus on the whys!"
- 0xdeadbeefbabe 6y agoContradiction by game https://github.com/nanochess/fbird https://github.com/nanochess/fbird. Take that 90s textbook.
- beagle3 6y ago> Additionally, the higher 8 bits of rax, rbx, rcx and rdx can be referred to as ah, bh, ch and dh. That’s bits 8-15 (lowest being 0 and highest being 63), not the highest 8 bits Didn’t have time to read the whole thing, but it looks nice.
- matzab 6y agoIt does say 'higher' not 'highest'.
- unnouinceput 6y agoIt's still not clear to a first time reader. Here is a better visualization, as much as HN let me do it, for RAX (same applies for RBX, RCX and RDX): |63|62|61|60|...|34|33|32|31|30|29|...|18|17|16|15|14|...|10|09|08|07|06|05|04|03|02|01|00| |.............................................|.............................|<-- AH (8 bits) --->|<------- AL (8 bits) -------->| |.............................................|.............................|<------------- AX (16 bits - lower part) --------->| |.............................................|<---------------------------- EAX (32 bits - lower part) ------.---------->| |<------------------------------------------------ RAX (full register - 64 bits) --------------------------.------>| (10 thousands edits, hope you guys see the same as I see, perfectly aligned)
- Stratoscope 6y agoNice illustration, thanks. Regarding the formatting, for a chart like this you will find it easier if you switch to a monospaced font. You can do that with two spaces at the beginning of each line, and you won't need the blank lines either. Here is a start: |63|62|...|33|32|31|30|...|17|16|15|14|...|09|08|07|06|...|01|00| |...............|...............|<-AH (8 bits)->|<-AL (8 bits)->| |...............|...............|<-AX (16 bits - lower part) -->| |...............|<--------- EAX (32 bits - lower part) -------->| |<--------------- RAX (full register - 64 bits) --------------->| (This still won't look good on a mobile device because of the width, best viewed in a desktop browser.)
- tzot 6y agoAnd that is why I'd prefer if the quoted text was: > Additionally, the higher 8 bits of ax, bx, cx and dx can be referred to as ah, bh, ch and dh. So either “higher” or “high” would work.
- vorticalbox 6y agoWhen we were learning this in my degree we used little man computer[1] to help visualise whats going on. 1. https://littlemancomputer.co.uk/ https://littlemancomputer.co.uk/
- atkbrah 6y agoWe used titokone [1]. The newest version of it even has some graphics support in it (although it's super slow). 1. https://www.cs.helsinki.fi/group/titokone/v1.100/kayttoohje/manual.html https://www.cs.helsinki.fi/group/titokone/v1.100/kayttoohje/...
- lastgeniusua 6y agoWe are working on our own (in Python, so it's not super fast) hardware simulator, check it out if you are interested: http://assemblysimulator.pythonanywhere.com/ http://assemblysimulator.pythonanywhere.com/
- tempodox 6y agoCompletely off topic, but I just have to say it: This is one of the few light-text-on-dark-background web pages that actually does it well. Contrast is managed so the text is still readable without escaping to Reader View or wearing sunglasses. I wish those sites that use squeaky-white on pitch-black would take example of this.
- zeepzeep 6y agoI can recommend the game Human Resource Machine
- jnwatson 6y agoYes, that was like assembly for dummies. Still, I don't think it really exploited its concept well enough. It was not remotely challenging to someone with a software background.
- simias 6y agoIt's very common for people to learn assembly using x86(-64) but this ISA is so messy, complicated and layered that it always seems like the bad choice to me. It's like teaching an intro programming course using C++, I understand why it's practical but it seems like it will be more trouble than it's worth. I'd probably recommend getting some ARM or ARM64 board and starting with this, most of the concepts will carry over to other assemblies anyway. Writing a simple CPU emulator for some simple architecture and then coding on it can also be a great teaching experience, if a little more involved. I find this tutorial a bit oddly structured too, but that may be because I'm from un*x world and I don't have the Windows mindset. It basically goes from "int3 ret" to "The PE Format and DLL Imports". That seems like quite the jump, and not necessarily super relevant to learning ASM IMO.
- Craighead 6y agoWhy is c++ not the best intro to programming language?
- simias 6y agoIt's too complicated IMO. The surface to cover is absolutely huge. Teaching complete novices to program is complicated enough, explaining the difference between char * and std::string and how a char is not really a char if you deal with unicode and OOP and destructors and exceptions and virtual calls and global constructors and RAII and templates and overloading and... I think it would make more sense to start with a simpler language and work your way to C++ if that's what you want.
- Darvon 6y agoDepends if your goal is to teach the maximum number of people the fundamentals of logic, or to transfer as much practical knowledge as quick as possible to the students with an aptitude for programming.
- josteink 6y ago> It's very common for people to learn assembly using x86(-64) but this ISA is so messy, complicated and layered that it always seems like the bad choice to me. Agreed. As someone who did lots of assembly for the 6502 and the whole Motorola 68k series CPUs while on Mac & Commodore-machines, I thought I might as well learn x86 assembly when I moved to "regular" PCs. After a week or so of en-bafflement, I just decided that dealing with assembly on any sort of regular basis was not something I was interested in doing on the Intel-platform. It was inferior to competing platforms in almost every conceivable way back then (except performance) and it haven't improved since. It's just utterly terrible and the only reason it's still around is backwards compatibility. Nobody would design anything like this today.
- lastgeniusua 6y agoHuge thanks! Was recently implementing an assembly language of my own, and this read seems to capture all of the important things that were otherwise hidden in ten different outdated books, specifications and websites.
- mlang23 6y agoI recently took up the challenge of porting JonesForth to x86-64. It was one of the most rewarding personal challenges in a very long time. For one, I was able to write x86-64 without needing to whip up a complete application. And learning Forth during the process was even more fun. https://github.com/mlang/jonesforth https://github.com/mlang/jonesforth And yes, I know there is also jonesforth64. However, doing the porting myself was totally worth it.
- MaxBarraclough 6y agoAnd in the true Forth spirit, the point was to implement Forth, not to implement something in Forth.
- mlang23 6y agoAlmost right. At the end of the exercise, I at least wrote TIME&DATE, a word to get the current system time. And I implemented DO..LOOP which appeared to be quite tricky. But yes, I agree. Getting the system to run was much more interesting then actually using it :-)
- deleted 6y ago[deleted]
- 0xdeadbeefbabe 6y agoDid you run into memory protection?
- mlang23 6y agoNo. Jonesforth is originally written for i386 Linux. Porting to x86-64 didn't really change a lot about the environment.
- ed_blackburn 6y agoAround 2000 we did this in the first week of university along side C. The number of people who changed courses to more analysis or business focused degrees was high. Of course it was deliberate. We barely touched Assembly again unless you opted into specific classes.
- melvinroest 6y agoWhen I was in my masters I never programmed in C and barely assembly assembly as I was in a Java/Python/JS school. Nevertheless, I found it doable to learn them both at the same time. How? GDB Combined with the TUI window and typing: * layout asm * layout regs * focus cmd And then ni and si were my favorite "step into instruction" and "next instruction" commands. And for C the same thing but then simply with layout src and sometimes layout asm and layout regs as well.
- non-entity 6y agoMaybe I'm just dumb, but anytime I've tried to learn anything about modern x86 platforms I just end up completely lost. I find it interesting the author uses FASM, and I've seen it used a bit more than I did in the past. Several years ago I toyed with it and found it neat because the editor and all the samples it shipped with. It did seems a bit different from things like nasm or gas as it the FASM code I saw used all sorts of interesting macros that provided quasi-high-level constructs like if statements.
- Wohlf 6y agoIt's not just you, modern x86 is very complicated. There are likely few if any people who deeply understands all of it.
- dtornabene 6y agoI feel like there should be a text that teaches assembly, not assumes it, but teaches it specifically with an eye toward shellcode and/or reversing. Every "learn assembly" text I've ever seen either teaches it in relation to C or architecture or simply by itself. Seems like a gap that could be filled by nostarch or someone willing to self publish
- im3w1l 6y agoWrite position independent code. This is much easier nowadays that you can use RIP relative addressing. To include data, just append it to your code or even put it inline with jmps to avoid executing it. To accomplish tasks use syscalls. If you want a library, load it dynamically with dlsym. Also take a look at https://en.wikipedia.org/wiki/Return-oriented_programming https://en.wikipedia.org/wiki/Return-oriented_programming