47
SKEE 3223 Microprocessor SEC 11/12 with SHAHIDATUL SADIAH

SKEE 3223 Microprocessor

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: SKEE 3223 Microprocessor

SKEE 3223MicroprocessorSEC 11/12 with SHAHIDATUL SADIAH

Page 2: SKEE 3223 Microprocessor

Module 4:ATmega32 AssemblyLanguage Programming

Page 3: SKEE 3223 Microprocessor

Computer System

Hardware• CPU• Memory• I/O• Datapath

• Operating System• Compilers• Assemblers• Assembly

language• High Level

Language (HLL)Could have another set of layers too, depending on the applications.

Page 4: SKEE 3223 Microprocessor

System Software Application

Program

Compilation

Execution

A program that translates high-level language

statements into assembly language statements

Compiler

HLL

OS

Hardware

A programming language that enable programmer to

write a program. This language can be translated by a

compiler to assembly language.

High-level language

Examples: C, Pascal, Fortran and Java.Machine language

Compiler

Assembler

Assembly Language

Page 5: SKEE 3223 Microprocessor

System Software

Is a lower language of computer that uses symbolic

(mnemonic) representation of machine instructions.

Assembly language

A program that translate a mnemonic version of

instruction into the binary version of machine

language

Assembler

Application

Program

Compilation

Execution

HLL

OS

HardwareA program that controls the execution of application

programs and act as an interface between user’s

program and computer hardware.

Operating System

Examples: Windows, Linux, and Mac OS.

Machine language

Compiler

Assembler

Assembly Language

Page 6: SKEE 3223 Microprocessor

High level language

• Describe tasks in form that are problem-oriented rather

than computer-oriented.

• Programs are easier and faster to write

• Machine Independence

• Portability (at least in theory)

• Syntax : Complicated set of rules (each instruction has different rules)

• Cost of Compilers : Compilers are computationally expensive and use a

large amount of memory

• Inefficiency: High level languages do not produce very efficient machine

language program

• High-Level languages doesn’t handle most architecture features, such as

registers, program status, etc.

Advantages

Disadvantages

Page 7: SKEE 3223 Microprocessor

Assembly language

• High speed

• Low code size

• Interact directly with register and memory

• The assembler does not solve all the problems of programming. One

problem is the tremendous gap between the microprocessor instruction set

and the task which the microprocessor is to perform. An assembly language

programmer must translate such tasks into a sequence of simple computer

instructions. The translation can be a difficult, time consuming job.

• Must have detailed knowledge of the particular microprocessor that you are

using

• Assembly language programs are not portable

Advantages

Disadvantages

Page 8: SKEE 3223 Microprocessor

Why assembly language?

Hardware prospective?

Assembly language teaches how a computer works at the machine level

(i.e. registers)

Software prospective?

The foundation of many abstract issues in software lies in assembly

language and computer architecture: Data types, addressing modes, stack,

input/output

Page 9: SKEE 3223 Microprocessor

AVR System Programming

Type in the

program

Compile the

program

Check for

errors

Make changes

or corrections

Improve

program?

Working

program

YES

YES

NO

NO

Page 10: SKEE 3223 Microprocessor

Debugger

Embedded systems debugger

1) To identify and fix bugs in the system ⇒ logical or synchronization problems in the

code, or a design error in the hardware

2) To collect information about the operating states of the system that may then be used

to analyse the system and boost its performance or to optimize other important

characteristics ⇒ energy consumption, reliability, real-time response etc.

Debugger is a computer program that is used to test and debug the

"target" program.

Page 11: SKEE 3223 Microprocessor

Emulator

Hardware emulation

The process of imitating the behaviour of one or more pieces of hardware

(typically a system under design) with another piece of hardware, typically a

special purpose emulation system.

Emulator Benefits:

• Allows users to play games for discontinued consoles.

• Allow software exclusive to one system to be used on another.

• Maintain the original look, feel, and behavior of the digital objects.

A hardware or software or both that duplicates (emulates) the function of one

computer system (the guest) in other computer system (the host) → a copy.

Page 12: SKEE 3223 Microprocessor

AVR Emulator

• In AVR system, an ARMulator is one of the software development tools for ARM-

based chips.

• It is written in C, and provides more than just an instruction set simulator, it provides a

virtual platform for system emulation. It comes ready to emulate an ARM processor

and certain ARM Coprocessors.

• Allows runtime debugging using either armsd (ARM Symbolic Debugger), or either of

the graphical debuggers that were shipped in Software Development Toolkit (SDT)

