INSTRUCTOR PARTICULARS

Instructor:Robert TrenaryOffice:B250CEAS

ComputerOrganizationSpring 2015

Tues– Thurs C124

11:30- 12:45, ,1:00 – 2:15

Office Hours: Tues–Thurs 2:15 – 5:00 (except when Department Meetings)

E­mail:

Required Materials:

Written, video, and linked materials willbeavailableat

A text “MSP430 Microcontroller Basics” by John Davies, ISBN: 978-0-7506-8276-3, from Elsevier or Newnes is excellent and will be referenced often. There is a wealth of online resources some of which are linked on my page. You will also purchase a kit consisting of the Texas Instruments “Launchpad” (about $ 50) and peripherals which will be handled through the Computer Club. You also must have a laptop running some Unix variant (Ubuntu , OS-X).

GRADED EVENTS:

Programmingassignments(30%)Generallythereareno lateassignments.You willbewisetoplantosubmitacompletedprogramordocumentedevidenceofprogress.Imaygivesome quizzes,which willcount inthisportionofthe grade.

  • MidtermExams(30%):ThefirstoftheseistentativelyscheduledasThursdayofweek 7.
  • FinalExamination:(35%)Asperfinalsweekschedule,

COURSE GOALS:

  • Understand the organization of a computer system from processor up to application level. This includes a detailed description of program structure on the MSP430 including the use of interrupt handlers.
  • Understand the software creation process from source to object to executable, and the way that high level language features such as arrays are mapped to a particular architecture.
  • Understand the Von Neumann (stored program) architecture and issues of bit level representation including instruction format , 2s complement , floating point.
  • Develop working mastery of programming in a C / Unix environment including the use of utilities such as make and gdb.

The above will be accomplished by writing programs in C and assembly language for both the MSP430 and a general C / Unix environment.

Measurable Student Outcomes:

  • Interpret and compute signed and unsigned values, given bit patterns represented as binary or hex, noting overflow conditions.
  • Develop C programs in a Unix environment using gcc, make, and gdb.
  • Write programs with both C and MSP430 assembly source for the MSP430 microprocessor.
  • Design a small application for the MSP430 that includes interrupt handling and peripherals for both input and output.

FIRSTSETOFGOALS:

Youshouldmake yourself responsible forthefollowingskills:

1) Beabletoconvert between thefollowing basesystems: 2,8,16,10.Generally,?.??=?.?10

2) Beabletoadd and subtract values represented inthosebases.

2)Given a fixednumber of bitsand a representationscheme asin 2)beable to statetherange ofvalueswhichcan berepresented, in both asigned andunsignedrepresentation.

3)Beabletowrite a simpleCprogram(asopposedtoC++). Know printfand write inC,and howtoimplementcall byreference.

5) Simplenavigationof Unixenvironment: editfiles,login remotely ifnecessary,script files,redirectinput andoutput.

CS223Helpful Hints

These comments are meant to help you work successfully in my course. Each instructor has style, practice, andidiosyncrasies.Here aresomesuggestionstodealwithmy version ofCS223

R.Trenary

I)Waysinwhichyouwilllearninthis course.

A)Lecture Notes

Theregularclassmeetingswill bepresented using chalkboard,verballecture. My handwritingisnotwonderful,and thematerial presented in lecturewill,asmuchaspossible, be drivenbyinteraction withstudents.Thismeans that notesmaynot be immediatelyorganized when you first createthem in class. Myadviceis toCopy Your NotesWithin 24 Hours.Theywillthenserve as agood resource,makeyou rethinkthelecture, and prompt good questions.

B)Questions

Iamquiteannoyingabout thisissuebecauseIbelievethatthebeststudentsaggressivelymakecertainthattheyarefollowingthelecture.Youcanaskanyquestionabout“AnythingAtAllInTimeOrSpace”andwillfindAAAITOSontheagendaatthebeginningofeveryclass.Ihavetaughtthisclassoftenenoughtoassureyouthatastudent’squestionalmostalwaystouchesonideasthatotherstudentsarewonderingabout.Soaskearly andoften.

C)Independent/SmallPrograms(“Lab”)

ComputerScienceandCS223focusonusingcomputerstosolveproblems.Youareencouragedtogetinthehabitoftestingideaswithsmallprograms.Thiscanbedoneto learnaboutstatementsinalanguageortotry totestwith experimentquestionswhichmay arise.

II)Terms. Some phrases

NotaBene(latin) abbreviatedNB.“NoteWell”. “This is important”

Molto Bene(Italian),MuyBien(Spanish)loosely,“very good”

i.e.“that is”

e.g. “forexample”

