Hanoi in MIPS (loop is 32 instructions)

##############################
####DREW CRAWFORD#############
####ASSIGNMENT 2##############
####COMPUTER ARCHITECTURE#####
####FEB 2 2010########
##############################
.data
.align 2
A: .asciiz "A\n"
.align 2
B: .asciiz "B\n"
.align 2
C: .asciiz "C\n"
prompt: .asciiz "How many disks?"
.align 2
newline: .asciiz "\n"
.align 2
print:  .asciiz "Move from \n"
.align 2
to: .asciiz " to \n"
.align 2
movet: .asciiz "The total number of moves is: \n"

.text
la $a0,prompt
li $v0,51
syscall
move $t0,$a0

#####t0 - n
#####a1 - "A"
#####a2 - "B"
#####a3 - "C"
la $a1,A
la $a2,B
la $a3,C
jal hanoi
#print totals
la $s1,movet
jal printstr
move $a0,$v1
li $v0,1
syscall
li $v0,10
syscall

li $v1,0

#A hanoi solution in 32 instructions
#(11 print instructions, 1 move count instruction)
#So only 20 algorithmic instructions.
#And only one expensive lw/sw pair per call.
#Beat that.
hanoi:
beq $t0,0,silentreturn
addi $t0,$t0,-1
xor $a2,$a2,$a3
xor $a3,$a2,$a3
xor $a2,$a2,$a3
addi $sp,$sp,-4
sw $ra,0($sp)
jal hanoi
##############non-algoirthmic section
#An implementation detail prevents me from using the printstr syscall on my emulator
#Feel free to replace with the syscall
la $s1, print
jal printstr
move $s1, $a1
jal printstr
la $s1,to
jal printstr
move $s1, $a3
jal printstr
la $a0,newline
la $v0,4
syscall
addi $v1,$v1,1
#############end non-algorithmic section
move $t1,$a3
move $a3,$a1
move $a1,$a2
move $a2,$t1
jal hanoi
xor $a1,$a1,$a3
xor $a3,$a1,$a3
xor $a1,$a1,$a3
lw $ra,0($sp)
addi $sp,$sp,4
addi $t0,$t0,1
silentreturn: jr $ra

printstr: #my hack around a printstr issue on my emulator
ld $s2,($s1)
andi $a0,$s2,255 #select xxxX
li $v0,11
beq $a0,10,ret
syscall
andi $a0,$s2,65280 #select xxXx
srl $a0,$a0,8
beq $a0,10,ret
syscall
andi $a0,$s2,16711680 #select xXxx
srl $a0,$a0,16
beq $a0,10,ret
syscall
andi $a0,$s2,4278190080 #select Xxxx
srl $a0,$a0,24
beq $a0,10,ret
syscall
addi $s1,$s1,4
j printstr
ret: jr $ra

On Closed Systems

> We lose nothing by having closed systems.

For good or for bad, for the past 25 years or so, programmers have effectively been subsidized in that the tools to design and create programs are effectively the same as the tools to *run* programs.

So every system, simply by installing a compiler, is ready to write computer programs.

Early computers didn’t even have that step. They had assemblers and basic in the ROM. It was assumed that you were going to be writing programs; how else were you going to get computers to do what you want?

The iPad/iPhone is the latest and greatest step in that huge gap. A little uneasy, for some of us, perhaps, who grew up with QBASIC on-device-coding and can’t imagine any other way.

But that is sort of a straw-man issue. You have to buy a real computer, so what? There’s a closely-related, but way-more-troubling problem.

App review.

App review is painful. I’ve had two apps axed by Apple not for bugs or for security issues, but because, quite simply, Apple didn’t like them (technically I had 3 such rejections; one was “reversed” on “appeal”).

Think this doesn’t affect you? It does. Google Voice found out the hard way. It was easier for them to rewrite their app in HTML5 then to talk Apple into letting it on the app store. Same goes for Google Navigation, that will never see the light of day.

For every app that you hear about, there are hundreds (I suspect more like thousands) of developers who had an app rejected and quietly went away.

That’s the danger in these new devices. Not that you need a computer to develop for them. Not that the apps are sandboxed and you can’t animate your icons or you require some ridiculous API nobody should ever need.