and the later ARM Developer Suite (ADS) products.

Page 13: SKEE 3223 Microprocessor

Simulator

• Simulator is a hardware or software or both that partially represents the function of one

computer system (the guest) in other computer system (the host).

• Normally, it is used during the initial stages of development, when the hardware is not yet

ready.

Two main types of simulator

1) The full-system simulator – simulator that allows real device drivers and operating

systems to be run, not just single programs. Typically has to include processor cores,

peripheral devices, memories, interconnection buses, and network connections.

2) Instruction set simulator – simulator that coded in a high-level programming

language, which mimics the behaviour of a mainframe or microprocessor.

Simulator is a program runs on a computer for the purpose of

simulating some sort of system.

Page 14: SKEE 3223 Microprocessor

Assembly Language

A low-level programming that deal with the internal structure of CPU, which

provided mnemonics for machine code instruction.

• To program in assembly language, the

programmer must know all the registers of the

CPU and size of each, as well as other details.

• Assembly language must be translated into

machine code by a program called assembler.

Page 15: SKEE 3223 Microprocessor

Assembly language structure

• The structure of assembly programs are a series of statements, or

lines, which are either instructions such as ADD and LDI, or

statements that is known as the directives.

• While instruction tell the CPU what to do, directives give directions

to the assembler.

label: mnemonic operand(s) ;comment

Page 16: SKEE 3223 Microprocessor

Directive & Instructions

directive

instructions

Page 17: SKEE 3223 Microprocessor

Assembler Directive

• Directives give direction to the assembler.

• The directives are not translated into opcodes.

• Used to adjust the location of the program in memory, define macros,

or initialize memory.

• The directive help us develop our program easier and make our program

legible (more readable).

Page 18: SKEE 3223 Microprocessor

Assembler Directives

.EQU .SET .CSEG

.BYTE

.ORG

.INCLUDE .DSEG

.EXIT.DB

.DW.ESEG .DEF

Page 19: SKEE 3223 Microprocessor

.EQU (equate)

Example:

assign a constant value or a fixed address to a variable.

constantvariable

Use

variable

to load

constantDefine the

name of the

I/O registers

with their

address

M32DEF.INC

The variable

CANNOT be

changed or

reassign

Page 20: SKEE 3223 Microprocessor

.SET

Example:

assign a constant value or a fixed address to a variable.

constantvariable

.SET io_offset = 0x25

Redefined

variable io_offset

Page 21: SKEE 3223 Microprocessor

.INCLUDE

Example:

Specified another file to be read by the assembler

iodefs.asm

sreg is defined inside the

file specified by include

directive

file

The nclude file

may itself contain

.INCLUDE

directives

Page 22: SKEE 3223 Microprocessor

Assembler Directives

.EQU .SET .CSEG

.BYTE

.ORG

.INCLUDE .DSEG

.EXIT.DB

.DW.ESEG .DEF

Page 23: SKEE 3223 Microprocessor

.DSEG

defines the start of a Data Segment

.DSEG ; Start data segment

var1: .BYTE 1 ; reserve 1 byte to var1

table: .BYTE tab_size ; reserve tab_size bytes.

.DSEG ; Start data segment

.ORG 0x110 ; Set SRAM counter to 0x110

var1: .BYTE 1 ; reserve 1 byte to var1

var2: .BYTE 3 ; reserve 3 bytes to var2

var3: .BYTE 1 ; reserve 1 bytes to var1

label

.BYTE directive

To place the

variables at specific

location in SRAM

Page 24: SKEE 3223 Microprocessor

.CSEG

defines the start of a Code Segment

.CSEG ; Start code segment

const: .DW 2 ; Write 0x0002 in prog.mem.

mov r1,r0 ; Do something

.CSEG

.ORG 0x110 ; Set SRAM counter to 0x110

ldi r30,low(var1) ; Load Z register low

ldi r31,high(var1) ; Load Z register high

ld r1,Z ; Load VAR1 into register 1

The default

segment

type

To place the

variables at specific

location in Program

Memory

Page 25: SKEE 3223 Microprocessor

.ESEG

defines the start of an EEPROM Segment

.ESEG ; Start EEPROM segment

eevar1: .DW 0xffff ; initialize 1 word in EEPROM

.DW directive

Page 26: SKEE 3223 Microprocessor

Assembler Directives

.EQU .SET .CSEG

.BYTE

.ORG

.INCLUDE .DSEG

.EXIT.DB

.DW.ESEG .DEF

Page 27: SKEE 3223 Microprocessor

