7/29/2019 Machine Code and Assembly Language.pptx
1/29
01110111011010001000
MOV A
JMP B
7/29/2019 Machine Code and Assembly Language.pptx
2/29
What is a programming language?
A programming language is a notational system for
describing computation in a machine-readable andhuman-readableform.
To build programs, people use languages that are similar
to human language. The results are translated intomachine code, which computers understand.
7/29/2019 Machine Code and Assembly Language.pptx
3/29
Classification of the languages
Programming languages fall into three broad categories:
Machine languages
Assembly languages
Higher-level languages
In the formal classification the above 3 categories are
divided into as 5 Generations of languages.
7/29/2019 Machine Code and Assembly Language.pptx
4/29
Generations of Programming
Languages1stGL: machine codes
2ndGL: symbolic assemblers
3rd
GL: (machine-independent) imperative languages(FORTRAN, Pascal, C ...)
4th GL: domain specific application generators
5th GL: AI languages
Each generation is at a higher level of abstraction
i.e.: The higher the generation, the lesser the programmer willbe aware of the internal workings of the program in thehardware level.
7/29/2019 Machine Code and Assembly Language.pptx
5/29
A Brief ChronologyEarly 1950s order codes (primitive assemblers)
1957 FORTRAN the first high-level programming language
1958 ALGOL the first modern, imperative language
1960 LISP, COBOL Interactive programming; business programming
1962 APL, SIMULA the birth of OOP (SIMULA)
1964 BASIC, PL/I
1966 ISWIM first modern functional language (a proposal)1970 Prolog logic programming is born
1972 C the systems programming language
1975 Pascal, Scheme two teaching languages
1978 CSP Concurrency matures
1978 FP Backus proposal
1983 Smalltalk-80, Ada OOP is reinvented
1984 Standard ML FP becomes mainstream (?)1986 C++, Eiffel OOP is reinvented (again)
1988 CLOS, Oberon, Mathematica
1990 Haskell FP is reinvented
1990s Perl, Python, Ruby, JavaScript Scripting languages become mainstream
1995 Java OOP is reinvented for the internet
2000 C#
7/29/2019 Machine Code and Assembly Language.pptx
6/29
What is Machine Code ?
Machine code is the only form of program instructions that
the computer hardware can understand and execute directly.
All other forms of computer language must be translated into
machine code in order to be executed by the hardware.
Machine code consists of many strings ofbinary digits that are
easy for the computer to interpret, but tedious for human
beings to interpret.
Machine code is different for each type of computer.
A program in machine code for an Intel x86-based PC will not run
on an IBM mainframe computer, and vice versa.
7/29/2019 Machine Code and Assembly Language.pptx
7/29
Assembly Language Assembly language is a symbolic representation of machine
code, which allows programmers to write programs inmachine code without having to deal with the long binarystrings.
For example, the machine code for an instruction that addstwo numbers might be 01101110, but in assembly language,this can be represented by the symbol ADD.
A simple assembler program translates this symbolic languagedirectly into machine code.
Because machine code is specific to each type of computerhardware, assembly languages are also specific to each type ofcomputer.
However, all machine languages and assembly languages lookvery similar, even though they are not interchangeable.
7/29/2019 Machine Code and Assembly Language.pptx
8/29
Assembler
Assembly
code
Object code
7/29/2019 Machine Code and Assembly Language.pptx
9/29
High Level Languages High-level language is a language that is convenient for human
beings to understand.
High-level programming languages must be translated into machinecode for execution, and this process is called compilation.
A program that carries out this translation is a compiler. High-level language may bear no resemblance at all to machine
code.
The compiler figures out how to generate machine language thatdoes exactly what the high-level-language source program specifies.
Languages like C++, Algol, COBOL, etc., are all compiled high-levellanguages.
They usually work more or less the same across all computer types,which makes them much more portable than assembly language.
7/29/2019 Machine Code and Assembly Language.pptx
10/29
Higher-Level Languages -
Third-Generation Languages Third-generation languages (3GLs) are the first to use true English-
like phrasing, making them easier to use than previous languages.
3GLs are portable, meaning the object code created for one type ofsystem can be translated for use on a different type of system.
The following languages are 3GLs:
FORTAN C
COBOL C++
BASIC Java
Pascal ActiveX
7/29/2019 Machine Code and Assembly Language.pptx
11/29
Example :
7/29/2019 Machine Code and Assembly Language.pptx
12/29
Higher-Level Languages -
Fourth-Generation Languages Fourth-generation languages (4GLs) are even easier to use
than 3GLs.
4GLs may use a text-based environment (like a 3GL) or mayallow the programmer to work in a visual environment, usinggraphical tools.
The following languages are 4GLs: Visual Basic (VB)
VisualAge
Authoring environments
7/29/2019 Machine Code and Assembly Language.pptx
13/29
7/29/2019 Machine Code and Assembly Language.pptx
14/29
Why we need assembly langauge?
Early computer systems were literally programmed by hand.
Front panel switches were used to enter instructions and data.
These switches represented the address, data and control lines
of the computer system. To enter data into memory, the address switches were toggled
to the correct address, the data switches were toggled next,and finally the WRite switch was toggled.
This wrote the binary value on the front panel data switches tothe address specified.
Once all the data and instruction were entered, the run switchwas toggled to run the program.
7/29/2019 Machine Code and Assembly Language.pptx
15/29
7/29/2019 Machine Code and Assembly Language.pptx
16/29
With the advent of better hardware which could address
larger memory, and the increase in memory size (due tobetter production techniques and lower cost), programs
were written to perform some of this manual entry.
Small monitor programs became popular, which allowedentry of instructions and data via hex keypads or
terminals.
Additional devices such as paper tape and punched cards
became popular as storage methods for programs.
7/29/2019 Machine Code and Assembly Language.pptx
17/29
Programs were still hand-coded, in that the conversion
from mnemonics to instructions was still performedmanually.
To increase programmer productivity, the idea of writing
a program to interpret another was a major
breakthrough.
This would be run by the computer, and translate the
actual mnemonics into instructions.
The benefits of such a program would be reduced errors
faster translation times
changes could be made easier and faster
7/29/2019 Machine Code and Assembly Language.pptx
18/29
Mnemonics AssemblerMachine
Code
Assembly language programming is writing machine
instructions in mnemonic form, using an assembler to
convert these mnemonics into actual processor
instructions and associated data.
So basically assembly language is a translator from
human world to the machine world.
7/29/2019 Machine Code and Assembly Language.pptx
19/29
Disadvantages of assembly
language programming
the programmer requires knowledge of the processor
architecture and instruction set
many instructions are required to achieve small tasks.
source programs tend to be large and difficult to follow
programs are machine dependent, requiring complete
rewrites if the hardware is changed
7/29/2019 Machine Code and Assembly Language.pptx
20/29
Software development process
The Real WorldProblem
Logical Solution(On paper)
Selecting tools
(programminglanguage/method)
Coding
Testing/Debugging
Release as finalsolution
7/29/2019 Machine Code and Assembly Language.pptx
21/29
The program translation sequence
Developing a software program to accomplish a particular
task : -
the implementer chooses an appropriate language,
develops the algorithm (a sequence of steps, which when
carried out in the order prescribed, achieve the desired
result),
implements this algorithm in the chosen language (coding),
then tests and debugs the final result.
7/29/2019 Machine Code and Assembly Language.pptx
22/29
Software execution process
Machine code or the executable codewhich the machine understands
7/29/2019 Machine Code and Assembly Language.pptx
23/29
Assembly language programming Features provided by an assembler are,
allows the programmer to use mnemonics when writing source codeprograms.
variables are represented by symbolic names, not as memory locations
symbolic code is easier to read and follow
error checking is provided
changes can be quickly and easily incorporated with a re-assembly
programming aids are included for relocation and expression evaluation
In writing assembly language programs for micro-computers, it isessential that a standardized format be followed. Mostmanufacturers provide assemblers, which are programs used togenerate machine code instructions for the actual processor toexecute.
7/29/2019 Machine Code and Assembly Language.pptx
24/29
The assembler converts the written assembly
language source program into a format which run on theprocessor.
Each machine code instruction (the binary or hex value) is
replaced by a mnemonic.
A mnemonic is an abbreviation which represents theactual instruction.
Binary Hex Mnemonic
01001111 4F CLRA Clears the A accumulator00110110 36 PSHA Saves A acc on stack
01001101 4D TSTA Tests A acc for 0
7/29/2019 Machine Code and Assembly Language.pptx
25/29
7/29/2019 Machine Code and Assembly Language.pptx
26/29
Assembly language statements are written one per line.
A machine code program thus consists of a sequence of
assembly language statements, where each statement
contains a mnemonic.
Each line of an assembly language program is split intofour fields, as shown below
LABEL OPCODE OPERAND COMMENTS
7/29/2019 Machine Code and Assembly Language.pptx
27/29
Label The label field is optional.
A label is an identifier (or text string symbol).
Labels are used extensively in programs to reduce reliance upon
programmers remembering where data or code is located. A label can be used to refer to a memory location the value of a
piece of data the address of a program, sub-routine, code portionetc.
The maximum length of a label differs between assemblers. Some
accept up to 32 characters long, others only four characters.
A label, when declared, is suffixed by a colon, and begins with a validcharacter (A..Z).
7/29/2019 Machine Code and Assembly Language.pptx
28/29
Example
START: LDAA #24H
Here, the label START is equal to the address of the instruction LDAA#24H.
The label is used in the program as a reference,eg,
JMP START
This would result in the processor jumping to the location (address)associated with the label START, thus executing the instruction LDAA#24H immediately after the JMP instruction. When a label isreferenced later on in the program, it is done so without the colonsuffix.
7/29/2019 Machine Code and Assembly Language.pptx
29/29