Live data from Hacker News

TCP HTTP Server written in Assembly

canonical.org

31–40 of 74 posts

Re: TCP HTTP Server written in Assembly

#31
post #29
post #22

OMG all these macros. It looks more like Python then Assembly. Come on, real men do not use macros.

ahh yes, real programmers twiddle bits on their hard drive with a nothing more than a tiny magnet: http://www.cs.utah.edu/~elb/folklore/mel.html

real programmers use butterflies http://xkcd.com/378/

Re: TCP HTTP Server written in Assembly

#32
post #9

Cool! My comments as an inexperienced assembly developer, assuming this is optimising for binary size: - The pug/doN macros do an extra reg-reg copy if passed a register - and the recursive definition calls pop/pop/pop instead of just add %esp, -4*N, you could shave a few bytes - AT&T syntax will always look weird to me, but the heavy use of macros and local labels is quite elegant - A little bit of candid swearing i…

Agree, AT&T syntax was just not designed for human reading. I doubt this is too optimized for size, since there are obvious tricks that it misses.

Another observation: the strlen code is incorrect, as it also counts the \0. We can fix this, and make the code 1 byte shorter (in glorious Intel syntax):

    lea esi, source        ; depends on source
    xor ecx, ecx           ; 2 bytes
    salc                   ; 1 byte
    cld                    ; 1 byte
    _back:
    scasb                  ; 1 byte 
    loopnz _back           ; 2 bytes
    not ecx                ; 2 bytes

Re: TCP HTTP Server written in Assembly

#33
post #18

Cool stuff. Really, though, this is still relying on a rather large runtime library: the physical, data-link, and network-layer drivers. Now what'd be really awesome to see, would be one of those Operating System guides that shows you how to write an OS kernel, in assembler, that can speak HTTP. Even just limiting yourself to targeting the synthetic hardware of a VM program, it'd still be quite a feat. Bonus points i…

Here you go:

http://www.kyllikki.org/hardware/wwwpic2/src/wwwpic2.asm.htm...

Bonus: runs on 68 bytes of ram. Not a typo, it's bytes, and it's a "complete" http+tcp/ip server.

Re: TCP HTTP Server written in Assembly

#34
post #33
post #18

Cool stuff. Really, though, this is still relying on a rather large runtime library: the physical, data-link, and network-layer drivers. Now what'd be really awesome to see, would be one of those Operating System guides that shows you how to write an OS kernel, in assembler, that can speak HTTP. Even just limiting yourself to targeting the synthetic hardware of a VM program, it'd still be quite a feat. Bonus points i…

Here you go: http://www.kyllikki.org/hardware/wwwpic2/src/wwwpic2.asm.htm... Bonus: runs on 68 bytes of ram. Not a typo, it's bytes, and it's a "complete" http+tcp/ip server.

Awesome. Can VirtualBox or VMWare run this?

Re: TCP HTTP Server written in Assembly

#35
post #33

Earlier quoted context omitted.

Here you go: http://www.kyllikki.org/hardware/wwwpic2/src/wwwpic2.asm.htm... Bonus: runs on 68 bytes of ram. Not a typo, it's bytes, and it's a "complete" http+tcp/ip server.

Awesome. Can VirtualBox or VMWare run this?

From the first line of the source, it's a PIC (microcontroller) program, rather than something for x86 (which VirtualBox and friends emulate), so, no.

There are a few open source PIC simulators -- e.g. [1] -- and I would guess you might be able to get it running, since the link layer is SLIP over a serial port. You'd just have to wire up the simulator's serial console in the right way.

[1] http://gpsim.sourceforge.net/

Re: TCP HTTP Server written in Assembly

#36
post #33
post #18

Cool stuff. Really, though, this is still relying on a rather large runtime library: the physical, data-link, and network-layer drivers. Now what'd be really awesome to see, would be one of those Operating System guides that shows you how to write an OS kernel, in assembler, that can speak HTTP. Even just limiting yourself to targeting the synthetic hardware of a VM program, it'd still be quite a feat. Bonus points i…

Here you go: http://www.kyllikki.org/hardware/wwwpic2/src/wwwpic2.asm.htm... Bonus: runs on 68 bytes of ram. Not a typo, it's bytes, and it's a "complete" http+tcp/ip server.

That is just running the TCP/IP layer speaking RS232 and relying on an external IC for lower layers. It's not at all what the GP is looking for.

It should probably also be noted that a minimum TCP header, with no data attached, is 20 bytes, so to implement a 'full stack' in 68 bytes is a pretty strong indication that you're relying on off SoC memory to handle the packet buffering.

Re: TCP HTTP Server written in Assembly

#38
post #33
post #18

Cool stuff. Really, though, this is still relying on a rather large runtime library: the physical, data-link, and network-layer drivers. Now what'd be really awesome to see, would be one of those Operating System guides that shows you how to write an OS kernel, in assembler, that can speak HTTP. Even just limiting yourself to targeting the synthetic hardware of a VM program, it'd still be quite a feat. Bonus points i…

Here you go: http://www.kyllikki.org/hardware/wwwpic2/src/wwwpic2.asm.htm... Bonus: runs on 68 bytes of ram. Not a typo, it's bytes, and it's a "complete" http+tcp/ip server.

Bet that handles TCP fragmentation well :)

Nice work though to whoever crammed that in a PIC.

Re: TCP HTTP Server written in Assembly

#39
post #36
post #33

Earlier quoted context omitted.

Here you go: http://www.kyllikki.org/hardware/wwwpic2/src/wwwpic2.asm.htm... Bonus: runs on 68 bytes of ram. Not a typo, it's bytes, and it's a "complete" http+tcp/ip server.

That is just running the TCP/IP layer speaking RS232 and relying on an external IC for lower layers. It's not at all what the GP is looking for. It should probably also be noted that a minimum TCP header, with no data attached, is 20 bytes, so to implement a 'full stack' in 68 bytes is a pretty strong indication that you're relying on off SoC memory to handle the packet buffering.

I encourage you to read the source code instead of guessing how it may work.

Re: TCP HTTP Server written in Assembly

#40

Earlier quoted context omitted.

This is obviously a toy, or PoC.

I don't know about calling it a piece of crap. Seems a little harsh. :-)

Haha, imagine what tech news would be like if every time you saw PoC you thought it meant piece of crap. Quite hilarious actually.
Post reply on HN