Page 1 of 1
Is writing a bootloader a good way to be introduced to asm?
Posted: Tue Mar 23, 2010 7:20 pm
by earlz
I was pondering on what the best way of learning assembler (as a novice programmer) would be. What do you think? I personally find interfacing with Windows or Linux to be troublesome at best, which really only leaves DOS development(who these days has DOS installed?) and bootsector creation. Is there some other method I'm missing? What are your opinions on it? How did you learn assembly?
Re: Is writing a bootloader a good way to be introduced to asm?
Posted: Tue Mar 23, 2010 7:51 pm
by Firestryke31
I learned assembly on the TI-83+. I learned x86 assembly writing bootsectors, and found it was in some ways more restrictive but in others I had glorious freedom. I would probably say write bootsectors since the only restrictions on format are the bootable sig at the end and a filesystem structure if you want to keep it (though for early work I wouldn't bother).
Re: Is writing a bootloader a good way to be introduced to asm?
Posted: Tue Mar 23, 2010 7:52 pm
by JackScott
Depends whether you want to learn assembly, or x86 assembly in particular. I'm not sure of the best way to go about learning the latter, but the former is easy in my opinion. The best way to learn assembly is to program microcontrollers.
Re: Is writing a bootloader a good way to be introduced to asm?
Posted: Tue Mar 23, 2010 7:59 pm
by VolTeK
i started out learning the registers, then the instructions, all in 16 bit first, then made random things out of them, how to get input, how to manipulate the input information, then learned osdevelopment in assembly, and it went from there. srry if im telling my stupid stories lol but thats how it worked for me. and plus i couldnt of done it without this forum
Re: Is writing a bootloader a good way to be introduced to asm?
Posted: Tue Mar 23, 2010 11:15 pm
by ~
It could be a good way probably only if you have some assembly experience for other platforms.
In the same way that writing a full protected mode kernel will completely limit you when you are just starting, writing a bootloader won't be the more natural way to go.
I started reading and writing some cooked code to reset the PC by jumping to something like FFFF:0 (I read it in the QUE's Upgrading and Repairing PCs, 2nd Edition, and such old books seem to be much better than the new ones, they always shared several useful things freely and one could truly learn), and some mouse code to invoke the mouse driver under DOS to use with Turbo C and BGI graphics.
-----------------------------
But it would be better if you said what you already know about assembly and what you expect being able to do or what you want to do that is practical.
Re: Is writing a bootloader a good way to be introduced to asm?
Posted: Wed Mar 24, 2010 12:45 am
by Love4Boobies
Learning assembly under x86 Linux isn't very hard. You don't need to complicate things using the C standard library, and use sys_write, sys_read and sys_exit only (via INT 80h). Focus on implementing algorithms, using jump tables and so on, and create text filters like hex converters, calculators, etc.
Re: Is writing a bootloader a good way to be introduced to asm?
Posted: Wed Mar 24, 2010 5:15 am
by Combuster
I think writing assembly for dos (via dosbox) is the easiest way to get to know x86 best - you can use system calls, you can access hardware directly, and you'll be able to practice ISRs. Writing asm under linux requires that you have a linux installation, and does not teach you what assembly is actually meant to do, but rather tends to learn you how to be your own C compiler IMO...
Re: Is writing a bootloader a good way to be introduced to asm?
Posted: Wed Mar 24, 2010 10:31 am
by Love4Boobies
Indeed but DOS is a 16-bit real mode OS and most assembly code out there is 32-bit (yes, people use assembly for things other than boot loaders sectors). The answer depends on the needs of the programmer. Then again, once s(he) has the proper mindset (i.e., understands addressing, registers and knows some instructions) it probably doesn't matter which one s(he) practiced, s(he) will be able figure things out easily on h(is/er) own.
I didn't use K&R to learn C, I knew Pascal and saw some C code. I didn't use and book on assembly, not even the Intel ones at first; I've read a crappy tutorial I found on the Internet (part of
PC-GPE, the VLA series in particular) and played around with VBE under DOS. My point is that even though the right material may speed up the learning process, people are usually smart enough to do without them. All they need in this case is the initial boost before they can jump into the Intel manuals.
Re: Is writing a bootloader a good way to be introduced to asm?
Posted: Wed Mar 24, 2010 12:53 pm
by Thomas
Hi,
An academic way of learning assembly language would be to roll your own simple vm and write an assembler for your vm.I assure you its not so hard .Good examples include
SIC ( This is the one that I used ),
MIX ,
hack
--Thomas
Re: Is writing a bootloader a good way to be introduced to asm?
Posted: Wed Mar 24, 2010 12:59 pm
by bewing
I find that the most important factor in learning any language is to have a project to use the language on, instantly. So I would definitely say that programming a bootsector in asm is an excellent way to start. Don't worry about the "limitations" of a bootsector at first. Look at a few bootsectors to see what opcodes are commonly used, look up what they do, and start coding your own.
Re: Is writing a bootloader a good way to be introduced to asm?
Posted: Wed Mar 24, 2010 8:48 pm
by earlz
Thomas wrote:Hi,
An academic way of learning assembly language would be to roll your own simple vm and write an assembler for your vm.I assure you its not so hard .Good examples include
SIC ( This is the one that I used ),
MIX ,
hack
--Thomas
Yea, this is what I did before writing Assembly.. I feel like it complicates matters too much though because you can't write a good virtual machine without understanding what a good virtual machine does..
Also, I'm considering writing a tutorial (or series of) to try to explain assembly as a first programming language, while keeping the person from losing hope. Real mode is way easy to me anyway... I mean, switch to using graphics with like 3 instructions, read from the disk with 3 instructions.. It's a very free standing environment, which makes it rather fun because there are so few standards to conform your code to. Of course.. first lesson "NEVER use `mov dl,0x80 \ int 0x10` as funny joke on your friends"
I like the idea of DOS also because it's basically like a superset of bootloader writing. You have all of BIOS, plus the DOS interrupts.. I think dosbox may be a good path to go with this in the beginning and then eventually step off to bootloader writing..
Re: Is writing a bootloader a good way to be introduced to asm?
Posted: Thu Mar 25, 2010 3:28 am
by Solar
I think any new language should first be practiced on some comparatively simple tasks in a developer-friendly environment (read, userspace).
Write a "Hello, World". Learn how to interface with other ASM modules, or how to call library functions. Practice with the various adressing modes. Write a counting loop (for), a conditional loop (while), a conditional execution (if). Learn how to handle integers and strings. Work with some primitive data structures (arrays, tables, lists). Learn about the features of your assembler (defines, macros, pragmas, whatever). Get to know the tools at your disposal (disassembler).
Only then set out to do something non-trivial.
Bottom line:
No, writing a bootloader is definitely NOT a good way to be introduced to ASM.
Spare the flames, OP asked my opinion and I gave it.
Re: Is writing a bootloader a good way to be introduced to asm?
Posted: Thu Mar 25, 2010 3:39 am
by osdnlo
Solar couldn't be more correct here. Take everything he said, place it [here] and include that I suggest that you write a simple hex editor.
Re: Is writing a bootloader a good way to be introduced to asm?
Posted: Thu Mar 25, 2010 4:55 am
by Love4Boobies
And those two posts combined are pretty much what I suggested.
EDIT: Oh damn, I said hex
converter.
Re: Is writing a bootloader a good way to be introduced to a
Posted: Fri Mar 26, 2010 11:24 pm
by ~
I have put a VGA sample in the "Samples" section of my "LowEST" project here (by now, the 7th element of the table of contents, it's a container):
http://126.sytes.net/projects/x86/OS/LowEST/index.html
In that example, you can see how to use that set of DOS.COM programs to fill the screen in the default 640x480 16-color VGA graphics mode from a .BAT script.
It also contains assembly source equivalent so that you can compare and better understand what each step means and does.
I will try to eventually put several useful examples to document the most basic PC features being programmed with assembly, and doing the programming independent from DOS, using it like nothing more as a shell and using it for "irrelevant" parts of programming.
It always help me catch errors like specifying wrong addresses as soon as I execute them in the step-by-step process, which reduces the effort needed to make a functional snippet.