I got an old laptop for free and I'm going to use it for some experiments... I'm trying to learn Assembly language from "Assembly language step by step", 3rd edition, on Linux, and it's a really fascinating topic, but I also have a printed version of the 2nd edition of that book, which focuses on DOS programming and real mode segmented model, so I thought I could install FreeDOS on a partition and begin to play a little... I know it's not easy and it's quite archaic for today's programming, but I wonder, is it really completely useless? If I wanted to try to write a bootloader for example (not now, when I'm more experienced) the CPU starts in real mode, doesn't it? And what about embedded programming? Apart from "practical" reasons, can learning segmented model first make me a better programmer in the long term? Thanks :)
Asked
Active
Viewed 132 times
2
-
I would say this will be closed quite quickly as opinion based. It will make you "a better programmer" in the way that you know more. But it won't give you anything especially useful in the long run. And yes, x86 CPUs start in real mode. – Sami Kuhmonen Feb 24 '16 at 09:30
-
What's there to learn? It's just one of the memory models. Having basic knowledge about them is useful, but only in the very long-term, and only because the systems with weird memory models keep occasionally popping up. The more useful piece of knowledge is the answer to the question "why this particular weird memory model exists at all". But that you have to learn yourself. – Dummy00001 Feb 24 '16 at 09:30
-
Learning "normal" asm that runs as part of a 64 or 32bit process under a normal OS like Linux or Windows is a lot simpler than writing your own standalone program that talks to the hardware. Learn the basics of ASM before you try to learn the warts of 16bit mode, and/or BIOS APIs for a bootloader. Learning DOS system calls is useless, because nobody wants new DOS programs. The [x86 tag wiki](http://stackoverflow.com/tags/x86/info) has some links about this, esp my [suggestions for learning asm](http://stackoverflow.com/a/34918617/224132) where I expand on how much 16bit sucks. – Peter Cordes Feb 24 '16 at 10:28
-
I just noticed that you said you're using Linux. It's quite simple to make system calls directly in Linux (set up args in regs, `mov eax, __NR_write` / `syscall` or `int 0x80`). Windows is more complex; I think everyone suggests `call`ing the DLL functions that wrap the actual system calls, so it doesn't feel like you're really writing lean and mean programs. Anyway, better programmer? Learning segments *first* is not going to make you better. They're basically vestigial in 64bit mode, and only used for thread-local storage in modern OSes. – Peter Cordes Feb 24 '16 at 10:37
-
You'll have your hands full just writing simple functions that do something to their inputs and return a value when you call them from C. Segments are just an unnecessary complication, along with a lot of 16bit limitations and crap that you don't have to learn until you want to try your hand at writing a bootloader or something. (I've never done that; I find it much more interesting to optimize asm to run fast than to reinvent the wheel with a bootloader or homebrew OS. I often report gcc bugs when it's a lot worse than what I could write by hand.) – Peter Cordes Feb 24 '16 at 10:43
-
Realmode segmentation is not fundamentally difficult (or even interesting, imo), it's just a pain to mentally juggle all those segments. – harold Feb 24 '16 at 11:14
-
1Understanding assembly code never hurts. If you are trouble-shooting a perf problem with a program then only studying and understanding the machine code can get you to the bottom of the issue. Focusing on the intricacies of 16-bit x86, no, that's pretty much a waste of time. You may have to, just because the book or tutorial does, just don't pay too much attention to it. – Hans Passant Feb 24 '16 at 12:04
-
One benefit to using FreeDOS to learn assembly is you can use DEBUG and type in a single instruction or a few instructions and immediately execute them step-by-step to see what they do. You'll be looking at real mode variants of instructions but they'll work fundamentally the same way as their 32/64 bit brethern. Better still run Linux on your laptop, and put FreeDOS in a VM (using QEMU or other hypervisor). – Χpẘ Feb 25 '16 at 08:41