Title: Assembly and High Level Languages
1Assembly and High Level Languages
2Creating Software
- Now that we have a computer to work with, how do
we create software to solve our problems? - One solution use machine language instructions
3Machine Language
- Recall machine language instructions are the
binary patterns that a processor natively
recognizes - What's the problem with this approach?
- Solution ABSTRACTION!
4Assembly Language
- Rather than binary patterns, what if we used
mnemonics (essentially words) to represent
instructions? - Ex add instead of 101010
- What do we gain?
5Assembly Language (cont)
- Consists of mnemonic names for instructions
- Each instruction corresponds to exactly one
machine language instruction - Another piece of software called the assembler
then translates ASM code into machine language
6The Assembly Code to Machine Code Translation
7But....
- Still tied to a particular piece of hardware
- Why?
- Thus each assembly language is specific to a
particular architecture
8The Structure of Assembly
- A typical line has four parts
- Label (optional)
- Instruction
- Address (sometimes optional)
- Comment (optional)
9Structure (cont)
- The address field holds the symbolic address of
the memory location being used - The label is a symbolic representation of an
instruction or data value
10Pseudo Ops
- Operations performed by the assembler
- Example
- .DATA associates labels with addresses and can
build integer values
11.DATA Example
- FIVE .DATA 5
- Associates an memory address with the label
FIVE, and puts the numeric value 5 into that
location - Can now do
- LOAD FIVE
- But why not LOAD 5?
- All psuedo-ops come after the HALT
12Overall Structure of An Assembly Program
.BEGIN ...... some instructions....... HALT
.... some pseudo ops (such as .DATA
declarations).....END
13Example
- Write an assembly program to do
- A B C - 7
14Example 2
- Write a program which loops 10 times
- Roughly equivalent to
- For a 0 to 10 do ....
15The Assembler
- Since each assembly instruction corresponds to
exactly one machine language instruction, the
assembler only has to - Convert mnemonic op codes to binary
- Convert symbolic addresses to binary
- Do the pseudo-ops
- Save output to a file
16Good Enough?
- As much of an improvement as it is, there are
still some drawbacks to assembly language. - Such as?
17Assembly Drawbacks
- Manual memory management
- Microscopic view of tasks
- Not like natural-language
- MACHINE-SPECIFIC
18High Level Programming Languages
- Designed to address some of the shortcomings of
assembly - Many memory details are abstracted away
- Many problem-specific details are abstracted away
- Less machine specific
- Closer to natural language
19This is not a course in Java
- This is not a course in Java
- This is not a course in Java
- This is not a course in Java
- This is not a course in Java
- This is not a course in Java
- This is not a course in Java
20Examples of HLPLs
- Java (but this is not a course in it)
- C (but this is not a course in C)
- Scheme/LISP
- Prolog
- FORTRAN
- Etc, etc, etc
21Concepts
- Variables
- Identifiers vs keywords
- Statements
22Statement Types
- Four main categories of statements
- Input
- Output
- Assignment
- Control
23Assignment Statements
- Assign a value to an identifier (typically a
variable) - Ex a 3 b
- 3 b is evaluated
- Result is assigned to a
- What about
- 3 a b
24Control Statements
- Three control mechanisms
- Sequential
- Conditional
- Looping
- The three define the flow of control in a program
25Divide and Conquer
- Break a problem into smaller pieces
- Solve each piece and combine results to solve the
overall problem
26Methods / Functions / Procedures / Subroutines
- A rose by any other name....
27Methods / Functions / Procedures / Subroutines
- A convenient way to encapsulate some
computation, which can then be used without
worrying about its implementation. With ...
functions it is possible to ignore how a job is
done knowing what is done is sufficient. (C
Programming Language, Kernighan and Ritchie)
28Parts of Functions
- Functions can be identified by their
- Name
- Return type (if any)
- Parameter (or argument) List
29Example
- integer Foo (boolean a, integer x)
- Defines a function called Foo which takes two
arguments a boolean value and an integer, and
returns an integer
30A Question....
integer x 3 Foo (integer y) y y
3 What is the value of x after doing "Foo(x)"?
31Call-by.... Mechanisms
- In programming languages there are two main
parameter passing mechanisms - Call by Value each argument to a function is
copied, and that copy passed to the function - Call by Reference the address of each parameter
to a function is passed in to the function
32Call By Value
- Using the Foo(x) example....
33Call By Reference
- Using the Foo(x) example....
34In Practical Terms
- In call-by-value, any changes to a variable are
not seen outside of the called function - In call-by-reference, changes to a variable are
seen outside of the called function
35In Practical Terms (cont)
- From an efficiency standpoint
- Call by value has to make a copy of each
parameter thus it can be slower