Language
Language
• Programming language
– Assembly
– C
– Python
– Java
• Analytics
– R language
– S language
• Web services
– Java
– Html
– Php
• Mobile application development
– Java
Embedded systems
• Computers used as part of a larger system
– That usually doesn’t look like a computer
– That usually controls physical devices
• Often reliability is critical
• Often resources (memory, processor capacity) are limited
• Often real-time response is essential
• What are we talking about? • Fuel injector controls
– Assembly line quality monitors • Medical equipment monitors
– Bar code readers • PDAs
– Bread machines • Printer controllers
– Cameras • Sound systems
– Car assembly robots • Rice cookers
– Cell phones • Telephone switches
– Centrifuge controllers • Water pump controllers
– CD players • Welding machines
– Disk drive controllers • Windmills
– “Smart card” processors • Wrist watches
• Often there are plenty of resources to handle the common cases
– But crises happen and must be handled
• Predictability is key
• Correctness is even more important than usual
– “correctness” is not an abstract concept
– “but I assumed that the hardware worked correctly” is no excuse
• Over a long time and over a large range of conditions, it simply doesn’t
Embedded systems programming
• You (usually) have to be much more aware of the resources consumed
in embedded systems programming than you have to in “ordinary”
programs
– Time
– Space
– Communication channels
– Files
– ROM (Read-Only Memory)
– Flash memory
– …
• You must take the time to learn about the way your language features
are implemented for a particular platform
– Hardware
– Operating system
– Libraries
• A lot of this kind of programming is
– Looking at specialized features of an RTOS (Real Time Operating
System)
– Using a “Non-hosted environment” (that’s one way of saying “a
language right on top of hardware without an operating system”)
– Involving (sometimes complex) device driver architectures
– Dealing directly with hardware device interfaces
– …
• We won’t go into details here
– That’s what specific courses and manuals are for
Introduction
Levels of Programming Languages
• Machine Language
– Consists of individual instructions that will be executed by the CPU one at a time
• Assembly Language (Low Level Language)
– Designed for a specific family of processors (different processor groups/family has
different instruction set)
– Consists of symbolic instructions directly related to machine language instructions
one-for-one and are assembled into machine language.
• High Level Languages
– e.g. : C, C++ and Vbasic
– Designed to eliminate the technicalities of a particular computer.
– Statements compiled in a high level language typically generate many low-level
instructions.
Assembly Languages
• One step up from machine
language.
• It initially a more user-friendly
way to program.
• Now mostly a compiler target. ENIAC, 1946
17k tubes, 5kHz
Reasons for using Assembly Language
• Assembly Language requires considerably less memory and
execution time than one written in a high –level language.
• Ability to perform highly technical tasks that would be difficult, if
not impossible in a high-level language.
• Write and maintain, a common practice is to recode in assembly
language those sections that are time-critical.
• Resident programs and interrupt service routines are almost always
develop in Assembly Language.
Assembly Language Model
…
add r1,r2
sub r2,r3
PC cmp r3,r4 Memory
ALU Registers
bne I1
sub r4,1
I1: jmp I3
…
Statements
• Syntax:
operation operand(s) comments
– comment are optional
– Number of operands depend on the instruction
– One statement per line
• At least one blank or tab character must separate the field.
– Each statement is either:
• Instruction (translated into machine code)
• Assembler Directive (instructs the assembler to perform some specific task such
as allocating memory space for a variable or creating a procedure)
13
Assembly Language Instructions
• Built from two pieces
ADD R1, R3
Opcode Operands
What to do with Where to get
the data data and put
(ALU operation) the results
Types of Opcodes
• Arithmetic, logical:
– ADD, SUB, MULT
– AND, Or
– CMP
• Memory load/store:
– LOAD, ST
• Control transfer:
– JMP
• Complex:
– MOV
Operands
• Each operand taken from a particular addressing mode:
• Examples:
Register ADD r1, r2, r3
Immediate ADD r1, r2, #10H
Register Indirect MOV r1, (r2)
Indirect MOV r1, @10H
• Reflect processor data pathways
A Few Basic Instructions
MOV
• Transfer data
– Between registers
– Between register and a memory location
– Move a no. directly to a register or a memory location
• Syntax
MOV destination, source
• Example
MOV AX, WORD1
Before After
• Difference? 0006 0008
AX
– MOV AH, ‘A’
WORD1 0008 0008
– MOV AX, ‘A’
XCHG
• Exchange the contents of
– Two registers
– Register and a memory location
• Syntax
XCHG destination, source
• Example
XCHG AH, BL Before After
1A 00 05 00
AH AL AH AL
00 05 00 1A
BH BL BH BL
ADD Instruction
• To add contents of:
– Two registers
– A register and a memory location
– A number to a register
– A number to a memory location
• Example
ADD WORD1, AX
Before After
AX 01BC 01BC
WORD1 0523 06DF
SUB Instruction
• To subtract the contents of:
– Two registers
– A register and a memory location
– A number from a register
– A number from a memory location
• Example
SUB AX, DX
Before After
AX 0000 FFFF
DX 0001 0001
INC & DEC
• INC (increment) instruction is used to add 1 to the contents of a register or
memory location.
– Syntax: INC destination
– Example: INC WORD1
• DEC (decrement) instruction is used to subtract 1 from the contents of a
register or memory location.
– Syntax: DEC destination
– Example: DEC BYTE1
• Destination can be 8-bit or 16-bits wide.
• Destination can be a register or a memory location.
INC WORD1
Before After
WORD1 0002 0003
DEC BYTE1
Before After
BYTE1 FFFE FFFD
Advantages of Assembly Language
• Assembly language is easier to understand and use as
compared to machine language.
• It is easy to locate and correct errors.
• It is easier to correct errors and modify program
instructions.
• It can access machine-dependent registers and I/O.
Disadvantages Assembly Language
• It is that assembly language is machine dependent.
• A program written for one computer might not run in other
computers with different hardware configuration.
• It is long and tedious to write initially.
• Code can be fairly difficult to understand and modify, i.e. to
maintain.
Application of Assembly Language
• Hand-coded assembly language is typically used in a
system's BIOS.
• Assembly language used because of the lower size code.