3 ms·
This is probably one of the few times assembly is more readable and easy to understand than C. Many years ago I used to teach OS classes at a local university,
by eduardordm 12y ago
This is probably one of the few times assembly is more readable and easy to understand than C. Many years ago I used to teach OS classes at a local university, we would build a simple bootstrap using NASM. The source code includes 32bits (a20 etc) and GDT iirc:
https://github.com/eduardordm/sisop/blob/master/sisop.asm https://github.com/eduardordm/sisop/blob/master/sisop.asm
- mvanotti 12y agoActually, I really prefer writing that in C rather than asm: You can use bitfields to define the GDT, IDT, Page Directories and so on. Doing everything is ASM is a PITA, for debugging and for readability. (I am a teaching assistant at one of these courses and hate when students do everything in asm.. but they are allowed to do as they want, as long as it works as specified).
- aosmith 12y agoWhy is debugging a pita?
- userbinator 12y agoGoing into protmode in the boot sector is extremely early. Most OSs I've seen will stay in realmode (or "unreal" mode) for a little bit longer, so they can use the BIOS to setup some more stuff before making that leap. Also noticed a minor optimisation: mov AL, [SI] ; pega um byte da string e carrega em al inc SI Could've been replaced with a 'lodsb', saving 2 bytes. Ditto for MOV BH/MOV BL with MOV BX. :-)
- mkup 12y agoCould've been replaced with a 'cld' and 'lodsb', saving 1 byte.
- drv 12y agoGoing down the size optimization rabbit hole a little bit (not criticism, I just enjoy this sort of puzzle). Two bytes shorter: call print_str ret => jmp print_str Three bytes shorter; this one may be a little too clever, since it depends on the low bit of CR0 being 0 initially: mov EAX, CR0 or EAX, 1 => mov EAX, CR0 inc AX
- aosmith 12y agoI agree... I did a similar thing here: https://github.com/aosmith/toy-os https://github.com/aosmith/toy-os The x86 code seems like a bear but once it's explained it is fairly simple.