The problem is that Apple can–and, in fact, does–reject well-behaved applications that it simply doesn’t like. Not just the buggy ones. Not just the malicious ones.

That’s a thought that should chill every developer to the bone.

Apple Predictions

Tablet (obviously).

  • LCD or OLED (not e-ink).  ARM-based.
  • 802.11n and 3G.  You can buy it without a contract, and get it on AT&T’s network later.  One US carrier.
  • Runs existing iPhone applications (I have inside info about this).
  • Tactile feedback API.  While the iPhone keyboard was best-in-class, consumers won’t accept a pure softkeyboard on a tablet-sized device.  A feedback keyboard, though…
  • Shipping in a few weeks
  • Battery life for reading a book will be incredible
  • 128 GB SDD option
  • Runs iPhone OS 4.0, possibly under a different name.
  • Major partnerships with health industry, publishing industry, and news corps.  News will be a “rental” model.
  • Named iPad (sorry…)
  • Prosumer-grade (bose, etc.) “hifi” dock, intended to replace your stereo.  Maybe it’s not demoed, but you know Apple’s partners will have it on launch day.

iPhone OS 3.2

  • Mostly a performance release, a few small features and fixes
  • Immediate availability (days)

iPhone OS 4.0

  • immediate SDK release to all paid developers
  • Unified SDK for tablet and iPhone/iTouch
  • tactile feedback API
  • Huge resolution independence changes
  • Turn-by-turn navigation built in (sorry Google)
  • Easy advertising API for free apps.  Just turn it on and get it paid around 25c per download.
  • Special API designed for low-power consumption mode (reading)
  • Complete ObjC overhaul to prevent you from any visibility into private methods.  This is a major complex rewrite which is required if app review will ever end.
  • No announcements about changes to the app review process (except to say they’re staffing up)
  • Changes to multitouch API to support more complex multihand gestures
  • Available for 3Gs (maybe 3G too, but not anything prior) and latest-generation iTouch
  • Multitasking (maybe they won’t announce this tomorrow for anything except the tablet, but a pre-summer handheld will support it and there will be references to it in OS 4.0)
  • 802.11n sync (really a wishlist item, not sure how possible this is.  Tablet had better support it tho.)

iPhone/iTouch

  • No announcements, new iPhone shipping in early summer.

OSX

  • No announcements, 10.7 developer release for WWDC

bassdll – an Arduino piezo music library

I’m finally getting around to publishing bassdll, a project that (unfortunately) has sat on my shelf for over a year now.

bassdll is an arduino sound/music engine that lets you wire up piezo buzzers across your arduino pins and make multichannel music!

Check out the demo below:

Check out the source on github.

Quick math puzzle

Got this in an e-mail today and I’m ashamed to say it took me a full three minutes to get the trick.  I used to do these all the time as a kid.

Click this link and play the game.  It takes all of 15 seconds.  I’ll wait.

The math behind it is pretty simple:  whatever number you choose, subtracting both digits will give you a multiple of 9.  Why is this true?  Well:

  1. Subtracting the second digit alone will always give you a number that’s divisible by 10.  Subtracting 7 from 27 yields 20, subtracting 6 from 26 yields 20, etc.
  2. Given a number that’s divisible by 10, subtracting the first digit will give you some multiple of 9.  I used this trick throughout gradeschool to memorize the multiplication table (Actually, I used a related statement: the digits of any two-digit 9-multiple add to 9).  With a bit of hoodwinking and some axioms, one can be proved from the other.

The first statement works independently, but it would be a bit obvious if the number you had at the end was always divisible by 10.  So the second trick is employed to make the results feel more random.

Then it’s simply a matter of picking a random gift and listing it for each 9-multiple:

Notice that all the 9-multiples say “refrigerator magnet” in my case.

After mulling this over, I found a more direct statement:  any arbitrary-digit number, after subtracting its digits, is a multiple of 9.

Consider a three-digit number in the decimal system, i.e. a * 100 + b * 10 + c, where a, b, c, are natural numbers.

