Posts

Showing posts from March, 2012

Innovative Humanitarian Products Organization

I am able to proudly say I'm part of the IHPO (Innovative Humanitarian Products Organization). We design and develop products that are cheap and able to make a difference in the developing world. Our first product was an electrical device (our founder, Grant Moore is an Electrical Engineering student), which uses salt water to make chlorine for sterilizing water, etc.

We are currently entered into a competition to win $5000 and need everyone's help. The competition gives $10,000 for the presentation with the most views, and $5000 for the 2nd - 5th places. We are currently in 5th place, but to solidify our win, we'd still love as many views as possible. Watch the presentation below or click the link:

http://portal.sliderocket.com/BMNDW/IHPO

Keep track of your IP address and internet connectivity

Below is some code I wrote to email me whenever my computer's IP address changes and log it to a file. I nifty side effect is it keeps track of when my internet connection is down as well. Copy this code and insert your own email address and run on a schedule such as cron.

No post for today's Computer Systems

We covered the all to crucial and important interrupts in Computer Systems today but alas, I was still occupied with Digital Electronics and the wonderful and sometimes mysterious world for transistors and couldn't take real good notes. For my own review and the benefit of the world, I'll write up a summary of HCS12 interrupts when time permits. Sorry...

Using Google Command Line Tools to post my Computer Systems Notes

Below is some code I wrote to post my Computer Systems notes online every day after class:


  1 #!/usr/bin/env perl
  2 use strict;
  3 use warnings;
  4 
  5 unless(defined $ARGV[0]){
  6    print "$0 [file to post]\n";
  7    exit;
  8 }
  9 my @date = ($1,$2,$3) if $ARGV[0] =~ m/Computer_Systems_(\d{4})(\d{2})(\d{2}).txt/g ;
 10 my $title = "Computer Systems Class Notes ".join('/',@date);
 11 my @infile = `cat $ARGV[0]`;
 12 my @template = `cat blank.html`;
 13 # Get rid of blank lines...
 14 my $tmp = pop(@infile);
 15 while($tmp =~ m/^\s*$/g){
 16    $tmp = pop(@infile);
 17    #print "tmp got $tmp\n";
 18 }
 19 push(@infile,$tmp);
 20 open(FH,">$ARGV[0].html");
 21 foreach(@template){
 22    if(m/{{{TITLE}}}/g){
 23       $_ =~ s/{{{TITLE}}}/$title/g;
 24    }
 25    if(m/{{{BODY}}}/g){
 26       $_ =~ s/{{{BODY}}}/@infile/g;
 27    }
 28    if(m/^\s*$/g){
 29       next;
 30    }
 31    print FH "$_";
 32 }
 33    close(FH);
 34 #  
 35 print "goog…

Class Notes 2012/02/13

; #1 Write a program to compute the following
;A1 = (B1 - C1) - (D1 + 8)

;Use only direct/extended addr. for all memory references.

ldea B1; A=B1
suba C1 ; A = (B1-C1)
ldab D1 ; B = D1
addb #8 ; B = (D1 + 8)
sba ;
staa A1 ;

;Use only constant offset indexed addr. for all memory references.

ldx #A1
ldaa 1,x ;A=B1
suba 2,x ; A=(B1-C1)
ldab 3,x ;B=D1
addb #8 ;B= D1+8
sba ;A=(B1-C1) - (D1 + 8)
staa 0,x ; staa x


;Use auto-increment indexed addr. for all mem references.

ldx #A1 ;
ldaa 1,+x ; A = B1
suba 1,+x ; A = (B1 - C1)
ldab 1,+x ; B = (D1)
addb #8 ; B = (D1 + 8)
sba ; A = (B1-C1) - (D1 + 8)
staa 3,-x ; A1 = A


;Use register offset indexed addr. for all mem references.
ldx #41
ldab #1
ldaa b,x ; A = B1
ldab #2
suba b,x ; A = (B1 - C1)
ldab #3
suba b,x ;A = (B1 - C1) - D1
suba #8 A = B1 - C1 - D1 - 8
ldab #0
staa b,x A1 = A

;Define 2 20-byte arrays,
; 1) Copy one byte at a time, using indexed add…

Class Notes 2012/02/10

ORG $800
vec1 dc.b 1,2,3,4,$FF
vec2 dc.b 0, $FF, 3, 5, $80
count ds.b 1
ORG $4000
ldx #vec1 ; x->vec1
ldy #vec2 ; y -> vec2
ldab #5 ; init loop counter
clr count ; clears the count
loop: ldaa 1,x+ ;vec1[i] -> A
cmpa 1,y+ ;compare vec1[i] with vec2[i]
blt next ;if vec1[i] < vec2[i] then branch
inc cont
next: dbne b, loop dec. loop counter + branch if it's !=0

Next example: Write a program to compute the dot product of vectors a + b. Assume the vectors contain unsigned 8-bit values and ignore any carries...

a (dot) b = sum from i to n of a_i*b_i = a1*b1 + a2*b2 + ... a_n*b_n

; Variables
vecA ds.b 5
vecB ds.b 5
result ds.w 1
counter ds.b 1

; Code
ORG $4000
ldx #vecA
ldy #vecB
movb #5, counter
movw #0, result ; We move word because multiplying two bit numbers results in word (???)
loop: ldaa 1,x+
ldab 1,y+
mul
addd result ; Goes into register D
std result ; Put the result stored in D back into result.
dec counter