CSC362.01, Class 3: Sample Source and Target Languages Admin: * Homework questions? * Run for SGA senator. Applications due at 5:00 p.m. today. * Cool convo Thursday. Extra credit for attending. * Watch Sam suffer on a panel Thursday evening. * Extra credit: 1/2 point for each activity; capped at 3 * There are 100 points in my class Overview: * More on Pascal * Goals for this week * What is assembly? * PAL, A pseduo-assembly language More stuff on Pascal you should learn * Structured types * Looping structures * Procedures and functions Basic types in Pascal * integer * real * Boolean * char Compound types in Pascal * Enumerated type weekdays = (Monday, Tuesday, Wednesday, Thursday, Friday); * You may not reuse names in enumerated types * Arrays array[lb..ub] of type workload = array[Monday..Friday] of integer; whatever = array[10..20] of char; samswork: workload; samswork[Monday] := 10; * Records (structs; procedure-less classes) person = record lastname: ...; firstname: ...; end; * String is normally a synonym for "packed array of characters" Loops: for VAR := INITIAL_VALUE to ENDING_VALUE do STATEMENT for VAR := INITIAL_VALUE downto ENDING_VALUE do STATEMENT for VAR := INITIAL_VALUE to ENDING_VALUE step STEPVAL do STATEMENT for even := 0 to 100 step 2 do STATEMENT; Can you use step with non-integers? It depends on your compiler. while TEST do STATEMENT; repeat STATEMENT-list until TERMINATION-CONDITION Procedures and Functions * Different creatures * Functions return values * Procedures do not procedure NAME(PARAMS); LOCAL-VARIABLES LOCAL-PROCEDURES begin STATEMENTS; end parameters are all typed function NAME(PARAMS): TYPE; LOCAL-VARIABLES LOCAL-PROCEDURES begin STATEMENTS; end The return value for a function is the value of the function variable when the procedure terminates int increment(int x) { return x+1; } function increment(x: integer): integer; begin increment := x + 1; end Pascal includes wonderful creatures known as "variable parameters". * If you change a variable parameter within a procedure, its change is reflected in the original program. Why some people hate var parameters Consider the following statements x := 5; y := 6; writeln(x); Goal for Wednesday: Discuss intermediate language we'll use this semester Control instructions: JUMP LABEL/Address JUMP-If-Zero REGISTER LABEL/Address Jump-if-less-than REG1 REG2 LABEL/Address Arithmetic instructions Stack instructions Call procedure The parameters to these instructions * Registers * Constant values (and labels) * Memory locations There are links on today's outline to PAL, the Pseudo-Assembly Language