Sunday, October 12th, 2014 - ???

Adventures in Ternary Computing

Bender: Ahhh, what an awful dream. Ones and zeroes everywhere... and I thought I saw a two.

Fry: It was just a dream, Bender. There's no such thing as two.

- Futurama

Several problems exist for anyone making the jump to tri-state computing. Firstly, all the experimental data is in Russian. Secondly, actual hardware implementation may be likened to a whangadoodle - no one knows what it is, and those who do know believe it to be purely fictatious. Then follows the gamut of lesser hurdles, not the least of which is the grand-canyon scale entrenchment of our current binary system, among other things. This post will therefore be continuously updated as I continue to collect the pieces needed to design and implement the jigsaw puzzle that is ternary computing.

Ternary ALU


Tuesday, September 9th, 2014

Recursivity in the Bourne Again SHell

Problem: Crawl through every directory in a tree and catalog its contents.

Solution:

#!/bin/bash

recur() { # Main function declaration

cd "$1"

ls -al

return

}

recur "$1" # Call the function.

This takes us to a directory and lists its contents by executing '$ script.sh directory'. In the directory there may be files, other directories, or nothing. We can ignore files and nothing, but for every directory another instance of the main function must be called. Note: On OS X *.* is actually the format of many psuedo directories disguised as files, e.g. Finder.app.

dir=$(pwd) # at last a real use for pwd

for z in $dir/*;do

if [[ $z != .* ]] && [[ $z != *.* ]];then # Skip checking invisible files, self, and above directory

if [ -d "$z" ] && [[ $z != //Volumes ]];then # Make sure z is any directory except /Volumes

recur "$z" # Call the function on all matches

fi

fi

done

Putting it all together:

#!/bin/bash

recur() {

cd "$1"

dir=$(pwd)

ls -al

for z in $dir/*;do

if [[ $z != .* ]] && [[ $z != *.* ]];then

if [ -d "$z" ] && [[ $z != //Volumes ]];then

recur "$z"

fi

fi

done

return

}

recur "$1"


Tuesday, August 19th, 2014

Side by side interlacing reference, using Victor Gabriel Gilbert's The Sleeping Beauty of Dornroschen. Images were made very large by intention (3MB-9MB) to increase loading time and allow for observation.

(for optimal viewing throttle your bandwidth)

No Interlacing

4 pass Vertical Interlacing

7 pass Horizontal & Vertical Interlacing


Sunday, August 17th, 2014

From ASCII to Bits,

using the Mac OS X GNU-based assembler & linker

~/asm ls -lh

total 8

-rw-r--r-- 1 nobody staff 63B 17 Aug 22:58 ff

~/asm as -arch x86_64 ff -o ff2

~/asm ls -lh

total 16

-rw-r--r-- 1 nobody staff 63B 17 Aug 22:58 ff

-rw-r--r-- 1 nobody staff 320B 17 Aug 23:02 ff2

~/asm ld -execute -arch x86_64 -macosx_version_min 10.9 -pie -S ff2 -o ff3 -lSystem

~/asm ls -lh

total 32

-rw-r--r-- 1 nobody staff 63B 17 Aug 22:58 ff

-rw-r--r-- 1 nobody staff 320B 17 Aug 23:02 ff2

-rwxr-xr-x 1 nobody staff 4.2K 17 Aug 23:03 ff3

4.2 Kilobytes of this:

.text

.globl _main

_main:

movl $0x2000001, %eax

syscall

Why the nonsensical waste of space?

Addendum

The standard OS X executable uses a mach-o binary, divided into multiple segments based on program length. The above program is small, and has only one segment. From the Developer pages: "For best performance, segments should be aligned on virtual memory page boundaries—4096 bytes for PowerPC and x86 processors." Segments smaller than 4096 bytes are buffered with zeros until they achieve the desired length. This explaines the large filesize for even very small code examples.


Thursday, August 7th, 2014

Unreliable Data Protocol, a test:

The User Datagram Protocol provides a stateless connection with no guarantee of packet ordering or delivery. A well known, simple example of UDP is the original echo protocol. A theoretical test of UDP reliability could use the echo protocol to setup a bouncing message between two servers. Eventually one of the servers or an intermediate will "drop the ball". To realize this test I coded a client that sends an initial message, then falls back into a server mode to receive the response. The number of bounces may serve as a rough estimate of network reliability. For instance, testing the protocol on the loopback address results in zero loss. Testing on a private network resulted in a high of 22,158 bounces.

Github Repository


Tuesday, July 29th, 2014

Computers are only 1's and 0's at runtime (excepting the Setun, which is just great anytime). Here's some assembly code to remind myself of that:

CheckNickErrors:: ; 669f

; error-check monster nick before use

; must be a peace offering to gamesharkers

; input: de = nick location

push bc

push de

ld b, PKMN_NAME_LENGTH

.checkchar

; end of nick?

ld a, [de]

cp "@" ; terminator

jr z, .end

; check if this char is a text command

ld hl, .textcommands

dec hl

.loop

; next entry

inc hl

; reached end of commands table?

ld a, [hl]

cp a, $ff

jr z, .done

; is the current char between this value (inclusive)...

ld a, [de]

cp [hl]

inc hl

jr c, .loop

; ...and this one?

cp [hl]

jr nc, .loop

; replace it with a "?"

ld a, "?"

ld [de], a

jr .loop

.done

; next char

inc de

; reached end of nick without finding a terminator?

dec b

jr nz, .checkchar

; change nick to "?@"

pop de

push de

ld a, "?"

ld [de], a

inc de

ld a, "@"

ld [de], a

.end

; if the nick has any errors at this point it's out of our hands

pop de

pop bc

ret

Full source available here.


Monday, July 7th, 2014

Purpose: This webspace was created to gather and analyze my personal ideas about computers and their languages. I anticipate that it will become a shameless conglomeration of my favourite bash scripts.