.ORG

Set a memory location counter to a value

Set SRAM

location

counter

Set

EEPROM

location

counter

Set

Program

Memory

counter

Page 28: SKEE 3223 Microprocessor

.ORG

Set a memory location counter to a value

variable 0x67 label

Page 29: SKEE 3223 Microprocessor

.ORG

Set a memory location counter to a value

Default values

of counter is 0

Default values of

counter is 32

Page 30: SKEE 3223 Microprocessor

Assembler Directives

.EQU .SET .CSEG

.BYTE

.ORG

.INCLUDE .DSEG

.EXIT.DB

.DW.ESEG .DEF

Page 31: SKEE 3223 Microprocessor

.BYTE

reserves memory byte in the SRAM

.DSEG ; Start data segment

.ORG 0x110 ; Set SRAM counter to 0x110

var1: .BYTE 1 ; reserve 1 byte to var1

var2: .BYTE 3 ; reserve 3 bytes to var2

var3: .BYTE 1 ; reserve 1 bytes to var1

Var1 0x110

0x111

Var2 0x112

0x113

Var3 0x114

0x115

SRAMNumber of

bytes to be

reserved

Page 32: SKEE 3223 Microprocessor

.DW

reserves constant words in the program memory or the

EEPROM

.CSEG

.ORG 0x110

varlist: .DW 0, 0xffff, 0b1001110001010101, -32768, 65535

.ESEG

eevarlst: .DW 0,0xffff,10

List of expression

List of expression

0x0000 0x110

0xFFFF 0x111

0x9155 0x112

0x8000 0x113

0xFFFF 0x114

0x115

0x116

Program

memory

Page 33: SKEE 3223 Microprocessor

.DB

reserves constant bytes in the program memory or the

EEPROM

.CSEG

consts: .DB 0, 255, 0b01010101, -128, 0xaa

.ESEG

const2: .DB 1,2,3

0x01 0x00

0x02 0x01

0x03 0x02

0x03

0x04

0x05

0x06

EEPROM

Page 34: SKEE 3223 Microprocessor

Assembler Directives

.EQU .SET .CSEG

.BYTE

.ORG

.INCLUDE .DSEG

.EXIT.DB

.DW.ESEG .DEF

Page 35: SKEE 3223 Microprocessor

.DEF

Example:

Set a symbolic name on a register

.DEF temp=R16

.DEF ior=R0

.CSEG

ldi temp,0xf0 ; Load 0xf0 into temp register

in ior,0x3f ; Read SREG into ior register

eor temp,ior ; Exclusive or temp and ior

Symbol can be redefined as

other register

There is no restriction on

symbol name

Page 36: SKEE 3223 Microprocessor

.EXIT

to stop assembling the file

.EXIT ; Exit this file

……

.include file.asm

file.asm

.exit

(1)

(2)(3)

(4)

(5)

Page 37: SKEE 3223 Microprocessor

How assembly language is created?AVRStudio

IDE

Source file

Object file

Hex file

EEPROM file

list file

map file

Page 38: SKEE 3223 Microprocessor

Example of Assembly program

Page 39: SKEE 3223 Microprocessor

Example of Assembly program

Assembly CodeMachine

code

LC/PC

Page 40: SKEE 3223 Microprocessor

In the program memory

0x00

0x01

0x02

0x03

0x04

0x05

0x06

The machine code of each instruction is stored

consecutively in program memory

The default

segment type in

assembly

program is cseg

Page 41: SKEE 3223 Microprocessor

In the data memory

R16 0x25 0x0F

R17 0x34 0x10

R18 0x31 0x11

SUM 0x300

Page 42: SKEE 3223 Microprocessor

In the data memory

R16 0x59 0x0F

R17 0x34 0x10

R18 0x31 0x11

SUM 0x300

Page 43: SKEE 3223 Microprocessor

In the data memory

R16 0x8A 0x0F

R17 0x34 0x10

R18 0x31 0x11

SUM 0x300

Page 44: SKEE 3223 Microprocessor

In the data memory

R16 0x8A 0x0F

R17 0x0B 0x10

R18 0x31 0x11

SUM 0x300

Page 45: SKEE 3223 Microprocessor

In the data memory

R16 0x95 0x0F

R17 0x0B 0x10

R18 0x31 0x11

SUM 0x300

Page 46: SKEE 3223 Microprocessor

In the data memory

R16 0x95 0x0F

R17 0x0B 0x10

R18 0x31 0x11

SUM 0x95 0x300

Page 47: SKEE 3223 Microprocessor