Then a * 100 + b * 10 + c – a – b – c = 99*a + 9*b.  It should be obvious that 99*a+9*b is divisible by 9.  For math majors:

  1. 99,9,a,b are all natural numbers
  2. Natural addition is closed
  3. 99 and 9 are multiples of 9
  4. Any multiple of 9 can be written as k * 9, for k some natural number
  5. Application of these rules yields 9*k*a + 9*j*b, {k,a,j,b elements of the natural numbers}
  6. Factoring yields 9 * (k*a+j*b).  Since natural addition is closed, this can be rewritten 9 * p for natural number p
  7. By application of #4, this is a multiple of 9.

Bonus points:  prove that all n-digit numbers, less their digits, are a multiple of 9 (for n a natural number).

Extra bonus points:  prove that uncountably long numbers, less their digits, are multiples of 9.

Sakaguchi iPhone project

Remember back when I was lamenting the lack of really solid iPhone titles?  Sure, your innovative block puzzler is kinda cool, but it’s no Final Fantasy or Chrono Trigger.

Well, Sakaguchi (the guy who designed Final Fantasy and Chrono Trigger) is now working on an iPhone project.  Along with some people from Brownie Brown (an offshoot of Square).

I can barely contain myself.

My macbook is a lemon

I’ve been having a crapload of trouble with my Late ‘06 macbook.

So far I’ve had

  • Two logic board replacements (and I need a third)
  • At least two heatpipe / thermal replacements
  • The display panel replaced
  • The battery replaced at least twice
  • The charger replaced

.  This last time the repair depot replaced the logic board, clearly it was a hardware problem, but they decided to wipe my hard disk for some inexplicable reason, and install 10.4 even though it had 10.6 installed.  Which was OK, I had a backup.  But by the time I spent the 4-5 hours doing the Time Machine restore and rebooted it wasn’t starting up anymore.  That’s right, the new logic board died on the second reboot.  Basically, the repair depot gave me a faulty part and wiped my machine.  Thanks for the help.

I’ve gone through three  logic boards (including the one it came with).  If I ship it to the repair depot and they give me fourth logic board, what’s to stop that one from breaking too?

I’m a software developer for a living, and I depend on this machine for my livelihood.  And when it has three major issues in the last 4 months, I can’t depend on it.

Logitech Sucks

I’ve been having a showstopping issue with my Logitech DiNovo Edge Mac Edition.  To put it simply:  it’s impossible to drag-and-drop with the included touchdisc.  Sure, it works for a few seconds, but the drag gets suddenly dropped–without any warning.  I’ve got two keyboards and three macs, and the same issue on all of them.

There’s a thread about this on the support forums where a bunch of people are complaining.  The issue manifests itself with a brand-new, out-of-the-box Mac, so it’s not like it’s difficult to reproduce.  It’s a software issue with Logitech’s LCC software–I might even consider reverse-engineering it and releasing a patch if they don’t fix it.  This is a $150 keyboard, which has consistently garnered 4.5-5 star reviews.  It’s fantastic–except for this showstopping issue.

I’ve contacted Logitech both via online e-mail support and phone support.  The e-mail people gave me a few old software versions to try, and when that didn’t work they said to call phone support (presumably, because they didn’t want what the phone support people were about to tell me in writing).  The phone support people said “there is a conflict” between my software configuration and the keyboard software, totally ignoring the fact that the issue manifests on an out-of-the-box Mac.  That’s a standard one-liner to avoid fixing the actual problem.

In this case, however, I’m a software developer, and I know how to test this stuff.  It’s definitely an LCC bug (probably triggered by OS X 10.5.8, which changed some keyboard drivers around).  Instead of owning up to their mistakes, Logitech prefers to run me around between support departments.

Not cool.  Suffice it to say, that’s the last Logitech keyboard I’ll ever buy.

Why I want to pay for news

I have absolutely no connection to the news industry.  I have a rather intense bias against reporters, based on some prior unfortunate experiences.

However, I think that paid news is in our future, and people will like it.  In particular, I support micropayments, although other models might work too.

Huh?

First of all, I’m in the minority.  Lots of smart people don’t like paying for news.  A new story about why paying for news is bad shows up in my RSS reader every day.  I get the (false) impression that the only people who support news paywalls are industry insiders.

Let’s be clear:  you can’t put “what you do now” behind a paywall and expect people to pay for it.  That ain’t going to happen.

