Post AS7o23lHX2SZe08evI by srevinsaju@mstdn.io
 (DIR) More posts by srevinsaju@mstdn.io
 (DIR) Post #ARQi6QYMugSx45TUrA by srevinsaju@mstdn.io
       2023-01-08T09:18:45Z
       
       1 likes, 1 repeats
       
       So it suddenly occurs to me that I have a pending #assignment on by Operating Systems course. The assignment seems to be trivial: it is to create a bootloader which prints 'Hello World' on the console. Thought it would be interesting to understand this with some help from my mastodon folks 😄 #university #operatingsystems #bootloader #nasm #assembly PS: future me, if you happen to be reading this post after you have forgotten about this, you can thank me later.
       
 (DIR) Post #ARQi6SFIcYOuJWZIPY by srevinsaju@mstdn.io
       2023-01-08T09:21:07Z
       
       0 likes, 0 repeats
       
       So looking at what has been provided to me, I have this in the material:#assembly #bootloader #university
       
 (DIR) Post #ARQi6U085vSFl3UD2m by srevinsaju@mstdn.io
       2023-01-08T09:30:37Z
       
       0 likes, 0 repeats
       
       Here is the code after a bit of good formatting(?) but at least its more readable. I have a lot of questions, but we will go through it line by line.#assembly #bootloader #university
       
 (DIR) Post #ARQi6Vbk7Z8Uk05lJI by srevinsaju@mstdn.io
       2023-01-08T09:33:05Z
       
       0 likes, 0 repeats
       
       Meanwhile, a question, I see `PrintCharacter` which seems to be called a 'procedure' in #assembly  (I wrote function call 🤦‍♂️), but does Assembly have any good style guidelines? For example, preference of snake_case over CameCase, or something like that? and what about indentation? cc @codewiz
       
 (DIR) Post #ARQi6VfHuNyIuzkaps by srevinsaju@mstdn.io
       2023-01-08T09:53:29Z
       
       0 likes, 0 repeats
       
       Re: [BITS 16], the most reasonable explanation I could find was that, when Intel introduced 32-bit CPU, it wanted to maintain backward compatibility with its older 16-bit bootloaders. So it made, the 32-bit mode of processing as a protected on-demand mode. Due to this convention, CPU's start processing the code in 16 bit mode, which then can transfer to 32 bits or 64 bits.
       
 (DIR) Post #AS7nCQz5weWybsyzXk by codewiz@mstdn.io
       2023-01-29T04:55:46Z
       
       0 likes, 0 repeats
       
       @srevinsaju I called them routines, or sometimes subroutines. Procedure is jargon from early procedural languages, such as Pascal.
       
 (DIR) Post #AS7nWjWaiqo3u4KVPM by codewiz@mstdn.io
       2023-01-29T04:59:28Z
       
       0 likes, 0 repeats
       
       @srevinsaju Which assembler are you using? I've never seen square brackets for assembler.dorextives. The traditional UNIX as as.wellcas gas uses . to introduce directives: https://ftp.gnu.org/old-gnu/Manuals/gas-2.9.1/html_chapter/as_7.html
       
 (DIR) Post #AS7o20OU3LRPCQRuTI by srevinsaju@mstdn.io
       2023-01-08T10:12:17Z
       
       0 likes, 0 repeats
       
       Meanwhile [ORG 0x7c00] also seems to be born out of convention. The BIOS loads the program to the RAM at 0000:7C00 before your program gets a chance to be executed. We _could_ ignore the ORG (aka origin), but your program will assume that its loaded at 0x0000 instead. (But you could choose to add 0x7c00 on every command if you would like to do the hardway).
       
 (DIR) Post #AS7o20sGGdGCgmNgsy by srevinsaju@mstdn.io
       2023-01-08T10:16:08Z
       
       0 likes, 0 repeats
       
       I had been looking at what `MOV AH, 0x0E` means and I found this https://forum.osdev.org/viewtopic.php?f=13&t=31031, a 13 year old had been trying to make a bootloader. wow I feel so old.
       
 (DIR) Post #AS7o21UBzbbMaQ7z0a by srevinsaju@mstdn.io
       2023-01-08T10:41:26Z
       
       0 likes, 0 repeats
       
       And I guess I am done, (at least with printing the character 'A').#bootloader #boot #assembly
       
 (DIR) Post #AS7o222Dx4p8Hy3A3M by srevinsaju@mstdn.io
       2023-01-08T10:47:13Z
       
       0 likes, 0 repeats
       
       For our #assignment, we _have_ to use #VirtualBox to run them, and create screenshots of the output of the same.
       
 (DIR) Post #AS7o22hLUBiWLVI09I by srevinsaju@mstdn.io
       2023-01-08T10:48:14Z
       
       0 likes, 0 repeats
       
       Looks like we have to choose "Floppy" storage type and choose the boot.img which we created earlier.
       
 (DIR) Post #AS7o238Hs1Gfh3tW8u by srevinsaju@mstdn.io
       2023-01-08T10:53:14Z
       
       0 likes, 0 repeats
       
       Looks okay.#bootloader #assembly #university
       
 (DIR) Post #AS7o23lHX2SZe08evI by srevinsaju@mstdn.io
       2023-01-08T12:49:40Z
       
       0 likes, 0 repeats
       
       After several hours of debugging and a hundred open tabs, I present: Hello World in a Bootloader.
       
 (DIR) Post #AS7o24VikNbfy1rkJ6 by codewiz@mstdn.io
       2023-01-29T05:05:07Z
       
       0 likes, 0 repeats
       
       @srevinsaju Now you can read the source code of LILO, a PC MBR boooader that was used by Linux distros for several years before GRUB took over:https://github.com/iamroot-x86-10/lilo-21.4.4/blob/master/first.S
       
 (DIR) Post #AS7o25cUcgcNPK2fVA by srevinsaju@mstdn.io
       2023-01-08T12:50:51Z
       
       0 likes, 0 repeats
       
       I wonder if I can submit this #mastodon thread as the assignment to my professor.#uni #university #assembly #operatingsystems #bootloader #assignment
       
 (DIR) Post #AS8wgf7j29b5tYT5WK by srevinsaju@mstdn.io
       2023-01-29T18:16:39Z
       
       0 likes, 0 repeats
       
       @codewiz I am using the nasm assembler, it was the one specified in our university study material.
       
 (DIR) Post #AS8wnhTmfoJ1EE8rR2 by srevinsaju@mstdn.io
       2023-01-29T18:17:51Z
       
       0 likes, 0 repeats
       
       @codewiz Ah names are really confusing, most of my professors and books refers to them as “procedures” :/
       
 (DIR) Post #AS96gHpGeYXfBEIIro by codewiz@mstdn.io
       2023-01-29T20:08:36Z
       
       0 likes, 0 repeats
       
       @srevinsaju Looks like it's still actively developed:https://github.com/netwide-assembler/nasmI never used nasm because it came from the DOS/Windows world and uses the Intel syntax (as opposed to the AT&T syntax, which is standard in UNIX/Linux toolchains).#assembly #programming #retrocomputing
       
 (DIR) Post #AS97kdWk0iBnb7Gb9k by codewiz@mstdn.io
       2023-01-29T20:20:06Z
       
       0 likes, 0 repeats
       
       @srevinsaju Here's some Motorola 68000 #asm I wrote long ago for the #Amiga:https://www.codewiz.org/projects/amiga/XModule/XModuleSrc/Startup.asmHow does it look compared to 8086 asm?
       
 (DIR) Post #AS98C0hNy021HYIYqm by codewiz@mstdn.io
       2023-01-29T20:25:34Z
       
       0 likes, 0 repeats
       
       This is part my first open source project, a GUI tracker and module format converter.I never managed to finish it, and now it seems silly to spend time rewriting the entire C startup code in assembly, when it's not at all performance critical.But that's how kids learn!@srevinsaju #programming #asm
       
 (DIR) Post #AS99i5FkfYnGczEM6K by codewiz@mstdn.io
       2023-01-29T20:42:25Z
       
       0 likes, 0 repeats
       
       @srevinsaju Ok, there's no official naming convention, but this is how early programming languages progressed:ROUTINE: a block of instructions that accomplishes a task. You can JMP to it and it doesn't necessarily return (e.g.: "the init routine jumps to the loader routine, which jumps to the main screen routine...")
       
 (DIR) Post #AS99y1Z49PINozrjNI by codewiz@mstdn.io
       2023-01-29T20:45:25Z
       
       0 likes, 0 repeats
       
       SUBROUTINE: a routine designed to be called from multiple locations and return to the caller.Late 1970s CPU designs supported this programming model by adding a stack pointer register (SP) and dedicated opcode pairs like JSR/RTS (m68k) and CALL/RET (x86).@srevinsaju #programming #asm
       
 (DIR) Post #AS9BwzhVnK6BeyS812 by CGM@mastodon.scot
       2023-01-29T21:05:02Z
       
       0 likes, 0 repeats
       
       @codewiz @srevinsaju - and the same logic also lead to COROUTINE - where rather than having a main routine which called subordinate routines, multiple routines would cooperate by passing control from one to another at appropriate points.  Of course this does not map onto a simple stack call/return model and so was much less commonly implemented. #programming
       
 (DIR) Post #AS9BzThVE7azHXdINk by codewiz@mstdn.io
       2023-01-29T21:08:10Z
       
       0 likes, 0 repeats
       
       PROCEDURE: ALGOL 60, the precursor of all modern procedural languages, including C, introduced the concept of passing arguments to subroutines. Argument passing used the awkward "call-by-name", but the VALUE keyword let you override it. There were no pointers and no references yet.Modern calling conventions pass the first N arguments in registers, and push the rest on the stack. This is what you'd use in your 8086 asm.@srevinsaju #programming #asm #retrocomputing
       
 (DIR) Post #AS9ENhbvMRfdHVhbZw by codewiz@mstdn.io
       2023-01-29T21:34:21Z
       
       0 likes, 0 repeats
       
       FUNCTION: Lisp was ahead of its time, with first-class functions in the '60s.My first encounter with functions was in BASIC. The Commodore dialect had built-in functions such as SIN(X), and supported a limited form of user-defined functions with a single argument and a one-line expression:DEF FN TRIPLE(X) = X*3Calls could nest:PRINT FN TRIPLE(FN TRIPLE(5) + 1)@srevinsaju #programming #retrocomputing
       
 (DIR) Post #AS9F7Ow57s76gPvCoi by codewiz@mstdn.io
       2023-01-29T21:43:15Z
       
       0 likes, 0 repeats
       
       Pascal had an explicit distinction: functions are procedures which return a result.K&R C didn't bother with procedures: everything is a function, and if you omit return at the end, it will return garbage to the caller 😂Later, ANSI C added the "void" type and (optional) function prototypes, making this footgun somewhat less dangerous.Support for declaring and defining functions without a full prototype will be finally removed in C23:https://en.cppreference.com/w/c/23@srevinsaju #programming
       
 (DIR) Post #AS9JjePSRVZJUl9l0S by alrj@hostux.social
       2023-01-29T21:10:37Z
       
       0 likes, 0 repeats
       
       @srevinsaju @codewiz A few languages, most notably #Pascal, used to make a distinction between functions, that return a value, and procedures, that do not.
       
 (DIR) Post #AS9Jjf1k9AC3PV4KgK by codewiz@mstdn.io
       2023-01-29T22:34:37Z
       
       0 likes, 0 repeats
       
       @alrj You beat me on time, but see the rest of my monologue 🙂I was forced to use Turbo Pascal in high school. I complained that it was an obsolete language, but my teacher insisted that it was good for me so I wouldn't learn bad habits from C... like early return, break, continue...In formal circles, those constructs were accused of being "non-structured" control flow, so my teacher would argue that adding flags to abort loops was better style 🤦‍♂️@srevinsaju #programming