avatar tianjara.net | blog icon Andrew Harvey's Blog

Entries from March 2009.

COMP3311 Wk02
26th March 2009

Various things about mapping ER Designs to Relational Schemas.

Mapping Strong Entities


The relational model supports only atomic attributes. To map composite attributes you can try,

  1. Concatenate the attributes eg. Struct name {"John", "Smith"} --> "John Smith"
  2. Map atomic components of the composite attribute to a set of atomic components. eg. mapcompatt1 mapcompatt_table
  3. ??

Mapping N:M Relations


Mapping 1:N Relations

map1nrel2Mapping 1:1 Relations


Notes from the Text Book (The Lecture Notes are a Little Different)

Domain Types & User Types

In the sample code for the first assignment to define "custom types" create domain is used. eg.

create domain PersonGender as char(1) check (value in ('M','F'));

However the text also shows create type. eg.

create type Dollars as numeric(12,2) final

It goes on to explain the difference.

Pattern Matching

Patterns in SQL can be desribed using % and _.


select foo from bar where lar like '_to%'

This will match to any of these strings, "Lto" "Ato" "ltoo" "rtoto" ... (any character at the start, then the "to" string, then any (even null) trailing string)

You can define the escape character for a like comparison as follows,

like 'he\%%'  escape '\'' --matches all strings begining with 'he%'

You can also use not like.

SQL:1999 allows for similar too which is similar to Unix regular expressions.

Drop vs. Delete

drop table r will remove all the tuples from r, and removes the schema of r, whereas

delete from r will just remove all the tuples from r, but leaving the schema so you can still add values to the table.


Shepherd, John. COMP3311 09s1 Lecture Slides. http://www.cse.unsw.edu.au/~cs3311/09s1/lectures/. (Diagrams have also been sourced from here).

Silberschatz. Database System Concepts. 5th Ed.

Tags: comp3311, computing.
COMP3311 - Wk01
23rd March 2009

Just a couple random notes, to reiterate some things I need to become acquainted with. Definitely not comprehensive.

The ER Diagram



  1. Each manager manages exactly one branch, and each branch is managed by exactly one manager.
  2. Each branch holds zero or more accounts, but each account is held be at most one branch.
  3. Each customer owns zero or more accounts and each account is owned by zero or more customers.


participNot all customers must take out a loan (or it is not the case that every customer takes out a loan), but every loan is taken out by at least one customer. i.e. Every loan is associated with at least one person, but every person is not necessarily associated with at least one loan.

Attributes Linked to Relationships


In (a) you know how much time a particular person spends on a project. In (b) you only know how much time has been spend on a particular project. You don't know the distribution of that time among the researches that have worked on it.


Shepherd, John. COMP3311 09s1 Lecture Slides. http://www.cse.unsw.edu.au/~cs3311/09s1/lectures/. (Diagrams have also been sourced from here).

Tags: comp3311, computing.
SENG4921 - Lec 02 - Moral Reasoning & Professional Ethics
21st March 2009

Part II of Stephen Cohen's lecture, (audio here) (2008 lecture slides here). Just as a side note, I think I've picked up more by listening to the audio where I can stop it to think about what was said, that I have by going to the lecture. Also it seems that the content in the two lecture doesn't fall under the title really well. It seems some of the stuff from lecture one falls under lecture two's title, and some of the stuff from lecture two falls under lecture ones title.

Cohen started by talking about some ethical theories. Here is a diagram based on the one we were shown.


On the left we have the group of ethical theories, consequential, that is based on the view that "Acts are right based on their consequences." Under this umbrella there are four different views as shown.

On the right we have another view where ethics is based on non-consequential things. That is, to determine if an act is right or wrong it in fact has nothing to do with the consequences of the act. Instead it has to do with other things such as rights, duties, contracts, fairness, etc.

Or to put it as Ken Robinson and Achim Hoffman have it in their introduction article,