But “what you do now” sucks.  The state of reporting (at least in tech) is absolutely, totally awful.  And I’m not just talking about “mainstream” outlets like NYT, WSJ, etc.  ”Tech” blogs are just as bad.  Take this snippet from Torrentfreak, a news site dedicated to “the p2p community, copyright issues, piracy and free culture“:

One of the downsides of Trackhub might be that it currently runs on Google’s App Engine platform which is based in the US. Unlike most existing trackers Google does keep logs and it is therefore advised to use the secure (https) announce url if you value your privacy.

If you are a software developer, or understand anything about networks you just did a silent W…T…F… as you read that.  I read it about four times to make sure it was as dumb as I thought on the first reading.  Let’s enumerate some of the many fails:

  • “Unlike most existing trackers” implies Google is a tracker, which it is not.  It’s a computing service provider, like a datacenter.  This betrays a total lack of understanding of Trackhub, the product the author is reporting about (which is not affiliated with Google, in the same way your Macbook is not affiliated with the power company)
  • Https does not protect your privacy from Google, the company running the datacenter.  Because you’re connecting to a tracker, it doesn’t even protect you against third-party eavesdroppers.  Security != Anonymity; that’s cryptography 101.  This is covered in different ways about 5x in any computer-related degree.  So far I’ve heard this speech in: Networks class, Discrete Mathematics, Analysis of Algorithms, Network Security… Anybody with a bachelors in a computer-related field knows this.
  • For torrents to work, you have to give random people your IP address and let them download stuff from you.  Period.  Presumably a blog dedicated to torrents would understand the protocol.
  • Why is it bad that Google is hosted in the US?  There are some record-keeping laws requiring you to hang on to logs for a few years, but these are the same in most developed countries.  The usual complaint about US datacenters is that they’re subject to PATRIOT act searches, etc., which violate some EU data safety laws, or so I’m told.  But P2P cases seem to always involve warrants and subpoenas, which any civilized country complies with, and I’ve never seen any p2p cases as a result of PATRIOT-style powers.

Of course this isn’t just to pick on Torrentfreak, mainstream press is even worse.  My point is that so-called “industry” blogs get it dead wrong on a regular basis.  Reading them is like tearing my eyes out.

What I’m proposing is simply this:  I’m perfectly willing to pay for somebody to write if they know what the heck they’re talking about.  I would totally pay for Apple coverage by a former Apple employee, or anybody with a CS degree, really.  I’d pay if somebody put together a comprehensive list of iPhone rejection letters and categorized them, maybe ran some stats on average review times.  I’d pay if car salesmen wrote about how to buy cars.  I’d pay biologists and physicists to write readable summaries of their own academic papers.

Too hard, you say?  I don’t think so.  Not all technical people can write, but some can.  (I’d like to think that I’m halfway decent.)  And there are nontechnical editors who can say to that scientist: “I don’t know what this list of words means.  Can you rework your article to explain them?”

Consider this list of recent stories:

  • Google Voice rejection.  Did anybody do any “journalism” apart from posting the FCC letters and making snide remarks in the corner?  Why can’t somebody put a theory together about the large section Google redacted from the public record?  I’d pay for that.
  • iPhone 3GS.  Can’t somebody dig up the contract with Cingular?  Or any of the three-dozen international carriers?  Or for the last-gen phone?  I understand that Apple’s an impenetrable wall, but surely there’s  a pissed-off exec willing to talk at one of the carriers.  I’d pay for that.
  • What the crap happened at the Tannenbaum trial?  I’m not a lawyer, but it sounded like that Harvard guy was nuts.  Can I get a lawyer to weigh in on WTF was really going on?  I’d pay for that.
  • Can I get a lawyer with a technical bent to blog about tech rights issues, like what sort of file sharing you can be prosecuted for, what wi-fi hotspots you can connect to (encrypted, unencrypted…), exactly what rights you have taking laptops across the border…  I’d pay for that.

The simple fact is, I want to read news that’s written by somebody that knows more than I do, instead of written by somebody that knows less.  When I read tech news, I consistently find that I have a better grasp on what’s going on than whoever wrote the article.  That’s absolutely no help.

Now, some thoughts on implementation:  the Kindle is demonstrating people will pay a few bucks to get the NYT on their device.  Which is really cool.  We certainly have the technology to try some other models, like per-article fees a la iTunes, or even (my favorite) a few bucks per hour of reading.

