STPPT2.2 Hardware and I - O Interfaces and Source Code Components
STPPT2.2 Hardware and I - O Interfaces and Source Code Components
MICROPROCESSOR SYSTEMS
ECEMICRO/ECE0035
Assembly Language Programming
Building and Microcontroller
System
ECEMICRO Module 2
■ Subtopics: 1) Microcontroller Systems 2) Hardware, I/O
Interfaces and Source Code Components
■ At the end of the chapter, the learner should be able to:
– Discuss terms and concepts of Microcontroller Systems, I/O
Interfaces, Source Code Components and Assembly Language
Subtopic # 2
Hardware, I/O
Interfaces and Source
Code Components
Interfacing Processors and Peripherals
I/O Design affected by
many factors
(expandability, resilience)
• Performance:
— access latency
— throughput
— connection between
devices and the system
— the memory hierarchy
— the operating system
• A variety of different
users (e.g., banks,
supercomputers,
engineers)
I/O
Important but neglected
• “The difficulties in assessing and designing I/O
systems have often relegated I/O to second class
status”
• “courses in every aspect of computing, from
programming to computer architecture often
ignore I/O or give it scanty coverage”
• “textbooks leave the subject to near the end,
making it easier for students and instructors to skip
it!”
I/O Devices
• Very diverse devices
— behavior (i.e., input vs. output vs. both)
— partners (who is at the other end?)
— data rates
I/O Techniques
Three main modes:
– Programmed I/O
• CPU checks and reads and writes device buffers
– Interrupt Mode
• CPU asks devices to let it know when they are read
– DMA
• CPU asks devices to perform directly from memory
• CPU sets the memory buffers
• CPU is informed when I/O is done (or in case of an error)
through an interrupt
I/O Example: Disk Drives
– Programmed I/O
• CPU checks and reads and writes device buffers
– Interrupt Mode
• CPU asks devices to let it know when they are read
– DMA
• CPU asks devices to perform directly from memory
• CPU sets the memory buffers
• CPU is informed when I/O is done (or in case of an error)
through an interrupt
Interfacing Analog IO
The following describes the output data format, Single-
Shot conversion and Continuous conversion techniques.
Continuous Conversion
When ADC is configured for Continuous conversion, the
ADC continuously performs an analog to-digital
conversion on the selected analog input. Each new
data value overwrites the previous value stored in the
ADC data registers. An interrupt is generated after each
conversion.
The DMA_ADC Address register points to a block
of the Register File to store ADC conversion values.
This register contains the seven most-significant bits
of the 12-bit Register File addresses.
The five least-significant bits are calculated from
the ADC Analog Input number (5-bit base address
is equal to twice the ADC Analog Input number).
ADC conversion data is stored in two bytes per
ADC Analog Input, with the most significant byte
of the ADC data stored at the even numbered
Register File address.
Potentiometer Input
• Using a potentiometer and one of the Arduino’s
analog-to-digital conversion (ADC) pins it is
possible to read analog values from 0-1024. the
following example uses a potentiometer to control
an LED’s rate of blinking. For others, you need
ADC.
Variable Resistor Input
• Variable resistor include CdS light sensors,
thermistors, flex sensors, and so on. This example
makes use of a function to read the analog value
and set a delay time. This controls the speed at
which an LED brightens and dims.
High-level language
6
• High-Level Language overcomes the limitation
of writing a program in Machine and Assembly
language as it is difficult and time consuming.
• In High-Level Language, the programs can be written
using simple English words. Examples of High-Level
Language are BASIC, Fortran, COBOL, C, C++.
• Programs written in high-level languages are
translated into machine language by a compiler.
7
Assembly languagesyntax
• An assembly language program consists of statements. The
syntax of an assembly language program statement obeys
the following rules:
- Only one statement is written per line.
- Each statement is either an instruction or an assembler
directive.
- Each instruction has an op-code and possibly one, two or
no operands at all.
- An op-code is known as mnemonic.
- Each mnemonic represents a single machine instruction.
- Operands provide the data to work with.
Basic Assembly ProgramStructure
8
Assembly language is made up of two(2) types of
statements:
Assembler Directive:
Inform the assembler about the program and the
environment and NOT be translated into machine code.
Executable Instruction:
One of the processor's valid instructions which can be
translated into machine code form by the assembler.
Assembler directive
9
• Assembler directives are instructions that are directed to the assembler
to do a specific thing.
• It is not translated into machine code.
(Assembler directives are executed by the assembler at assembly time,
not by the CPUat run time).
• Directives can be used to :
• Link symbolic names to actual values.
• Set up pre-defined constants.
• Allocate storage for data in memory.
• Control the assembly process.
• Include additional source files.
• starting address for the program.
10 Example of assembler directives
• EQU - Equate
Assigns a value to a symbol (same as = ) e.g. TRISA EQU 0x85
• ORG - Origin
Sets the current origin to a new value. This is used to set the program or register address
during assembly. For example, ORG 0x00 tells the assembler to assemble all subsequent
code starting at address 0000H.
• INCLUDE
An assembler include, or header, file is any file containing valid assembly code.
Usually, the file contains device-specific register and bit assignments. This file may be
“included” in the code so that it may be reused bymany programs. As an example, to
add the standard header file for the PIC16F877 device to your assembly code, use:
#INCLUDE P16F877.INC
• END
This directive is the last statement in an assembly language program. The END
directive terminates an assembly language program.
Instruction format – Label
12
• A label is used to represent a line or group of code, or a constant value. It is
needed for branching instructions.
• Labels should start in column 1. They may be followed by a colon (:), space,
tab or the end of line.
• Labels must begin with an alpha character or an under bar (_) and may
contain alphanumeric characters, the under bar and the question mark.
• Labels must not:
• begin with two leading underscores, e.g. temp
• begin with a leading underscore and number.
e.g. _2NDLOOP
• be an assembler reserved word (mnemonic, directive,
etc.).
Instruction format – Label
13
• Labels may be up to 32 characters long.
• By default they are case sensitive, but case
sensitivity may be overridden by a command-
line option (/c).
• If a colon is used when defining a label, it is treated
as a label operator and not part of the label itself.
• Example:
Here NOP
GOTO Here
Instruction format - Opcode
14
• This field consists of a symbolic operation code,
known as op-code.
• The opcode describes the operation.
• Symbolic op-codes (known as mnemonic) are
translated into machine language opcode.
• Mnemonics are not case sensitive.
• ORG - Origin
Sets the current origin to a new value. This is used to set the program or register address
during assembly. For example, ORG 0x00 tells the assembler to assemble all subsequent
code starting at address 0000H.
• INCLUDE
An assembler include, or header, file is any file containing valid assembly code.
Usually, the file contains device-specific register and bit assignments. This file may be
“included” in the code so that it may be reused bymany programs. As an example, to
add the standard header file for the PIC16F877 device to your assembly code, use:
#INCLUDE P16F877.INC
• END
This directive is the last statement in an assembly language program. The END
directive terminates an assembly language program.
REFERENCES
[1] Microprocessor Architecture, Programming, and Applications with the 8085
5th Edition Textbook by Ramesh S. Gaonkar
[3] Jones, Daniel (2017). Arduino: The Ultimate Beginner’s Guide to Learn Arduino
(Volume 1). CreateSpace Independent Publishing Platform
[4] Kumar, N. Senthil (2012). Microprocessors and interfacing: 8086, 8051, 8096,
and advanced processors. Oxford University
Press
[5] Mazidi, Muhammad Ali (2016). PIC Microcontrollers and Embedded Systems.
Microdigital Ed.
REFERENCES
https://www.webopedia.com/TERM/H/high_level_language.html
https://www.slideshare.net/shashankputhrran/assembly-language-
53015963
https://www.tutorialspoint.com/microprocessor/microprocessor_quick_guid
e.htm
ASK ANY QUESTION RELATED TO
OUR TOPIC FOR TODAY.