Kant was a non-consequential thinker. His idea (how I have interpreted it) was that good will is what makes an act right, where good will is recognising your duty and then being able to make yourself do it (eg. you crash into a parked car you realise it is your duty to leave your details and then your able to make yourself to do that, even if you don't want to do it).

Cohen then goes on to make a very good point about autonomy. The audio segment is embedded here, (or direct download)

[audio http://www.cse.unsw.edu.au/~amha119/se4921-090317-autonomy_cut.mp3]

"Kant was the person, and this has been a feature of thinking about ethics ever since Kant. A number of people think that a really important feature about ethical performance is autonomy, autonomy. Which means being free from various kinds of constraints and being able to generate something all on your own. Autonomy, I do it not because I have to, not because I've been trained to do it. In that respect you see you could be free ...--go do whatever you want, but you've now been as it were brainwashed to do a certain kind of thing--. You would be free but you wouldn't be autonomous. Autonomous is being able to come up with the principle, to generate it yourself and then make yourself do it. And that has been a very important element in thinking about ethics." --Stephen Cohen, 2009.

Aristotle on the other hand thinks ethics is about having the right character. Imagine there's person walking along a pier and he sees someone who's drowning. The person with a good character (a good kind of person) does think twice, they pick up the lifefloat tube and trow it to them. This person has good ethical values as a result of their good character. Taking another approach, same situation but now someone who doesn't have good character who doesn't value human life. They don't want to save this person, but they know that they ought to save them so they throw them the lifefloat to save them, despite the person not wanting to do it. This person does not have good character, but they have good ethical vales because they recognised what they ought to do, and they did it. This is Kant's view.

Another view, sometimes called contractarism, focuses on "Keeping the terms of the contract."

Another slide that Cohen showed was this.


Cohen makes the point that in order to have made a moral judgement you need to make a judgement, have some justification for that judgement, and also have some principle that lead you to believe that that justification was right.

judgement > justification > principle

If you don't have this, you don't have a moral judgement. He also says that the way you could discover that something is not a moral judgement, rather you have some bias or preference towards that judgement and it is not a moral judgement is if you don't have that, you don't have judgement > justification > principle.

If you are more committed to a particular judgement rather than the principle. Cohen then goes on to say that he thinks this is how we go on about moral reasoning. We try to put these two together. Sometimes we modify the judgement in light of the principle, and sometimes we modify the the principle in light of the judgement. These are exceptions to the rule (or the principle).


Cohen then talks about business and the profession.


The big difference between profession and business is profession have this extra bit about the public interest and the client interest. They have a duty to survey the whole landscape and do what is best. Professions and professionals must do that stuff as above. You can't be a profession if you have some extra incentive (eg. being paid to do something against the client and public's interest).

"A person’s having a conflict of interest is not the same thing as a person’s being affected by a conflict of interest." People who say they don't have a conflict of interest just because they are not affected by (or more specifically their judgement is not affected by) a conflict of interest doesn't mean they don't have a conflict of interest.


Two more good slides. This first one shows two organisational models, one where the top has great power, with this comes great responsibility, the other where they all have power, with this comes great trust.


The second shows some of the modern differences between a Code of Ethics and a Code of Conduct.


Any principle/value will require judgement. Say you subscribe to the principle of honesty. At some stage you will need to make a judgement based on this principle. For example (and Cohen makes the story sound more convincing than I do here) you are at home with your close friend, Bob. Bob says he is scared as some crazy person is out to get him. Someone then knocks on your door, you answer and there is a big strong man there with a knife in his hand who asks is Bob here. Honesty does not require that you say yes he is here. You make a judgement on the principle/value, and in this respect Code's of Ethics are empowering.

Code's of Conduct are different. They are not for introducing new values. They are there to remove judgement. They tell you exactly what to do in specific situations. One area they may deal with is gifts/bribes. They may say that you cannot accept any gift you receive over a given about. They take the heat off.

Although Cohen did not cover this in the lecture, the lecture slides from last year looked into management and leadership issues and ways to promote ethical behaviour in an organisation. I find this interesting so I'll go over a couple of these things here.

One last thing about morals and ethics. Back in COMP1917 Richard Buckland made a good statement he said something along the lines of come up with your own ethics and moral beliefs, and stick to them. I think this is good advice.

Also here are some notes made by the COMP1917 class which seem relevant.

  • "Ethics is the way you behave when people are not around and there is a spanking new Alienware laptop sitting on the table in front of you waiting for you to steal.
  • When you face ethical dilemmas at work, don't forget you can ask other professionals from your field for advice on how to handle such situations.
  • Discussed a large range of examples of ethical dilemmas and scenarios which present interesting problems:
    1. Hitler's guards - Each of Hitler's guards, when told to throw the next lot of prisoners into the gas chambers must have each thought inside that they didn't want to do it, but nobody had the courage to say anything. Maybe if one guard refused, all the others would, then a message might get sent that what they were doing was wrong.
    2. Richard's friends - was put on the spot by her boss in an interview with a client to lie about the progress of her software. In spur of the moment she lied and ever since the boss does it regularly now. She feels like she is doing the wrong thing and doesn't know what to do.
  • Richard's advice on ethics was for each person to sit down and work out exactly what they think is ethically wrong and ethically right, and then never break that. It doesn't matter what he thinks, in the end it's YOUR ethics and morals that count for yourself. He said that breaking morals breaks the spirit and that we get extreme happiness from obeying our morals and doing the right thing. He also said we need to plan ahead, and attempt to predict ethical dilemmas before they arise, that way we can think about them and make a proper decision, since during the heat of the moment we will often give into temptation and fail miserably.
  • Whistleblowing - extremely difficult thing to do, the company/government will attempt to discredit your character and make a mess of your image etc. If anyone feels like whistleblowing read a book called "the Whistleblowers Handbook" by Brian Martin. Richard says its a great read."-- COMP1917 08s1 Class.


Cohen, Stephen. 2009s1 SENG4921 Lecture. Audio. 2008 Slides.

Tags: ethics, seng4921.
COMP2121 - Wk02
20th March 2009

This week we learnt some of the things that separate assembly language from machine code in the context of AVR (or should I say AVR Studio).

Important Note 1: Assembly Language

In AVR assembly an input line takes the form of one of these, ([foo] = Optional)

[label:] directive [operands] [Comment]
[label:] instruction [operands] [Comment]
Empty Line

where a comment has form,

; [Text]

Important Note 2: Pseudo Instructions

AVR Assembly (using AVR studio) has some additional commands that are not part of the AVR instruction set, but the assembler (that is part of AVR studio) interprets into machine code.

Pseudo instructions are recognised by their preceding '.' (dot character). eg,

.equ CONST = 31

, will upon assembly go through the code and replace CONST with 31.

Here are the AVR assembly Pseudo Instructions.

Directive Description
BYTE Reserve byte to a variable
CSEG Code Segment
CSEGSIZE Program memory size
DB Define constant byte(s)
DEF Define a symbolic name on a register
DEVICE Define which device to assemble for
DSEG Data Segment
DW Define Constant word(s)
EQU Set a symbol equal to an expression
EXIT Exit from file
INCLUDE Read source from another file
LIST Turn listfile generation on
LISTMAC Turn Macro expansion in list file on
MACRO Begin macro
NOLIST Turn listfile generation off
ORG Set program origin
SET Set a symbol to an expression

.byte - Reserve some space (only allowed in dseg). eg.

  var1: .byte 4 ;reserve 4 bytes and store address in var1

  ldi r30, low(var1) ; Load address into Z low register
  ldi r31, high(var1) ; Load address into Z high register
  ld r1, Z ; Load VAR1 into register 1

...and some more...

.def FOO=r30 ;give register 30 the symbolic name FOO
.equ var = 2 ;like C's #define statement
.set var = 2 ;like a global variable in C

Important Note 3: Segments

There AVR three segments of an AVR assembly program. Also when writing an assembly program you need to be able to specify which segment you are referring to, so you need to declare this using an AVR assembler directive shown in brackets below.

  1. Code Segment (.cseg)
  2. Data Segment (.dseg)
  3. EEPROM Segment (.eseg)

"The CSEG directive defines the start of a Code Segment. An Assembler file can consist of several Code Segments, which are concatenated into one Code Segment when assembled. The BYTE directive can not be used within a Code Segment. The default segment type is Code. The Code Segments have their own location counter which is a word counter. The ORG directive can be used to place code and constants at specific locations in the Program memory. The directive does not take any parameters." [1]

Notes from the Lab

Assembly Code and Machine Code

In the lab we looked at this AVR assembly program,

.include "m64def.inc"
.def a =r16 ; define a to be register r16
.def b =r17
.def c =r18
.def d =r19
.def e =r20
main: ; main is a label
ldi a, 10 ; load 10 into r16
ldi b, -20
mov c, a ; copy the value of r16 into r18
add c, b ; add r18 and r17 and store the result in r18
mov d, a
sub d, b ; subtract r17 from r19 and store the result in r19
lsl c ; refer to AVR Instruction Set for the semantics of
asr d ; lsl and asr
mov e, c
add e, d
inc r21 ; increase the value of r21 by 1
rjmp loop ; jump to loop

The machine code executable produced by AVR studio was 24 bytes long, the question was why. It's actually quite simple, all of the here instructions are 1 word (2 bytes = 16 bits), there are 12 instruction so total 24 bytes. One thing that initially confused me was the weird encoding. Back in 1917 I got the impression that if you have something like mov r16 r17 that this would be represented in machine code as some number for the mov operation followed by two more numbers of the same bit size for the registers. However this can vary depending on the architecture.

For example the mov operation, MOV Rd, Rr has encoding 0010 11rd dddd rrrr. The instruction takes up 6 bits, the source register takes up 5 bits and the destination takes up 5 bits (total 16 bits). The reason that the source and destination bits are intertwined is that it makes things easier on the hardware implementation to do it this way.

The program above has machine code (in hexadecimal),

E00A EE1C 2F20 0F21 2F30 1B31 0F22 9535 2F42 0F43 5993 CFFE

and annotated,

+00000000:   E00A        LDI     R16,0x0A         Load immediate
+00000001:   EE1C        LDI     R17,0xEC         Load immediate
+00000002:   2F20        MOV     R18,R16          Copy register
+00000003:   0F21        ADD     R18,R17          Add without carry
+00000004:   2F30        MOV     R19,R16          Copy register
+00000005:   1B31        SUB     R19,R17          Subtract without carry
+00000006:   0F22        LSL     R18              Logical Shift Left
+00000007:   9535        ASR     R19              Arithmetic shift right
+00000008:   2F42        MOV     R20,R18          Copy register
+00000009:   0F43        ADD     R20,R19          Add without carry
+0000000A:   9553        INC     R21              Increment
+0000000B:   CFFE        RJMP    PC-0x0001        Relative jump

Status Register

Stepping through this program also shows a few of the status registers in use. The Status register, like all the other registers has 8 bits, namely,

SREG Status Register
C Carry Flag
Z Zero Flag
N Negative Flag
V Two’s complement overflow indicator
S N ⊕ V, For signed tests
H Half Carry Flag
T Transfer bit used by BLD and BST instructions
I Global Interrupt Enable/Disable Flag

Last week we saw how signed and unsigned numbers are stored, so if you look at the program above you will see that the last part just increments a register infinitely over and over. Stepping through this shows us what the status register does as we do this. Remember that AVR does all arithmetic in two's compliment.

0 H Z
1-127 H
128 H V N
129-255 H S N

As you can see the values that are negative under the two's complement 128-255 have the N (negative) flag. Also from 127 then to 128 under two's compliment we have gone from 127 to -128, so the V (Two’s complement overflow indicator) flag is indicated. 0 has the zero flag.

The Rest

The lecture notes go over some of the AVR instructions but I think the docs provided by Atmel are fine. What I do think needs explaining (and me learning) is the carry flag and the difference between operations like add without carry (ADD) and add with carry (ADC).

Here is how I understand the carry bit. Say we have 4 bit registers and try to add (in binary) 1000 and 1000, the answer is 10000 however this is 5 bits and we only have 4 bits available to store the result. An overflow has occurred. To introduce some terminology, the most significant bit (or byte) (msb) is the left most bit (or byte) in big-endian (right most in little-endian), and vice-versa for least significant bit (or byte) (lsb). The carry bit (C flag) is the carry from the msb. This can indicate overflow in some cases but not always, it those cases the V flag (Two’s complement overflow indicator) is set.

So getting back to ADD and ADC, ADD will just add the two numbers ignoring the carry bit and ignoring overflow whereas ADC will actually add the carry bit to the result. At least this is what I've observed, though I'm not 100% sure on this.


[1] AVR Assembler User Guide. www.atmel.com/atmel/acrobat/doc1022.pdf


AVR Assembler User Guide. www.atmel.com/atmel/acrobat/doc1022.pdf

Tags: comp2121, computing.
MATH1081 and MATH1231 Cheat Sheets
19th March 2009

Just cross posting my cheat sheets from MATH1081 and MATH1231. PDF and LaTeX source are provided. These are from 08s2, at UNSW. I've released them into the public domain, if that is not legally possibly in Australia then lobby your parliament representative.

math1081.pdf math1081.tex

math1231-alg.pdf math1231-alg.tex

math1231-calc.pdf math1231-calc.tex

Tags: math1081, math1231.
A Letter to the Board of Studies NSW
14th March 2009

Here is a letter I wrote to the Board of Studies (service@bos.nsw.edu.au).

Hello, I'm not exactly sure who I should address this to, so I hope you can pass it along to the relevant person. I am writing to ask that the Office of the Board of Studies considers licensing their syllabi and examination materials under an open content license (such as Creative Commons, GNU Free Documentation License or another open content license). Currently the Board's course syllabi, HSC and SC examinations and Notes from the Marking Centre are licensed in a way that prevents redistribution and derivative works. The current status of the copyright licenses hiders students and teachers ability to use the syllabi and examination materials for study through sharing and collaboration of content. For example it is to my understanding that students, teachers and anyone else cannot take all the syllabus "dot points" and annotate them with their own content, and republish this for the benefit of others. Similarly the current licence prevents use of syllabus extracts such as "dot points" for collaborative works using modern web tools (such as wiki's). Please note that I have published this letter on the internet (http://andrewharvey4.wordpress.com/2009/03/14/a-letter-to-the-board-of-studies-nsw). If you agree to any reply to this letter to be posted online (with credit of course), please let me know otherwise I will not publish any reply. Thank you for you time, Andrew Harvey (Past HSC student, Currently University Student)

(EDIT: A related post, http://andrewharvey4.wordpress.com/2008/12/24/board-of-studies-nsw-and-their-syllabi-copyright-license/)

Tags: board of studies nsw, copyright, education, hsc.
COMP2911 Wk 01
14th March 2009

A few random things I've picked up this week that I think are noteworthy.

To my understanding,

Some indicators of Good Design,

Some indicators of Bad Design,

Eclipse and NetBeans are both IDE's. They pretty much do the same thing. Though NetBeans is made by Sun.

I think these two slides from Potter's notes sum things up nicely.

point_class_annotatedpoint_annotatedAn extension of this point class is, (the arrows show which variables java is refering to)

point_class2And some sample code to use this class,

   Point p = null;
   p = new Point(1, 2);
Tags: comp2911.
An old memory of Linux
13th March 2009

I only started using Linux when I started Uni (2008). I knew nothing about it prior to this. I had heard of it but that is all. I now wish I'd become aware of it sooner but then I realised I had the chance. A friend of mine introduced me to it in year 10 (2005) and I even got an Ubuntu 4, 5 or 6 CD (I can't recall which one). But I never used it. Why not? Well, it occurred to me that Windows was the sole reason for me not at least testing Linux out. I had had some bad experiences with some Windows operating systems and installing windows operating systems. So I had the thought "I don't want to risk breaking my computer/loosing things again with another OS install" just to test this Linux thing out. Huge mistake! Though at least I've learnt from this experience and I'm trying to try things out and give them ago before I just assume them to be poorer quality or choosing not to use them.

One of the best pieces of advice that I would give is to try new things out, if you don't try it you won't know what your missing. For if I was always too afraid to try new things out I would still be using Windows 95.

Tags: computing, linux.
Tales of Dvorak - Part II
13th March 2009

A while ago I posted My Tale of the Switch to the Dvorak Layout. I've realised that some things have changed since then.

I just did the KTouch training session where I took 61 seconds to style 228 characters (38 words) which equals 216 characters per minute or 37 words per minute. T I had an accuracy of 97% (6 mistyped characters). Hopefully when I find the other sessions that come with KTouch I will be able to get some more data.

Mostly I can type without looking at the keyboard, hoverer as I'm still learning there are occasions when I needed to look at the keyboard. This is okay, it slows my down but its not bad. The problem is when I'm in the CSE labs I'm typing in Dvorak on a Qwerty keyboard so when I go to look down at the keyboard (as this is a habit I've gotten into when I get stuck) I get completely lost. And I end up pressing 5 different keys until I find the one I want.

I have a prac exam in June, so I better either hurry up and get better at Dvorak or go back to qwerty and get familiar with it again. Otherwise my prac exam may not go so well.

A few days ago I would have said that I type by remembering were specific letters are, but typing now it seems that's not the case and my hand movements just come naturally without thinking too much. So it looks like I'm improving.

I don't want to try tying in qwerty as that seems to really stuff things up badly for me.

Tags: dvorak.
SENG4921 - Lec 01 - Theoretical Underpinnings of Ethics
13th March 2009

Today's This week's lecture for SENG4921 - Professional Issues and Ethics was given by Stephen Cohen of the School of History and Philosophy, UNSW. The lecture title was “Theoretical Underpinnings of Ethics”.

It was a very interesting lecture for me, and I thought it was presented very well. You can find his lecture slides from last year here, and the audio here.

This post is basically a summary of the notes I made in the lecture, so you should be able to follow though the slides as its in chronological order. I've mixed in my own interpretation so it may not be the case that this is exactly what Cohen said and/or meant.

Relativism is doing what the culture is doing just because everyone else is doing it. This is does not make it right. For example say you go to another country where bribery is common. This does not make it right. Nor does the line of thought "everyone else is doing it so it must be okay".

For example if you bump into a parked car and dent the other car's bumper your thinking here is focused on answering the question "What should I do?". However if for example you are asked to list some important moral characteristics your thinking here is focused on answering the question "What kind of person should I be?".

These two questions are the underpinnings of ethics.

You don't always end up doing what you think you should do.

"What kind of person should I be?" relates to a "Code of Ethics". This is what the employees or organisation are. "What should I do?" relates to a "Code of Conduct".  This is what the employees or organisation should do.

When we talk about ethics we mean prescriptive ethics. This is what you should or ought to do, compared to descriptive ethic which is what people do do.

Morals and ethics are really the same.

Ethical is compared to (i.e. very different to)

To borrow a diagram from Cohen's slides,


Rules, consequences, professional code, law, loyalty to your employer, confidentiality, requirements of your role, etc. all factor into ethics.

Rules and consequences are requirements of morality of an individual (private morality), the other is public morality which comes into play when you occupy a role, it is mediated by the institution.

and another diagram,


I think this is the foundation of a lot of Cohen's message.

Cohen's advice, "be aware of these things".

"At work, you don't leave your private, personal values at the door!"
"Your ethical values must be there."

All these things often conflict, but you must make a decision. You may ask "Who's to judge" these things. The answer is always "You, as an individual." (from whatever perspective whether it be legal, ethical...)

I feel this is a key and important part of the lecture, and I know that this is not easy.

You have an obligation to your employer, at the same time you have your own ethics which may conflict. Would you do something you think is unethical just because you don't want to lose your job? I don't know what I would do...

Cohen makes another good example. Say there was a rule that said all motor vehicles must stop at a stop sign. But what about police who are chasing a criminal. What about an ambulance. What about people rushing someone injured to the hospital. As Cohen puts it, the right thing to do in all these cases is to run the stop sign. But we will continue to find more cases. The rules cannot cover them all.

The point he is trying to make is "you can't clear up ethics stuff with more rules." You need to make an ethical judgement.

I agree with this. Though this sounds like a tough legal issue. Who would be the judge of the ethical judgement? What if you broke the law in order to do what you thought was ethical? Would claiming you made an ethical judgement hold up in a litigation suite? I'm guessing not.

Another good example Cohen gave was the "dead man's break". As it was told State Rail implemented the dead man's break in it's trains, so if the driver got off the seat a break would be applied. The drivers didn't like this so some disabled it. As a result a train crashed because of this. So what did State Rail try to then do, they tried to make a fool-proof break. This doesn't work.

Whistleblowing - As Cohen puts it, the whistleblower almost always suffers. Its something that you are never obligated to do.


Cohen, Stephen. Theoretical Underpinnings of Ethics. 2009. SENG4921 - Professional Issues and Ethics Lecture 1.

Tags: ethics, seng4921.
COMP2121 - Wk01
13th March 2009

Just some reflections on the first week of my 09s1 COMP2121 Lectures and other materials. I will base a lot of this material on the course lecture notes by Hui Wu. Actually if you read this and the lecture notes you might see that they are pretty much identical.

The 4917 Microprocessor

This first lecture clarified a lot of the things I'd learnt about low level computing in COMP1917, which was good. Back in COMP1917 we were introduced to the 4917 microprocessor (a hypothetical designed just for this course). It was 4bit, has 16 memory locations and 4 registers (instruction pointer, instruction store, general register 0 and general register 1). Each memory location could store a number between 0 and 15, and there were 16 instructions.

It had a simple start up (registers set to 0, all memory locations set to 0, fetch-execute cycle begins), and a fetch-execute cyle,

So for example the following 4917 machine code program would print 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15.

8 0 3 11 1 15 0

This is understandable but was difficult for me to tie into my desktop computer level, for instance the CPU and the RAM. This became a bit clearer today.

The Von Newman and The Harvard Architectures

Two main computer architectures include the Von Newman Architecture and the Harvard architecture. The hypothetical 4917 from COMP1917 was a Von Newman Architecture because both the program and the data were stored in the same memory. (It seems that processors like the Intel Pentium 4, Intel Core 2, etc. use this architecture)


Another key thing is the Arithmetic and Logic Unit (ALU) and the Control Unit are collectively called the CPU (Central Processing Unit). A microprocessor is just a CPU on a single chip. A microcontroller is basically a computer on a chip, so the CPU, memory, etc. are all on a single chip.

I learnt a lot from experimenting with this architecture and the 4917 (and its successors). Though when I began to write more complex programs I found myself constantly putting a GOTO instruction number n command at the very begining, and using that skiped space as memory for data. I also came to see that this architecture allows for the buffer overflow vulnerability as program data can be executed as instructions if there are vulnerability. These two observations tend to lead to the Harvard architecture (which I am new to).


This is the architecture used for the Atmel AVR microprocessor, which is what we will focus on in this course (I think). I'll come back to this when I talk about address space.

Computer Memory

This is the computer memory hierarchy diagram from the lecture notes.


This helps put a lot of my misunderstandings of how the 4917 from COMP1917 relates to modern processors, as I didn't quite see if the instructions and data were stored in RAM or on the CPU. But really this is just an implementation issue so it didn't really matter to the 4917.

In the CPU there are registers which are really fast, but there are few (apparently in x86 (eg. Pentium, Core 2) there are only 8 integer and 8 floating point registers). Then there is the cache (on chip memory), this is what that 4MB cache that I see advertised that my CPU has. This cache can be separated for program code and data. This is faster that reading from RAM (the off chip memory), so currently active program code is moved to here from the RAM when necessary to speed things up (this is apparently implemented on the hardware level (which is always nice for a software developer ;) ). Then there is off-chip memory and auxiliary storage. This fits in nicely with the picture I get when I open up my computer.

The material on the types of RAM and ROM in the lecture notes needs no further commentary, so I'll skip that part.

ISA (Instruction Set Architecture)

"ISA is the interface between hardware and software

This sums up the situation nicely, and makes perfect sense.

There are 4 things that make up memory instruction set architectures,

RISC - Reduced Instruction Set Computer CISC - Complex Instruction Set Computer

Atmel AVR is RISC.

Number Systems

Problem: How do we represent negative numbers in a computer? 4 main methods (from Wikipedia).



It is important to know that the hardware does all arithmetic in 2's compliment. It is up to the programmer to interpret the number as signed or unsigned.

To convert a number from 2's compliment, for example -45 in 2's compliment is 11010011, we can do something like this,

$latex 1 \times (-2^7) + 1 \times 2^6 + 1 \times 2^6 + 0 \times 2^5 +1 \times 2^4 + 0 \times 2^3 + 0 \times 2^2 + 1 \times 2^1 + 1 \times 2^0 = -45$

To go the other way from say -1 to the 2's compliment form 11111111 we use that $latex 2^p - X$ formula. I'm not exactly sure how its supposed to work so I've hacked it to make it work.

If the number you wish to convert is negative, let $latex X = -n$, so that X is positive then take $latex 2^p$ where p is the number of bits you are using (say 8), then subtract X. If the number to convert is less than $latex 2^p$ (where p is the number of bits, say 8 ) then leave it as is and that in your 2's compliment.

Now that was complicated. But its the only way I can get that advertised $latex 2^p - X$ formula to work with the given set of sample data (as in that table above).

This raises an issue for comparison operations. eg. Is 1111 1100two > 0000 0010two? If those two numbers are unsigned then YES, if they are signed thin NO. As such the hardware uses the S flag in AVR to indicate the result of the signed comparison, and the C flag to indicate the result of unsigned comparison.

Representing Strings. We saw one method back in COMP1917 though its nice to see that the other methods that come to mind were used also.

  1. 1st position of string reserved for length (Pascal)
  2. an accompanying variable has the length of the string (as in a structure)
  3. last position of string marked with a special character (NULL in C)

Sign Extension

How do we extend a binary number of m bits to an equivalent binary number of m + n bits? If the number is positive add n 0's to the most significant side (usually left) of the binary number. If the number is negative add n 1's to the most significant side of the binary number. This is called sign extension. To add twe binary numbers of different lengths just sign extend the shorter one so that both numbers have the same bit length then add as usual.


Wu, Hui. COMP2121 09s1 Lecture Notes.

(Updated 20th June 2009 with explanation of 2's compliment conversions and sign extension)

Tags: comp2121, computing.
Patents in the Digital Age
13th March 2009

I was just reading this (which coincidently seems much better written in terms of style and content than what I write here on my blog),

"In my opinion, copyright and patent laws are entirely suboptimal, especially with regard to the digital side of things. The concept of a patent is a noble one -- that is, it allows the inventor of some concept to be protected by the law for a certain amount of time in the production or implementation of that concept. Before patents, inventors would hold their ideas very close to their chests, so nobody could steal them. They'd make a killing selling whatever it was they invented, then take their secret to the grave. Obviously the loss of knowledge is regrettable, but there was no way to let future generations benefit from the invention without giving away its secrets (and thus, your rights). Enter patents. The concept behind patents is that they provide protection for the patent holder for a time, given that he describes it in enough detail for his idea to be replicated. This solves the problem at hand quite neatly: the inventor keeps a grip on his invention, and is given ample time to monopolise upon it. If the inventor were to pass away, the knowledge is retained and can be referred to in the future. The period during which the patent can be enforced is, in most cases, 20 years. But, wait -- if we're to apply such a law to computer programs... when was the last time you used a 20-year-old piece of software? When was the last time you used even a 7-year-old piece of software? Probably about six years ago. Patents are still a good idea in software, but the patent term needs to be drastically reduced for it to apply sanely. 18 months, at a maximum." --http://nornagon.livejournal.com/27709.html

It got me thinking, patent law was really designed for a different age where you invented things such as the telephone and the Rubik's Cube. Patents documented the inner workings of the invention and how to build it. Thus after the patent owner has made some money from their invention and it falls into the patent equivalent of the public domain anyone else can make it and build upon it. Enter the digital age where generally copyright is used to protect computer software rather than patents (I've heard of software patents, but they don't require submission of source code). Copyright was intended to protect creative works where there are no "inner workings" or "instructions" needed in order to build it. Given the fact that most (maybe not most, but lots of) software is written in programming languages that get compiled into machine code, computer software needs these "inner workings" and "instructions" i.e. the source code in order to build upon it once the original creators have made some money.

There are two problems here with the fact that software falls under copyright rather than patents.

  1. When the protection expires there is no method to ensure that the source is published, and
  2. secondly copyright laws currently last life + 70 years. In some cases this could be 160 years it takes for the copyright to expire. By then the technologies would have most certainly changed and the software would be of no use (even if the physical storage medium has survived that long (though I think laws now allow copying for backup)). As suggested in the quoted article above a reasonable protection length would need to be less. I think 2-3 years, but really an experienced team of worldwide economists would be able to come up with this figure much better than I could. This would, I think, push innovation forward as software creators would need to come up with new things in order to continue the income stream.

But what if the government's were to introduce some new patent laws that tried to put computer software under patent laws rather than copyright (yes I know that's a semantics issue, but I'm referring to the current laws). Well lets say that the law said that you will only have protection for your computer program if you give us the source which we will lock up and then release after a few years. Despite the fact that you would need to employ a lot of patent officers, I don't think this will work because,

  1. its hard to tell if the source that was provided really was everything for the program (i.e. manual checking would be needed.)
  2. you could argue that machine code is the source (i.e. say you wrote the program in machine code when you really used C++)
  3. that creators will just say "okay we don't need protection from the law, we won't use patents, we'll just implement our own DRM and skip your patent laws". This is even worse as it locks up the program for as long as it takes to crack the DRM.

Another key thing is that even in the time of patents if you bought a product that was protected under patent law, you were still allowed to make changes to it. For example if you bought a Rubik's Cube and if it was protected by a patent, the law could not stop you for example pulling it apart to see what it looks like on the inside, or writing some numbers on the outside squares. However now in the digital age and particularly with the DMCA you cannot even do this (though I don't think Australia has any law that is equivalent to the DMCA that restricts you circumventing DRM). In these time it is apparently illegal for you to open up and change your own products that you have purchased and own.

Tags: copyright, law.
A problematic HSC ITG Question (2001 Q5a)
11th March 2009

I discovered this back in 2007 when I was preparing for my HSC exams.

Here is the question (from the exam paper here),

[caption id="attachment_310" align="aligncenter" width="450" caption="2001 HSC ITG Q5a"]2001 HSC ITG Q5a[/caption]

Firstly I think this question is beyond the scope of the syllabus. The only relevant dot point says,

"Pictorial drawing
  • isometric
  • perspective (mechanical and measuring point)"

There is no reference to oblique drawing or oblique projection (this was the official answer).

Secondly, and more importantly the examiners say in their Notes from the Marking Centre, "This part was generally well answered; candidates had little trouble in identifying oblique and perspective projection."

They claim that the first one is oblique projection, yet with just the information given its impossible to determine the projection used. For example the drawing given could be of a cube drawn in oblique projection or it could be of another object (shown below) in isometric projection, or some other object in some other projection. There are infinity different projections that it could have been drawn in.

[caption id="attachment_311" align="aligncenter" width="450" caption="An object (I call a Vube) shown in 3rd angle orthogonal which when drawn in isometric looks like a cube in oblique."]An object (I call a Vube) shown in 3rd angle orthogonal which when drawn in isometric looks like a cube in oblique.[/caption]

[caption id="attachment_312" align="aligncenter" width="450" caption="Vube shown in perspective."]Vube shown in perspective.[/caption]

The exam paper should have specified that the object in question is a cube.

Tags: graphics, hsc, industrial technology, technical drawing.
Another example of copyright being used for censorship of views (FreeView Ad)
9th March 2009

I've just read this article http://smh.com.au/news/technology/biztech/youtube-yanks-freeview-parody-clip/2009/03/09/1236447116498.html and viewed this video (though that link may not work in the future) http://www.youtube.com/watch?v=Q9JGdE-p4dQ.

On one side of the argument, companies are yet again using Copyright laws (which were originally designed to create incentive to create the work in the first place (though I'm not saying that that is true for our current laws, nor it should or should not be true (I'm not an academic...)) to hinder or stop speech. This is the opposite of free speech, this is censorship. I think that in this case this derivative work should be legal. I don't think that simply because one side does not like or agree with the views of another they should be allowed to censor the others argument. If this were so, then we could not debate an issue very easily.

Despite this I do understand the other side of the argument. They have copyright in a video, and they have not authorised this reproduction of the video. Full stop.

This is where I think the current copyright laws fail. But I can't see a simple solution in sight. Creative Commons helps, but only for works that creators have chosen that (or a similar) license. On one hand this sort of derivative work should be allowed, on the other if this use were legal what would then be stopping some one taking a full length feature film, adding a small logo to the bottom (similar to what TV networks do) and then claiming it is a derivative work and hence distributes it freely to all, counter with the copyright owner of the original work who is trying to get some money back to cover their expenses of the creation of the work. This is a tricky question because its a very subjective line that splits these two examples, so it would be difficult to have a law that works for both these cases.

Should this derivative work simply be allowed because the original work was freely distributed? I think not.

A concept I explored in this post, in my view would allow both parties to win, though unfortunately I don't see this type of economy becoming the main any time soon.

Though probably not a valid argument, but the video (not the audio) in question was a commercial. It was made in an aim to get as many people as possible to watch it. Pushing organisations to stop re-distributing it seems a bit against what the ad was made for doesn't it?

Tags: copyright.
My Boot Times
7th March 2009

My Boot Times... (so that I can compare them with 9.04 when it comes out)

Ubuntu 8.10

0.00 Power on
0.06 Start GPU Memory Test (512MB)
0.15 Start Motherboard Loading Screen
0.22 End Motherboard Loading Screen (shows some hardware config)
0.30 GRUB Menu Displayed
0.32 OS Load (I have GRUB set on a 2 sec timeout)
1.15 Login Screen Ready
1.55 GNOME Desktop ready with taskbars loaded (OS loaded and responsive)

Windows XP

0.00 Power on
0.06 Start GPU Memory Test (512MB)
0.15 Start Motherboard Loading Screen
0.22 End Motherboard Loading Screen (shows some hardware config)
0.30 GRUB Menu Displayed
0.32 OS Load (I have GRUB set on a 2 sec timeout)
1.17 Login Screen Ready
1.47 Background Loaded
2.02 Taskbar Loaded
2.17 OS Fully Loaded and Responsive


Hardware Level  - 24 sec
GRUB            - 6 sec
XP OS Level     - 1 min 45 sec
Ubuntu OS Level - 1 min 23 sec
Tags: ubuntu.
Some thoughts on Feed Readers
3rd March 2009

I currently use Google Reader to subscribe to and read RSS and Atom feeds. It has pros and cons.

One of the great things about Google Reader is that its entirely in the cloud. I can access it wherever I am, whichever operating system I'm using. Also as its run on Google's servers, they pay the bandwidth bill not me. I subscribe to lots of feeds (181 as of now) but I don't read them all all the time. If I don't want to read some high volume feeds I don't open them and they don't get downloaded to my machine. This also means that its Google that checks the feed for updates all the time, not my machine. And that's the beauty of using a cloud based feed reader. Google only has to download the feed 1 time for all the subscribers of that feed in Reader, not once for each user.

This is the sole reason I use a cloud based reader, and this pro is too great to get me to switch. Unfortunately there are some things that I don't like about reader and some things I wish I could add. That's the bad thing about using a cloud service like this, I cannot edit the code for my needs. Open source desktop applications can, but with Google's cloud services you cannot.

Its good that in Reader you can download a list of your subscribed feeds, but I wish I could also download the feed items themselves in bulk. There is a copyright issue here that being, from what I've experienced when you subscribe to a new feed in Reader you can view the past postings going back probably to when it was first indexed, despite these items no longer being in the feed. I want to be able to download those too. I guess since you are already downloading them when you view them this is the same, so its not a new issue.

This is turning into a debate about cloud services vs. desktop software, so I'll stop here.

Tags: computing, google.
RE: RailCorp targets rogue iPhone app (ZDNET.com.au)
3rd March 2009

So I just read the article over at ZDNET.com.au. Sadly this sounds all to common. I recommend you read the article for yourself.

This is terrible news.

I don't know the legal status of whether RailCorp would win if they went to court, but either way this in more evidence of Australia's poor Copyright laws. The fact that government created facts that are not creative works can be protected by copyright is absurd. Dispite numerous reviews (Crown Copyright Law Review 2005, Review of The Nation Innovation System (though the Government is still reviewing the findings of this one)) nothing has changed.

As the article states, "A 2005 inquiry by the Copyright Law Review Committee recommended relaxation of Crown copyright provisions to allow for more easy access to public interest information, but those changes have yet to be implemented and RailCorp is standing by its challenge.". This inquiry was done in 2005, it is now 2009 so its safe to assume that the Government is not willing to change the laws in light of the recommendations.

They say that they are using copyright laws to protect people from information that may be false. That is a poor argument. The public know this, they know that this is a service provided by a third party and that it may not be accurate. This works because if there are too many problems with it for what the consumer is happy to accept they will simply not use this. This is no excuse to stop people using/republishing/remixing facts.

I always thought that copyright laws were there in order to create incentive for the original creation of a creative work. Thought I think that this is more of a US constitutional or outdated view. I do not necessarily agree with this, and I don't think that is the sole reason we need copyright laws. But obviously that is not what the copyright laws are doing in this case.

I'm just hoping that the Department of Broadband, Communications and the Digital Economy fixes crown copyright soon before this mess continues.

Tags: copyright, law.

RSS Feed