But wait, you say–p-p-p-p-piracy!  Yes, piracy.  But if iTunes has demonstrated anything, it’s that if it’s easy enough, a lot of people will pay.  Sure, you can write an FF plugin that caches the NYT.  But if somebody iTunesed the news industry, I think people just might use it.  (I’m looking at you, upcoming Apple tablet…)

Lots of people pirate movies and music because they’re mad.  Mad at a system that has “release windows” and files lawsuits and treats people like criminals and scum.  News does none of that.  And insightful news… the real “hard work” kind… people actually like it.  The only people mad at that is the company who got scooped.  And I’m willing to pay for that.

Your Wi-Fi Rights FAQ

After having a few run-ins with various over-enterprising institutions, I’ve gotten a pretty good grasp on the state of US Wi-Fi law.  Behold, a FAQ.

First of all, you have a right to run Wi-Fi networks, period.  The landowner can throw a hissy fit all they like, but (more often than not) you can still set up your hotspot.  The rationale is pretty simple.

1.  The 2.4GHz band is owned by the public.  This isn’t a “landowner’s right”, where each landowner “owns” the radio waves traveling over his/her particular land.  It’s like airspace.  American Airlines doesn’t consult with you before they fly planes over your house; they consult with the FAA.  Similarly, you don’t consult with the landowner before broadcasting radio waves, you consult with the FCC.

2.  The FCC has given you permission to broadcast on 2.4GHz (erm, the part that WiFi uses anyway, there are some IRM bands that are still licensed airwaves).  This is like the FAA saying you can fly over above 3500 feet–who you’re flying over has no say in the matter.

3.  Claims of “you can’t use hotspots because they interfere with our network” are not legally sound.  In the eyes of the law, “their network” is no more legitimate than yours, and they have no claim (either through landowner rights or through “first use”) to the airwaves.  If they want their own band, they can pay the FCC for licensed spectrum.  Otherwise, they have to share it with you/everyone.  Period.

4.  This leads to something extremely interesting–it’s perfectly legal to “jam” unlicensed 2.4GHz space (as long as you don’t interfere with licensed space or broadcast louder than the normal WiFi ceiling).  In particular, it’s perfectly legal to use beacon-layer flooding (bringing up lots of imaginary hotspots) or to talk over transmitters (as long as you don’t go above allowed transmit power).

5.  You cannot “sniff” conversations (encrypted or unencrypted) to which you are not a party (47cfr15.9).  There was an incident in the not-distant past in which an organization was sniffing wi-fi packets in order to determine the identity of persons operating “unauthorized” networks.  This is illegal.  Furthermore, if the AP is encrypted, it very likely meets the “access without authorization” test, rendering it a federal trespass crime.  It is also my considered (but untested) opinion that breaking WEP/WPA is additionally DMCA violation in some cases.

Okay, well maybe I can’t ban radio transmission, but as the landowner, surely I can keep hotspots (the physical boxes) off my property?

Actually, no.  Sure, if the Hotspot Bandit runs on your property, you can issue him a trespass warning, and he and his hotspot can go broadcast on the curb.  But if we’re talking about a legal resident / tenant, they can have whatever hotspots they want.  Huh?

It’s simple, really.  There are rules about what landlords can and cannot do.  They can’t not rent to black people or to women or to handicapped people.  They also can’t tell you that you can’t use a hotspot.  The FCC’s reasoning goes like this: since the 2.4ghz spectrum is unlicensed, anyone can broadcast on it.  The only reason to ban hotspots is to prevent people from accessing public airwaves.  Therefore, landowners can’t ban them.

The FCC has ruled like this on case after case–against residential landlords, airports, everybody.  As long as you have “exclusive use” of an area (basically, you can deny random people off the street entry), you can install a WiFi hotspot.  Period.  (You can also install small satellite dishes and many other kinds of antennas, and you can even put things on a mast above the roofline, subject to some safety restrictions.)

But my lease / the rules say X and Y!

I can write a lease that says you can’t have any Asian guests.  That doesn’t make it even remotely legal.  And if anybody tried to enforce it, there would be hell to pay.  Same with WiFi.

But… but…

Sorry.  That’s clearly and unequivocally the law.

Return top