Skip to content

Instantly share code, notes, and snippets.

@thentenaar
thentenaar / gist:4142031
Created November 25, 2012 01:30
Disassembly of TI BASIC's RND function
4F00: ST @>834A,>3F ; Zero loop counter: >3F (63)
4F03: ST @>8310,>4B ; Number buffer address: >834B
4F06: RAND >63 ; Get a pseudo-random number (using 100 as the divisor)
4F08: CZ @>8378 ; If then number isn't zero, goto >4F16
4F0A: BR >4F16
4F0C: DEC @>834A ; Decrement the zero loop counter
4F0E: CZ @>834A ; If the zero loop counter is 0, goto >4F23 (return 0)
4F10: BS >4F23
4F12: BR >4F06 ; Otherwise, continue the loop
4F14: RAND >63 ; Get the next pseudo-random number
@thentenaar
thentenaar / sunos-551-paging-bug-fix.c
Created July 24, 2015 18:30
Patch for the paging bug on Solaris 2.5.1 (SunOS 5.5.1) i386
/**
* Patch to fix the paging bug in the SunOS 5.5.1 (i386) kernel
* Copyright (C) 2015 Tim Hentenaar
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* 1. Redistributions of source code must retain the above copyright
@thentenaar
thentenaar / echo-server-3.c
Created January 26, 2015 23:29
Simple echo server: Refactor #3: Change the work loop's while into a do { } while(), and make it smaller
/**
* Simple echo server
*
* This program listens for connections on the
* loopback interface, on port 9999. Upon connecting,
* The first line we read, of up to BUF_LEN bytes, is
* then sent back to the sender, and the connection
* is closed.
*/
#include <stdio.h>
@thentenaar
thentenaar / echo-server-4.c
Created January 27, 2015 00:23
Simple echo server: Refactor #4: Replace duplicate returns with goto
/**
* Simple echo server
*
* This program listens for connections on the
* loopback interface, on port 9999. Upon connecting,
* The first line we read, of up to BUF_LEN bytes, is
* then sent back to the sender, and the connection
* is closed.
*/
#include <stdio.h>
@thentenaar
thentenaar / echo-server-5.c
Created January 27, 2015 00:49
Simple echo server: Refactor #5: Reduce the depth of nesting in main().
/**
* Simple echo server
*
* This program listens for connections on the
* loopback interface, on port 9999. Upon connecting,
* The first line we read, of up to BUF_LEN bytes, is
* then sent back to the sender, and the connection
* is closed.
*/
#include <stdio.h>
@thentenaar
thentenaar / echo-server-6.c
Created January 27, 2015 00:59
Simple echo server: Refactor #6: Move the work loop back out into its own function.
/**
* Simple echo server
*
* This program listens for connections on the
* loopback interface, on port 9999. Upon connecting,
* The first line we read, of up to BUF_LEN bytes, is
* then sent back to the sender, and the connection
* is closed.
*/
#include <stdio.h>
@thentenaar
thentenaar / echo-server-1.c
Created January 26, 2015 20:59
Simple echo server: Refactor #1: Move the socket setup code into its own function.
/**
* Simple echo server
*
* This program listens for connections on the
* loopback interface, on port 9999. Upon connecting,
* The first line we read, of up to BUF_LEN bytes, is
* then sent back to the sender, and the connection
* is closed.
*
* Refactor #1 - Move socket creation code into its own
@thentenaar
thentenaar / echo-server-2.c
Created January 26, 2015 22:04
Simple echo server: Refactor #2: Move the work loop into its own function.
/**
* Simple echo server
*
* This program listens for connections on the
* loopback interface, on port 9999. Upon connecting,
* The first line we read, of up to BUF_LEN bytes, is
* then sent back to the sender, and the connection
* is closed.
*/
#include <stdio.h>
@thentenaar
thentenaar / echo-server.c
Created January 26, 2015 20:55
A very simple, and quickly implemented, echo server
/**
* Simple echo server
*
* This program listens for connections on the
* loopback interface, on port 9999. Upon connecting,
* The first line we read, of up to BUF_LEN bytes, is
* then sent back to the sender, and the connection
* is closed.
*/
#include <stdio.h>