Live data from Hacker News

I want to compile a C program so simple I can explain all of the assembly

blog.ksplice.com

11–20 of 39 posts

Re: I want to compile a C program so simple I can explain all of the assembly

#12
If you really want to write code that you can understand all the way down I suggest starting from as close to bare metal as your level of masochism allows. For me, that's GRUB.

This tutorial walks you through making a kernel image that GRUB can load, and shows how to poke bytes into video memory to print characters to the screen:

http://wiki.osdev.org/Bare_bones

Re: I want to compile a C program so simple I can explain all of the assembly

#13

If you really want to write code that you can understand all the way down I suggest starting from as close to bare metal as your level of masochism allows. For me, that's GRUB. This tutorial walks you through making a kernel image that GRUB can load, and shows how to poke bytes into video memory to print characters to the screen: http://wiki.osdev.org/Bare_bones

And then buy an FPGA and bust out some Verilog and write the metal yourself.

Re: I want to compile a C program so simple I can explain all of the assembly

#15
post #5

That was a really cool article, anyone with more knowledge on the subject want to comment on how sound the author's thought process is? Thanks.

The article is quite sound and doing all this is standard practice in the embedded world where you can't afford the size of glibc. The article is a bit incomplete, but presumably he'll address the rest in his next installment. As a preview, to provide the correct C ABI to main() you need to zero the BSS (this is how your static variables get initialized), maybe copy the initalized data, call the constructors and dest…

> presumably he'll address the rest in his

by Jessica McKellar

Re: I want to compile a C program so simple I can explain all of the assembly

#16

Earlier quoted context omitted.

The article is quite sound and doing all this is standard practice in the embedded world where you can't afford the size of glibc. The article is a bit incomplete, but presumably he'll address the rest in his next installment. As a preview, to provide the correct C ABI to main() you need to zero the BSS (this is how your static variables get initialized), maybe copy the initalized data, call the constructors and dest…

> presumably he'll address the rest in his by Jessica McKellar

Pretty sexist to make assumptions just because the dude's name is Jessica.

Re: I want to compile a C program so simple I can explain all of the assembly

#17
I love being reminded occasionally about the lower levels of computer operation. It never ceases to amaze me how easy it is to gloss over the details of computers with an abstraction. We create layer upon layer of abstraction and can quickly forget what is underneath, if we ever knew in the first place.

As long as those abstractions don't leak, it isn't a big deal, but when they do you had better know what's going on down below.

Re: I want to compile a C program so simple I can explain all of the assembly

#19

There was an example I read recently of doing this in Windows that I liked more -- perhaps because the setup and tear-down was more interesting.

Do you have a link for that article? Sounds like something I'd be interested in reading. Thanks.

Re: I want to compile a C program so simple I can explain all of the assembly

#20

If you really want to write code that you can understand all the way down I suggest starting from as close to bare metal as your level of masochism allows. For me, that's GRUB. This tutorial walks you through making a kernel image that GRUB can load, and shows how to poke bytes into video memory to print characters to the screen: http://wiki.osdev.org/Bare_bones

And then buy an FPGA and bust out some Verilog and write the metal yourself.

When I was about 14 I found writing a floppy disk boot loader in x86 Assembly to be a good way of learning how a computer really works at the most basic level. Including reading FAT12 to find the start of your next piece of code and even displaying a slash screen!

While a little masochistic I find I still call upon what I learned back then while writing in C and to a lesser extent higher level languages.

Post reply on HN