AAAITOS-“AnythingAt AllInTimeOr Space”

III)Grading

Theallocationofamark(‘A’,‘BA’etc.)fortheworkinthecourseisdoneonce–whenthegradesheetsarefilledoutattheendofthecourse.Untilthattimethereisonlydata,generatedfromexams,programsetc.Thatdataisprocessedintoasinglenumberbyweighting(exampointsareweightedmostheavily).Thosenumbers

areusedtocreateahistogram.Thathistogramisthenorganizedintogroups(‘clusters’)whicharethenlabeledwith thetraditionallabels‘A’,‘BA’,etc.).

Mygoalwillbetogetawidedistributionofperformancesothattheclustersarewelldefined.Iwillexercisesubjectivejudgmenttolabelthedatapointsthatarenotclearlyinagroupandtodeterminethelabelforagivengroup.Pleasekeepanyexamorprogramthathasbeengivenagradeincasethereisanyquestionaboutgrades.

C LinkingandLoading

C language topics:Source,object,executable. C specificthings: printf, pass by ref,logicals, (shiftsandbitwiselogicals),write?. gcc–c, gcc – o, Separatecompilation of sourcecode.

Compiling,Linking,Loading

Thecreationofcomputerprogramsinvolvesthetranslationoftheprogrammer’sidea(thealgorithm)andexpressedinaprogramminglanguageasasourcefileintoastoredprogramexecutedonsomecomputer.Thetransformationsarecalledtranslation(compilation),linking/loading,andexecution.

InourenvironmentthesourcefileforaCprogramistypicallynamedas<something>.c.SoafilemightbecreatedusingatexteditortocreateafilecalledMySourceFile.c.Thisfileisfirsttranslatedusingthegcccompiler;gccisactuallyascriptthat invokes thewholeprocesstoatetherunning program.Ifwewant totake only thefirststepwecan use thecommand

%gcc–cMySourceFile.c

andwe willcreate afilecalledanobject file whosenameisMySourceFile.o.

Theobjectfileisafilewhichcanbelinkedtogetherwithotherobjectfilestocreateaprogram.Itisimportanttonoticethatotherobjectfilesmay bedrawnfromsourcefileswrittenindifferinglanguages.Wewilldo this byhavingC mainprogramscombinedwithSparc assemblylanguage functions,andviceversa.

Object filescan be combinedusing gcc as in

%gcc MyCSourcefile.oMySparcSourcefile.o

wheretherearesourcefilesnamedMyCSourcefile.candMySparcSourcefile.s(whereSparcassemblylanguagefilesarenamed .sby convention).Theresultofthecommandabove willbeanexecutablewhichis,by default,calleda.out. Then thisexecutablecan berun by merelyinvoking itsname:

%a.out

Notethaterrorscanoccurateachstep(translation,loading,execution).Errormessagescanhelprevealwhatstageoftheprocesshascausedtheerror. Forexample,aloadingerrortypicallyhasanerrormessagefrom‘ld’theprogramthatactuallydoestheloading.

C Language

TheCprogramminglanguageisasubsetofC++withafewexceptions.WewilluseCinthiscoursebecauseitsimplifiestheprogrammingenvironment.There arefeatures of C/C++ whichyou may nothave seen. The sectionsbelowwill deal withsomethatwe will need.

GeneralStructure ofC program

Thetext fileforaCsourceprogram is similarto a C++program.Typically there will beastatement

#include<stdio.h>

andnot theinclude used inC++ programs.

There shouldbe prototypesfor allfunctionscalledbelow main,andyou arewarnedthat main should bean intfunction.

Inallfunctionsthevariablesmustbedeclaredbeforeanystatementsthatusethem.Thus,theC++practiceofdeclaringforloopindicesintheforloop i.e.for (int I=0;…)willnot beallowed inC.Theloop variablemust bedeclaredbeforeanyexecutablestatement.

PassBy ReferenceViaPointers

Theparameterpassing inC hasonly onemode:passby value.RecallthatC++has bothpassby valueandpassby reference.Thisdistinctiongovernswhethertheargumentwhichispassedcanbemodifiedinthefunction(passbyreferenceallowssuchchanges).SinceChasonlyapassby valuemodeandthusthereneedstobeawaytoeffectapassbyreference.Thisisdoneby usingpointervariables.The pervasive useofpointers in C is a result ofthis necessity.

Anexampleoftheuseof pointerstocausepassbyreferenceis shown below:

#include<stdio.h>

voidswap(int *, int *); /* a functiontoswaptwovariables */int main()

{int x,y;x=6;y=7;

printf(“beforetheswapx=%dy=%d\n”,x,y);swap(&x,&y);

printf(“aftertheswap=%dy=%d\n”,x,y);

)

