Assembly and High Level Languages - PowerPoint PPT Presentation

1 / 35
About This Presentation
Title:

Assembly and High Level Languages

Description:

Each instruction corresponds to exactly one machine language instruction ... The Assembly Code to Machine Code Translation. But... – PowerPoint PPT presentation

Number of Views:46
Avg rating:3.0/5.0
Slides: 36
Provided by: webhome2
Category:

less

Transcript and Presenter's Notes

Title: Assembly and High Level Languages


1
Assembly and High Level Languages
2
Creating 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

3
Machine Language
  • Recall machine language instructions are the
    binary patterns that a processor natively
    recognizes
  • What's the problem with this approach?
  • Solution ABSTRACTION!

4
Assembly Language
  • Rather than binary patterns, what if we used
    mnemonics (essentially words) to represent
    instructions?
  • Ex add instead of 101010
  • What do we gain?

5
Assembly 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

6
The Assembly Code to Machine Code Translation
7
But....
  • Still tied to a particular piece of hardware
  • Why?
  • Thus each assembly language is specific to a
    particular architecture

8
The Structure of Assembly
  • A typical line has four parts
  • Label (optional)
  • Instruction
  • Address (sometimes optional)
  • Comment (optional)

9
Structure (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

10
Pseudo 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

12
Overall Structure of An Assembly Program
.BEGIN ...... some instructions....... HALT
.... some pseudo ops (such as .DATA
declarations).....END
13
Example
  • Write an assembly program to do
  • A B C - 7

14
Example 2
  • Write a program which loops 10 times
  • Roughly equivalent to
  • For a 0 to 10 do ....

15
The 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

16
Good Enough?
  • As much of an improvement as it is, there are
    still some drawbacks to assembly language.
  • Such as?

17
Assembly Drawbacks
  • Manual memory management
  • Microscopic view of tasks
  • Not like natural-language
  • MACHINE-SPECIFIC

18
High 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

19
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
  • This is not a course in Java

20
Examples 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

21
Concepts
  • Variables
  • Identifiers vs keywords
  • Statements

22
Statement Types
  • Four main categories of statements
  • Input
  • Output
  • Assignment
  • Control

23
Assignment 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

24
Control Statements
  • Three control mechanisms
  • Sequential
  • Conditional
  • Looping
  • The three define the flow of control in a program

25
Divide and Conquer
  • Break a problem into smaller pieces
  • Solve each piece and combine results to solve the
    overall problem

26
Methods / Functions / Procedures / Subroutines
  • A rose by any other name....

27
Methods / 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)

28
Parts of Functions
  • Functions can be identified by their
  • Name
  • Return type (if any)
  • Parameter (or argument) List

29
Example
  • 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

30
A Question....
integer x 3 Foo (integer y) y y
3 What is the value of x after doing "Foo(x)"?
31
Call-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

32
Call By Value
  • Using the Foo(x) example....

33
Call By Reference
  • Using the Foo(x) example....

34
In 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

35
In Practical Terms (cont)
  • From an efficiency standpoint
  • Call by value has to make a copy of each
    parameter thus it can be slower
Write a Comment
User Comments (0)
About PowerShow.com