Is writing a bootloader a good way to be introduced to asm?

Programming, for all ages and all languages.
Post Reply
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Is writing a bootloader a good way to be introduced to asm?

Post 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?
User avatar
Firestryke31
Member
Member
Posts: 550
Joined: Sat Nov 29, 2008 1:07 pm
Location: Throw a dart at central Texas
Contact:

Re: Is writing a bootloader a good way to be introduced to asm?

Post 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).
Owner of Fawkes Software.
Wierd Al wrote: You think your Commodore 64 is really neato,
What kind of chip you got in there, a Dorito?
User avatar
JackScott
Member
Member
Posts: 1031
Joined: Thu Dec 21, 2006 3:03 am
Location: Hobart, Australia
Contact:

Re: Is writing a bootloader a good way to be introduced to asm?

Post 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.
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: Is writing a bootloader a good way to be introduced to asm?

Post 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
User avatar
~
Member
Member
Posts: 1226
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Re: Is writing a bootloader a good way to be introduced to asm?

Post 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.
YouTube:
http://youtube.com/@AltComp126

My x86 emulator/kernel project and software tools/documentation:
http://master.dl.sourceforge.net/projec ... 7z?viasf=1
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Is writing a bootloader a good way to be introduced to asm?

Post 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.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Is writing a bootloader a good way to be introduced to asm?

Post 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...
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Is writing a bootloader a good way to be introduced to asm?

Post 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.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Thomas
Member
Member
Posts: 281
Joined: Thu Jun 04, 2009 11:12 pm

Re: Is writing a bootloader a good way to be introduced to asm?

Post 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
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: Is writing a bootloader a good way to be introduced to asm?

Post 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.
earlz
Member
Member
Posts: 1546
Joined: Thu Jul 07, 2005 11:00 pm
Contact:

Re: Is writing a bootloader a good way to be introduced to asm?

Post 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..
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: Is writing a bootloader a good way to be introduced to asm?

Post 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.
Every good solution is obvious once you've found it.
User avatar
osdnlo
Member
Member
Posts: 136
Joined: Thu Feb 25, 2010 5:39 pm

Re: Is writing a bootloader a good way to be introduced to asm?

Post 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.
Yes, I see that you have proven it, but my question was, 'How did you know that would work?'.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: Is writing a bootloader a good way to be introduced to asm?

Post by Love4Boobies »

And those two posts combined are pretty much what I suggested. :)

EDIT: Oh damn, I said hex converter.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
~
Member
Member
Posts: 1226
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Re: Is writing a bootloader a good way to be introduced to a

Post 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.
YouTube:
http://youtube.com/@AltComp126

My x86 emulator/kernel project and software tools/documentation:
http://master.dl.sourceforge.net/projec ... 7z?viasf=1
Post Reply