voidswap(int *x, int *y)

{int temp;temp =*x;

*x =*y;

*y =temp;

}

TheprintfstatementsareexamplesofoutputinCsincewedonothavecoutfromC++.Wewilluseprintfforoutput.Seebelowforitsparticulars.TheexampleaboveistheonlyreasonablewaywecancauseaswapfunctiontobewritteninC,sincepassbyvalue is thedefaultparametermode.

printf

Theprintffunctionisusedtocreateoutput.Itisafunctionwhichhasparameters.Thefirstoftheseiscalledaformatstringandisastringvariable.Embeddedwithintheformatstringareformatdescriptors(e.g.%d)andescapecharacters(e.g.\n).Theformatstring specifiestheoutput, literally,exceptfortheformat descriptors which describetheway in whichvaluesaretobeoutput.Thevalueswhichareoutputaretheotherparameterstotheprintffunction.Intheexampleabovetheyarethevaluesofxandy.Theformatdescriptor%dsaystooutputthevalueasasigneddecimal.Otherformatdescriptorsinclude

%u(unsigneddecimal),%x(hexadecimal), %s (string),%f (float).The escapecharacter \n is equivalenttonewlinein C++.

Thus theoutputabove is

beforetheswapx=6y=7aftertheswapx=7 y=6

Tounderstandthewayin whichformatdescriptorsworkconsidertheoutput fromtheprintfstatementprintf(“%x%u%d “, -1,-1,-1);

Notethat theexpressionswhichareinterpreted viatheformatdescriptors do not need tobevariables.Theoutputabove is

0xffffffff 32-1

Thereasonsforthisoutputrequireus toconsidera numberofspecifics about themachines on whichyou runyourprograms.

[ToBeContinued]

Conversions

From \ To / 2 / 8 / 10 / 16
2 (Binary) / Group 3 Bits,MaptoOctalDigit
(Right to Left) / Formula1 / Group 4 Bits,MaptoHexDigit
(Right to Left)
8 (Octal) / Mapeach octaldigit to 3bits / Formula1 / 8216
10
(Decimal) / DivisionAlg / DivisionAlg / DivisionAlg
16(Hex) / Mapeachhexdigit to4 bits / 1628 / Formula1

Vdi

*bi

i0,/1,/2,...

I)

Place Value Systems represent a number V as a

sequenceofdigitsdndn­1…d2d1d0.d­1d­2…whereabaseb,apositiveinteger,isunderstood,andisusedtocomputethevalueassociatedwiththedigit.Thevaluesarepowersofbwhichcorrespondtothesubscriptsabove.b0=1andb­n=1/bn.ThevalueV of a placevalue numeralcan becomputedthe equation above called Formula 1.

Notethatthedigitscanbe0andthenumeralcanhavearbitrarylength.Butwetendtosuppressleadingandtrailing0’sinplacevaluenumerals.Sowewrite4,196.25andnot0000004196.250000000.(Thecommahasnomathematicalmeaning).Noticefurtherthatthedigitsarelimitedbythebasetotherange0,…,b­1(besureyouseewhythisistrue).Notealsothatwhenour base isgreaterthan10,weneedtoinventnewnamesfordigits. So hexnumbersrequiresymbols0,1,…9,A,B,C,D,E,Fto representthe 16digits.

II)GivenNbinarydigits,thereare2Npossiblenumeralswhosevaluesrangefrom0to2N­1.Thereisanatural1­1correspondencebetweenthenumberofdigitsinabase=2N,

e.g.16=24,andNdigitbinarypatterns.Thuseveryhexdigitnaturallycorrespondsto4digitbinarynumeral.Thiscorrespondenceallowsmorecompactdescriptionofbitpatternsusinghexnotation.

III)WhenavalueVisdividedbyabaseb,theremainderrepresentsthedigitd0.Successiveapplicationsofthisfactwillyieldthedigitsd0,d1,d2….untilthequotientbecomes0.Afterthatpointthedigitscorrespondingtoleading0.’sinthenumeralVrepresentedinbasebasdndn­1…d2d1d0.Thisprocessistermedherethe‘divisionalgorithm’.

IV)WhenavalueV,whichislessthan1,andrepresentedas d­1*b­1

d­2*

b­2…+dn

*bn…is

multipliedbythebaseb,theresultingvaluewill=d­1* b0

d­2*

b­1…+dn

*bn+1.Thenet

effectofsuccessiveapplicationsofthisruleisthatanumerallessthan1canbeconvertedtoanarbitrarybase.Moresimply,thisletsyouconvertadecimaltoanarbitrarybase.