background image

1

Podstawy techniki 

mikroprocesorowej 

ETEW006

Grupy rozkazów 

Tryby adresowania

Andrzej Stępień

Katedra Metrologii Elektronicznej i Fotonicznej

MU0

Prosty Procesor

licznik rozkazów 

(

PC – Program 

Counter

)

przechowuj

ą

cy adres 

kolejnej wykonywanej  instrukcji

akumulator 

(

ACC – ACCumulator

)

rejestr zawieraj

ą

cy jeden z 

argumentów przed operacj

ą

 ALU 

i wynik pracy ALU

jednostka arytmetyczno-
logiczna 

(

ALU – Arithmetic-Logic 

Unit

)

wykonuj

ą

ca operacje na 

binarnych argumentach, np. &, |, 
^, not, +, –, ........

rejestr instrukcji 

(

IR – Instruction 

Register

zawieraj

ą

cy aktualnie 

wykonywan

ą

  instrukcj

ę

układ dekodowania instrukcji

(

decode

)

i sterowania 

(

control logic

)

które koordynuj

ą

 prac

ę

 procesora

PC

IR

ACC

Bsel

ACC[15]

ACCz

ALUfs

ACCce

MU0

memory

MEMrq

RnW

IRce

opcode

PCce

Asel

ACCoe

ALU

A

B

m

u

x

0

1

mux

0

1

Rysunek 1.6

Steve Furber: ARM System-on-Chip Architecture.

2nd Edition. Addison Wesley, 2001, ISBN-10: 0-201-67519-6

MU0

Struktura 

[1#2]

MU0

jest 

16-bitowym

procesorem 

16-bitowe instrukcje 

zawieraj

ą

:

4-bitowy kod operacyjny   

(

operation code or opcode

); procesor 

realizuje jedynie 16 instrukcji

12-bitowy adres pami

ę

ci  

(

address field S

); procesor mo

ż

zaadresowa

ć

  8 Kbajtów pami

ę

ci zło

ż

onej z 4.096 16-bitowych 

komórek pami

ę

ci

kod operacyjny

(opcode)

S

4 bity

12 bitów

adres pami

ę

ci

(memory address)

Steve Furber: ARM System-on-Chip Architecture.

2nd Edition. Addison Wesley, 2001, ISBN-10: 0-201-67519-6

MU0

Struktura 

[2#2]

Mnemonik rozkazu 

ADD S

oznacza wykonanie 

ACC: = ACC + mem

16

[S]

:

dodanie

zawarto

ść

 akumulatora 

ACC

i zawarto

ś

ci 16-bitowej 

komórki

pami

ę

ci

o adresie 

S

(12-bitowy adres)

przesłanie 

wyniku

dodawania do akumulatora 

ACC

kod operacyjny

(opcode)

S

4 bity

12 bitów

adres pami

ę

ci

(memory address)

Steve Furber: ARM System-on-Chip Architecture.

2nd Edition. Addison Wesley, 2001, ISBN-10: 0-201-67519-6

Instrukcja

Opcode

Efekt wykonania

LDA

S

0000

ACC := mem

16

[S]

STO

S

0001

mem

16

[S] := ACC

ADD

S

0010

ACC := ACC + mem

16

[S]

SUB

S

0011

ACC := ACC – mem

16

[S]

JMP

S

0100

PC := S

JGE

S

0101

if ACC 

0 PC := S

JNE

S

0110

if ACC 

0 PC := S

STP

0111

stop

MU0

Formaty instrukcji

wynik (result) jest efektem wykonania  przez procesor MU0 podstawowych 
operacji, np. dodawania dwóch argumentów

format instrukcji

:

kod operacyjny 

instrukcji okre

ś

la jej sposób działania, np. dodawanie

niektóre bity kodu operacyjnego okre

ś

laj

ą

 

typ operandu

, np. rejestr 

(register) lub pami

ęć

 (memory)

inne bity okre

ś

laj

ą

 

miejsce składowania wyniku 

(result destination)

niektóre bity mog

ą

 okre

ś

la

ć

 

adres nast

ę

pnej do wykonania instrukcji  

(address of the next instruction to be executed)

instrukcje 

mog

ą

zawiera

ć

 4-, 3-, 2-, 1- lub 0-argumentów (adresów

argumentów) oraz wyniku 

(result)

Steve Furber: ARM System-on-Chip Architecture.

2nd Edition. Addison Wesley, 2001, ISBN-10: 0-201-67519-6

MU0

Instrukcje 4—adresowe (argumentowe)

format 4-argumentowej (adresowej) instrukcji

:

ADD

d

s1

s2

next_i

; d := s1 + s2
; instrukcja liczy (

4n + f

) bitów

function

s1 addr

s2 addr

d addr

next_i addr

f bitów

n bitów

n bitów

n bitów

n bitów

adresy dwóch

operandów

adres

wyniku

adres nast

ę

pnej do 

wykonania instrukcji

typ funkcji

Steve Furber: ARM System-on-Chip Architecture.

2nd Edition. Addison Wesley, 2001, ISBN-10: 0-201-67519-6

background image

2

MU0

Instrukcje 3—adresowe (argumentowe)

format 4-argumentowej (adresowej) instrukcji

:

ADD

d

s1

s2

next_i

; d := s1 + s2
; instrukcja liczy (

f + 4n

) bitów

function

s1 addr

s2 addr

d addr

next_i addr

f bitów

n bitów

n bitów

n bitów

n bitów

format 3-argumentowej (adresowej) instrukcji 

– adres nast

ę

pnej instrukcji 

obliczany  przez dodanie rozmiaru bie

żą

cej (wykonywanej) instrukcji do jej 

adresu i wpisanie nowej warto

ś

ci do licznika rozkazów  PC (redukcja liczby 

bitów w ka

ż

dej instrukcji); obliczanie adresu jak poprzednio:

ADD

d

s1

s2

; d := s1 + s2
; instrukcja liczy (

f + 3n

) bitów

function

s1 addr

s2 addr

d addr

f bitów

n bitów

n bitów

n bitów

adresy dwóch

operandów

adres

wyniku

adres nast

ę

pnej do 

wykonania instrukcji

typ funkcji

Steve Furber: ARM System-on-Chip Architecture.

2nd Edition. Addison Wesley, 2001, ISBN-10: 0-201-67519-6

MU0

Instrukcje 2—adresowe (argumentowe)

Steve Furber: ARM System-on-Chip Architecture.

2nd Edition. Addison Wesley, 2001, ISBN-10: 0-201-67519-6

function

s1 addr

s2 addr

d addr

next_i addr

f bitów

n bitów

n bitów

n bitów

n bitów

adresy dwóch

operandów

adres

wyniku

adres nast

ę

pnej do 

wykonania instrukcji

typ funkcji

format 4-argumentowej (adresowej) instrukcji

:

ADD

d

s1

s2

next_i

; d := s1 + s2;

instrukcja liczy (

f + 4n

) bitów

format 3-argumentowej (adresowej) instrukcji:

ADD

d

s1

s2

; d := s1 + s2; instrukcja liczy (

f + 3n

) bitów

function

s1 addr

s2 addr

d addr

f bitów

n bitów

n bitów

n bitów

function

s1 addr

f bitów

n bitów

d addr

n bitów

format 2-argumentowej (adresowej) instrukcji

– zmniejszenie 

długo

ś

ci instrukcji, je

ś

li 

wynik nadpisuje

jeden z argumentów:

ADD

d

s1

; d := d + s1;  instrukcja liczy (

f + 2n

) bitów

MU0: Instrukcje 1—adresowe 

(argumentowe)

Steve Furber: ARM System-on-Chip Architecture.

2nd Edition. Addison Wesley, 2001, ISBN-10: 0-201-67519-6

function

s1 addr

s2 addr

d addr

next_i addr

f bitów

n bitów

n bitów

n bitów

n bitów

adresy dwóch

operandów

adres

wyniku

adres nast

ę

pnej do 

wykonania instrukcji

typ funkcji

format 4-argumentowej (adresowej) instrukcji

:

ADD

d

s1

s2

next_i

; d := s1 + s2;

instrukcja liczy (

f + 4n

) bitów

format 3-argumentowej (adresowej) instrukcji:

ADD

d

s1

s2

; d := s1 + s2, instrukcja liczy (

f + 3n

) bitów

function

s1 addr

s2 addr

d addr

function

s1 addr

d addr

format 2-argumentowej (adresowej) instrukcji

:

ADD 

d

s1

; d := d + s1

instrukcja liczy (

f + 2n

) bitów

format 1-argumentowej (adresowej) instrukcji

– je

ś

li rejestrem wyniku 

jest domy

ś

lny rejestr zwany  akumulatorem:

ADD

s1

; acc := acc + s1  instrukcja liczy (

f + n

) bitów

function

s1 addr

f bitów

n bitów

function

MU0: Instrukcje 0—adresowe 

(argumentowe)

Steve Furber: ARM System-on-Chip Architecture.

2nd Edition. Addison Wesley, 2001, ISBN-10: 0-201-67519-6

function

s1 addr

s2 addr

d addr

next_i addr

f bitów

n bitów

n bitów

n bitów

n bitów

adresy dwóch

operandów

adres

wyniku

adres nast

ę

pnej do 

wykonania instrukcji

typ funkcji

format 4-argumentowej (adresowej) instrukcji

:

ADD

d

s1

s2

next_i

; d := s1 + s2;

instrukcja liczy (

f + 4n

) bitów

format 3-argumentowej (adresowej) instrukcji:

ADD

d

s1

s2

; d := s1 + s2, instrukcja liczy (

f + 3n

) bitów

function

s1 addr

s2 addr

d addr

function

s1 addr

d addr

format 2-argumentowej (adresowej) instrukcji

:

ADD 

d

s1

; d := d + s1

instrukcja liczy (

f + 2n

) bitów

format 1-argumentowej (adresowej) instrukcji

:

ADD

s1

; acc := acc + s1  instrukcja liczy (

f + n

) bitów

function

s1 addr

function

format 0-argumentowej (adresowej) instrukcji

:

ADD

; szczyt_stosu := szczyt_stosu + nast

ę

pna_warto

ść

_na_stosie

; (top_of_stack := top_of_stack + next_on_stack)
instrukcja liczy (

) bitów

function

Model programowy procesora

http://pl.wikipedia.org/wiki/Model_programowy_procesora

http://en.wikipedia.org/wiki/Instruction_set

model programowy procesora

(

ISA

- Instruction Set Architecture) 

ogólne okre

ś

lenie dotycz

ą

ce organizacji, funkcjonalno

ś

ci i zasad 

działania procesora, widoczne z punktu widzenia programisty jako 
dost

ę

pne mechanizmy programowania (nie jest architektur

ą

 procesora)

model programowy 

procesora tworz

ą

 m.in.:

– lista rozkazów procesora 

(

instruction set

)

– typy danych 

(

data types

)

– dost

ę

pne tryby adresowania 

(

addressing modes

)

– zestaw rejestrów 

dost

ę

pnych dla programisty (

register file

)

– zasady obsługi wyj

ą

tków i przerwa

ń

 

(

exceptions

and 

interrupts

)

procesory posiadaj

ą

ce ten sam model programowy s

ą

 ze sob

ą

 

kompatybilne 

– mog

ą

 wykonywa

ć

 te same programy w taki sam 

(funkcjonalny) sposób, np. Cortex-M0/M0+ 

Cortex-M3 

 

Cortex-M4

Instrukcje

http://pl.wikipedia.org/wiki/Instrukcja_(informatyka)

instrukcja

(w programowaniu) to 

najmniejszy samodzielny element 

imperatywnego 

j

ę

zyka programowania

; instrukcja mo

ż

e by

ć

:

– niskiego poziomu napisana w asemblerze (np. mov  r1, r2), która po 

przetłumaczeniu na kod binarny nadaje si

ę

 do uruchomienia przez 

procesor 

– instrukcja wysokiego poziomu napisana np. w j

ę

zyku C (int a = 5;)

która zostanie przetłumaczona  na kilka instrukcji niskiego poziomu (na 
poziomie asemblera)

program

jest tworzony  jako 

zbiór ró

ż

nych instrukcji

; instrukcja mo

ż

zawiera

ć

 wewn

ę

trzne  komponenty (np. wyra

ż

enia).

instrukcje

mog

ą

 by

ć

 

proste

(NOP, a = a + 1, return 5, goto 13, 

ClearScreen) lub 

zło

ż

one

(if a>3 then .. else .., switch c …….)

background image

3

Linia  kodu  programu

[etykieta:]

[; komentarz]

etykieta 

- symboliczny adres,

instrukcja

- rozkaz wykonywany przez procesor,

mnemonik

- symboliczna nazwa instrukcji,

operand

- argumenty instrukcji,

dyrektywa

- polecenie dla asemblera,

komentarz - tekst pomijany przez asembler,  od ‘;’ do CR LF

mnemonik instrukcji

[operand1], [operand2], ..

dyrektywa

instrukcja

Cortex-M0

StartUp_LPC11xx.s

PRESERVE8
THUMB

; Vector Table Mapped to Address 0 at Reset

AREA

RESET, DATA, 

READONLY

EXPORT

__Vectors

__Vectors

DCD

__initial_sp

; Top of Stack

DCD

Reset_Handle

r

; Reset Handler

DCD

NMI_Handler

; NMI Handler

..........................................................................

; External Interrupts

DCD

WAKEUP_IRQHandler

; 16+ 0: Wakeup PIO0.0

DCD

WAKEUP_IRQHandler

; 16+ 1: Wakeup PIO0.1

..........................................................................

Reset_Handle

r

PROC

; Reset Handler

EXPORT

Reset_Handler

[WEAK]

IMPORT

SystemInit

IMPORT

__main

LDR

R0

, =SystemInit

BLX

R0

LDR

R0

, =__main

BX

R0

ENDP

; Dummy Exception Handlers (infinite loops which can be modified)                

NMI_Handler

PROC

; NMI Handler

EXPORT

NMI_Handler

[WEAK]

B

.

ENDP

HardFault_Handler

PROC

; HardFault_Handler

EXPORT

HardFault_Handle

r

[WEAK]

...........................................................................

dyrektywa 

DCD

(Define Constant Data)

deklaruje kilka 32-bitowych słów 
b

ę

d

ą

cych adresami procedur, które 

tworz

ą

 tabel

ę

 skoków

ARM Developer Suite. Assembler Guide. 
ARM DUI0068B, v.1.2, November 2001

etykieta

operand

; komentarz

dyrektywa

mnemonik instrukcji

Makroinstrukcje

http://pl.wikipedia.org/wiki/Makroinstrukcja

makroinstrukcja

(

macro instruction

) to ci

ą

g instrukcji wywoływanych 

za pomoc

ą

 jednej dodatkowo zdefiniowanej instrukcji:

MACRO

{$label

macroname { $cond }  { $parameter { ,$parameter } ... } 
; code 

MEND

przekształcenie

(rozszerzenie) 

makroinstrukcji

w ci

ą

g słów j

ę

zyka 

programowania (poddawanych dalszej  translacji) jest realizowane przez 
wst

ę

pny element translatora (

preprocesor

)

ARM Compiler toolchain. Version 4.1. Assembler Reference. 

ARM DUI 0489C, p.6-30

Dekoder  instrukcji

dekoder rozkazów 

(

Instruction  decoder

) – układ okre

ś

laj

ą

cy typ rozkazu, 

sposób jego wykonania, sposób generowania sygnałów steruj

ą

cych, np. 

pami

ę

ci

ą

 

sposób dekodowania 

rozkazu zale

ż

ny od typu procesora, projektantów 

procesora 

prostszy i szybszy dekoder procesorów RISC 

(mniejsza  liczba  rozkazów)

w porównaniu z architektur

ą

 CISC

ka

ż

da 

instrukcja zawiera informacj

ę

 

o:

kodzie operacyjnym 

(

opcode

), typie wykonywanej  operacji, 

operandach

ź

ródle argumentów wej

ś

ciowych  (

sources

), np. numery 

rejestrów, adresy pami

ę

ci itp.

operandach

– przeznaczeniu  argumentów wyj

ś

ciowych  (

destination

), np. 

numery rejestrów, adresy pami

ę

ci itp.

sposobie ich adresowania 

(

addressing mode

)

Dekodowanie  instrukcji

Format 2:  Thumb  ADD/SUB

ARM7TDMI Data Sheet. ARM DDI 0029E, p. 5-7

00011

I

9

15

11

Op

6

Rm/

Offset3

8

3

Rn

5

0

Rd

2

Destination
register

Source
register

Source register /
Immediate value

Opcode

: 0 – ADD

1 – SUB

Immediate flag: 0 – Register operand

1 – Immediate operand

Op

I

Instruction

Action

0

0

ADD  Rd, Rn, Rm

Rd 

Rm + Rn

0

1

ADD  Rd, Rn, #Offset3

Rd 

Rn + Offset3 (3-bit immediate value)

1

0

SUB  Rd, Rn, Rm

Rd 

Rn – Rm 

1

1

SUB  Rd, Rn, #Offset3

Rd 

Rn – Offset3 (3-bit immediate value)

Dekodowanie  instrukcji

ADD (register)

ARM

®

v7-M Architecture Reference Manual. Errata markup. 

ARM DDI 0403Derrata 2010_Q3, p. A7-223

T3

: ADD{S}<c>.W  <Rd>, <Rn>, <Rm>{,<shift_5bits>}

10

1000

S

4

Rn

0

imm3

11

11101

15

14

11

9 8

5

3

0

15

12

Rd

8

01

imm2

7

0

4

6

shift

type

5

Rm

3

T2

: ADD<c> 

<Rdn>, <Rm>

10

010001

15

00

8

DN

7

0

3

6

Rm

Rdn

2

T1

: ADDS 

<Rd>, <Rn>, <Rm>

00011

0

10

15

9

11

0

9

6

Rm

8

3

Rn

5

0

Rd

2

Thumb, Outside IT block

Thumb-2

Thumb

00 – LSL

01 – LSR 

10 – ASR

11 – ROR  

DN:Rdn

(4 bits)

background image

4

PREFIX w kodach rozkazów MCS51

0x

NOP

x0

AJMP

addr11

x1

LJMP

addr16

x2

RR

A

x3

1x

OPCODE

PREFIX

JBC

bit, rel

ACALL

addr11

LCALL
addr16

RRC

A

2x

JB

bit, rel

AJMP

addr11

RET

RL

A

Ax

ORL

C, /bit

AJMP

addr11

MOV
C, bit

INC

DPTR

Dx

POP

addr

ACALL

addr11

LJMP

addr16

RR

A

Ex

MOVX

A,@DPTR

AJMP

addr11

MOVX

A, @Ri

Fx

MOVX

@DPTR,A

ACALL

addr11

MOVX

@Ri, A

INC

addr

x5

DEC
addr
ADD

A, addr

DJNZ

addr, rel

MOV

A, addr

MOV

addr, A

OPCODE 
PREFIX = 0A5h
dodatkowe 
instrukcje np. 

80C51MX

(Philips)

C251 

(Intel/Atmel)

Przetwarzanie danych, obsługa pamięci

(Data handling and Memory operations)

wpis 

warto

ś

ci do rejestru 

(

set 

a

register

to a fixed constant value)

odczyt danych

z pami

ę

ci do rejestrów lub 

zapis danych 

z rejestrów 

do pami

ę

ci 

(

move data 

from a memory location to a register, or vice versa),

odczyt 

danych z urz

ą

dze

ń

 peryferyjnych do rejestrów lub 

zapis

danych z rejestrów do urz

ą

dze

ń

 peryferyjnych 

(

read/write data

from/into hardware devices),

http://en.wikipedia.org/wiki/Instruction_set

Instrukcje  arytmetyczne i  logiczne

(Arithmetic and logic operations)

dodawanie

odejmowanie

mno

ż

enie

dzielenie

warto

ś

ci w dwóch 

rejestrach, wynik równie

ż

 w rejestrze ze zmian

ą

 znacznika lub znaczników w 

rejestrze statusowym 
(

addsubtractmultiply

, or divide the values of two registers, placing the 

result in a register, possibly setting one or more condition codes in a status 
register)

operacje bitowe 

z koniunkcj

ą

 i alternatyw

ą

 bitów w parze rejestrów lub 

negacj

ą

 ka

ż

dego bitu w rejestrze 

(perform

bitwise operations

, taking the conjunction and disjunction of 

corresponding bits in a pair of registers, or the negation of each bit in a 
register)

porównanie 

dwóch warto

ś

ci w rejestrach, np. test czy mniejszy lub test 

równo

ś

ci itp. 

(

compare

two values in registers, for example, to see if one is less, or if they 

are equal)

http://en.wikipedia.org/wiki/Instruction_set

Kontrola przepływu 

(Control flow operations)

bezwarunkowe rozgał

ę

zienie programu

– skoki bezwarunkowe

(

branch 

to another location in the program and execute instructions 

there)

warunkowe rozgał

ę

zienie programu

– skoki warunkowe

(

conditionally branch 

to another location if a certain condition holds)

wywołania podprogramów, przerwa

ń

z pami

ę

taniem adresu 

powrotu z podprogramu, przerwania
(

indirectly branch 

to another location, while saving the location of the 

next instruction as a point to return to (a call))

http://en.wikipedia.org/wiki/Instruction_set

Typy instrukcji

wymiana danych 

(Data Transfer)  

[1#2]

wpis zadanej warto

ś

ci do rejestru

(

set a register to a fixed constant 

value

; a temporary "scratchpad" location in the CPU itself)

przenoszenia danych 

z pami

ę

ci do rejestru lub na odwrót (

move data 

from a memory location to a register, or vice versa

); w celu uzyskania 

danych do wykonywania  dalszych oblicze

ń

 lub zapisania wyniku 

oblicze

ń

odczyt/zapis z/do układów peryferyjnych 

(

read and write data from 

hardware devices

)

http://en.wikipedia.org/wiki/Instruction_set

Instructions  Types

Data Transfer  

[2#2]

Load and Transfer

MOV, MOVC, MOVX, XCH, XCHD, SWAP

Stack operation

PUSH, POP

MCS51

Load and Transfer

MOV

Stack operation

PUSH

MSP430

Load and Transfer

MOV, MOVW, LDI, LD, LDD, LDS, CLR, SET, 
ST, STD, STS, LPM, SPM, 

IN, OUT

Stack operation

PUSH, POP

AVR

Load and Transfer

MOV, MOVN, LDR, STR, LDM, STM, SWP

Stack operation

LDM, STM, PUSH (Thumb STM), POP (Thumb LDM)

ARM

Load and Transfer

MOV, XCHG, CMPXCHG, CMPXCHG8B, 
BSWAP, XADD, CWD/Q/W/E

IN, OUT

Stack operation

PUSH, POP

IA-32 
Architectures

P89LPC952/954 User Manual. NXP Semiconductors, UM10147, Rev. 02 - 28 April 2008

8-bit AVR Instruction Set.
Atmel Corporation, Rev. 0856G–AVR–07/08

MSP430x4xx Family User’s Guide. 
Texas Instruments, SLAU056J, January 2010

RealView

®

Developer Kit. Assembler Guide. ARM DUI 0283B, Version 2.2 - April 2005

Intel® 64 and IA-32 Architectures. Software Developer’s 
Manual. Volume 1: Basic Architecture. 
Intel Corporation, 
Order Number: 253665-037US, January 2011

background image

5

ARM Cortex

Multiple Data Transfer

I

A

R1

kierunek 

narastania 

adresów

R4

R0

R1

R4

R0

R1

R4

R0

R1

R4

R0

I

B

D

A

D

B

LDMxx R10, {R0, R1, R4}

STMxx R10, {R0, R1, R4}

lista rejestrów

R10
rejestr 

bazowy

xx:

ARM Architecture Reference Manual. Thumb-2 Supplement. 

ARM DDI 0308D, p. 4-96/4-98

!

aktualizacja rejestru 
Rn (R10) po 
zako

ń

czeniu 

transferu danych

I

lub 

D

korekta 
rejestru Rn 
(R10) o liczb

ę

 

transferowa-
nych bajtów

SIMD 

(Single Instruction, Multiple Data)

LDM | STM 

{<cond>}

<add mode> Rn 

{

!

}

, <registers>

<add mode>

okre

ś

la jeden z trybów  adresowania

:

I

A

I

(instrukcja ARM), 

D

(instrukcja ARM)

D

B

Increment

or

Decrement

After (przed)

lub 

Before (po)

Cortex

Multiple Data Transfer

SIMD 

(Single Instruction, Multiple Data)

LDM | STM  <add mode> Rn 

{

!

}

, <registers>

<add mode>

okre

ś

la jeden z trybów adresowania

I

A

D

B

Increment

or

Decrement

, , 

After (przed)

lub 

Before (po)

ARM Architecture Reference Manual. Thumb-2 Supplement. 

ARM DDI 0308D, p. 4-96/4-98 

LDM

D

B

LDMEA

Load Multiple Decrement Before 

(Load Multiple  Empty 

Ascending Stacks)

p.4-96 

wielokrotny  odczyt kolejnych komórek pami

ę

ci 

adresowanej rejestrem bazowym Rn (liczba  odczytów  zale

ż

y od listy 

rejestrów <registers>); rejestr bazowy Rn 

dekrementowany

(

4)

przed

odczytem danych

LDM

I

A

LDMFD

Load Multiple Increment After

(Load Multiple  Full

Descending Stacks)

p.4-98

wielokrotny odczyt kolejnych komórek 

pami

ę

ci adresowanej rejestrem bazowym  Rn (liczba  odczytów  zale

ż

od listy rejestrów <registers>); rejestr bazowy Rn 

inkrementowany

(+4)

po

odczycie danych  

Arithmetic  Instructions

ADD

Integer add

(DADD(.B) Add src and C decimally to dst 

MSP430

)

ADC

Add with carry

(DADC(.B) Add C decimally to destination 

MSP430

)

INC

Increment

DAA

Decimal adjust after addition

SUB

Subtract

(RSB Reverse Subtract 

ARM

)

SBB

Subtract with borrow

(RSC Reverse Subtract with Carry 

ARM

)

DEC

Decrement

CMP

Compare

(CMN Compare Negative 

ARM

)

(CPC Compare with Carry 

AVR

)

(CPSE Compare Skip if Equal 

AVR

)

(DJNZ Decrement and Jump if Not Equal 

C51

)

DAS

Decimal adjust after subtraction

NEG

Arithmetic negate

MUL

Unsigned multiply

DIV

Unsigned divide

C51:

OV = C  xor  A

7 | 6

P = parzysta liczba 1 w Acc i P 

Znaczniki

C,  H,  V,  S,  N,  Z

(AVR - 1/2)

Rd     Rr

bez znaku

C

H

V

N

S

Z

0xFF + 1 = 1111 1111b

255 + 1 = 256 !

0000 0001b

–1 + 1 = 0

C=1

0000 0000b

1

1

0

0

0

1

ze znakiem

R

H

V

C = 1,

Rd

7

=1, Rr

7

=0, R

7

=0

H = 1,

Rd

3

=1, Rr

3

=0, R

3

=0

V = 0,

Rd

7

=1, Rr

7

=0, R

7

=0

N = 0,  R

7

=0

S = 0
Z = 1,  all R

n

=0

7

Rd

7

R

7

R

7

Rr

7

Rr

7

Rd

 

 

C

+

+

=

0

1

4

R

R

2

R

3

R

R

5

R

6

R

7

R

 

 

Z

=

7

R

 

 

N

=

7

7

R

7

Rr

Rd

7

R

7

Rr

7

Rd

 

+

=

3

Rd

3

R

3

R

3

Rr

3

Rr

3

Rd

 

 

H

+

+

=

V

N

 

 

S

=

8-bit AVR Instruction Set. 

Atmel, Rev. 0856G–AVR–07/08, doc0856, p.15

Znaczniki

C,  H,  V,  S,  N,  Z

(AVR - 2/2)

Rd     Rr

bez znaku

C

H

V

N

S

Z

0x7F + 1 = 0111 1111b

127 + 1 = 128

0000 0001b

+127 + 1 = – 128 !

C=0

1000 0000b

0

1

1

1

0

0

ze znakiem

R

H

V

C = 0,

Rd

7

=0, Rr

7

=0, R

7

=1

H = 1,

Rd

3

=1, Rr

3

=0, R

3

=0

V = 1,

Rd

7

=0, Rr

7

=0, R

7

=1

N = 1,  R

7

=1

S = 0
Z = 0,

all R

n

=0

7

Rd

7

R

7

R

7

Rr

7

Rr

7

Rd

 

 

C

+

+

=

0

1

4

R

R

2

R

3

R

R

5

R

6

R

7

R

 

 

Z

=

7

R

 

 

N

=

7

7

R

7

Rr

Rd

7

R

7

Rr

7

Rd

 

+

=

3

Rd

3

R

3

R

3

Rr

3

Rr

3

Rd

 

 

H

+

+

=

V

N

 

 

S

=

C51:

OV = C  xor  A

7 | 6

P = parzysta liczba 1 w Acc i P 

Instrukcje logiczne

przesunięcia i obroty

Instrukcje logiczne AND

OR,

(

XOR

NOT

wykonuj

ą

 podstawowe 

operacje logiczne dla bajtu, słowa i podwójnego słowa. 

xor B = [A 

and

(

not

B)]  

or

[(

NOT

A) 

and

B]

Instrukcje przesuni

ęć

 

(shift) 

i obrotów 

(rotate) przesuwaj

ą

 i obracaj

ą

 

bity w słowie i podwójnym słowie (arytmetyczne lub logiczne).

Intel 64 and IA-32 Architectures.  Software Developer’s Manual. 

Volume 1: Basic Architecture. Intel Corporation, Order Number 

253665-037US, January 2011, p.5-5

scr

N

scr

0

scr

N

scr

0

C

0

przesuni

ę

cie 

(shift) 

obrót 

(rotate) 

background image

6

Logical Instructions

Z = X 

xor

Y = (X 

and

(

not

Y)) 

or

((

not

X) 

and

Y) 

Z = X 

and

Y

Z

X

Y

0

0

0

0

1

0

0

0

1

1

1

1

Z = X 

or

Y

Z

X

Y

0

0

0

1

1

0

1

0

1

1

1

1

Z = 

not

Z

X

1

0

0

1

Z = X 

xor

Y

Z

X

Y

0

0

0

1

1

0

1

0

1

0

1

1

MCS51

AVR

MSP430

ARM

IA–32

NOT

CPL 

COM 

*INV(.B)

NOT

(only Acc)

(One’s Complement)

BIC(.B)

CMN

(ot)

, MVN

(ot)

AND

ANL

AND, ANDI

(mmediate)

AND(.B)

AND

AND

BIT(.B)

OR

ORL

OR, ORI

(mmediate)

BIS(.B)

ORR, ORN

(ot)

OR

XOR

XRL

EOR

XOR(.B)

EOR

XOR

Shift and Rotate Instructions

[1#2]

LEFT

scr

N

scr

0

logical shift

scr

N

scr

0

C

0

scr

N

scr

0

RIGHT

scr

N

scr

0

C

rotate

scr

N

scr

0

C

scr

N

scr

0

C

scr

N

scr

0

C

0

arithmetic shift

scr

N

scr

0

C

dst

N

dst

0

CF

dst

N

dst

0

– instruction shifts the bits in the destination operand to the left (right) and fills the 

empty bit positions (in the destination operand) with bits shifted out of the source 
operand

– shift count can range from 0 to 31 bits
– source operand is not modified
– CF flag is loaded with the last bit shifted out of the destination operand.

dst

N

dst

0

CF

dst

N

dst

0

Intel® 64 and IA-32 Architectures. 

Software Developer’s Manual. 
Volume 1: Basic Architecture. 

Intel Corporation, Order Number

253665-037US, January 2011, p.7-18

RRX (Rotate right 

with extend moves)

Shift and Rotate

Instructions  

[2#2]

N

0

K

K-1

N

0

K K-1

Before:

After:

N

0

K

K-1

N

0

K

K-1

Before:

After:

SWAP

Sign (

or Zero

)

extension (

IA–32

)

ARM

Barrel  shifter  

[1#3]

mult

A[31:0]

control

Data out register

Data in register

Instruction

decode

&

control

A

L

U

b
u
s

B

b
u
s

A

b
u
s

Barrel

shifter

ALU

P
C

Register 

bank

P
C

incrementer

Address register

przesuni

ę

cia 32-bitowej zmiennej 

zawartej w jednym rejestrów, w lewo 
lub w prawo o zadan

ą

 liczb

ę

 bitów, 

przed wpisem do ALU 

przesuni

ę

cia zwi

ę

kszaj

ą

 wydajno

ść

 

wielu operacji przetwarzania danych 

ż

nych operacji 

przesuni

ę

cia

:

logiczne przesuni

ę

cie w lewo 

(logical shift left)

LSL

logiczne przesuni

ę

cie w prawo 

(logical shift right)

LSR

arytmetyczne przesuni

ę

cie w prawo 

(arithmetic shift right)

ASR

obrót w prawo
(rotate right)

ROR

rozszerzony obrót w prawo 
(rotate right extended)

RRX

Steve Furber: 
ARM System-

on-Chip 

Architecture.

2nd Edition. 

Addison 

Wesley, 2001, 

p.92

ARM

Barrel  Shifter  

[1#2]

no shift

in[3]

in[2]

in[1]

in[0]

out[0] out[1]

out[2]

out[3]

right 1

right 2

right 3

left 1

left 2

left 3

Barrel

shifter

ALU

Steve Furber: ARM System-on-Chip Architecture.

2nd Edition. Addison Wesley, 2001, 

p.92

ilustracja zasady działania 
przesuwnika w oparciu o 
matryc

ę

 4 x 4 (cross-bar switch 

4 x 4 matrix) –

ARM u

ż

ywa 

matrycy 32 x 32

ka

ż

de wej

ś

cie jest poł

ą

czone 

z wyj

ś

ciem przez matryc

ę

 

przełaczników  - tranzystorów 
NMOS

przesuni

ę

cie realizowane 

przez wł

ą

czenie odpowiedniej 

przek

ą

tnej matrycy

ARM

Barrel  shifter  

[2#2]

out[0] out[1]

out[2]

out[3]

no shift

right 1

right 2

right 3

left 1

left 2

left 3

przy 

przesuni

ę

ciu

lewo

lub w 

prawo

ą

czana  jest 

wła

ś

ciwa  przek

ą

tna

w ARM przesuwnik działa w 
logice ujemnej (stan "1" jest 
reprezentowany  jako 
potencjał masy GND, a 
stan '0’ – jako potencjał 
bliski zasilaniu  V

CC

wyj

ś

cia niepodł

ą

czone 

do 

wej

ść

 s

ą

 w stanie 

naładowania, co jest 
traktowane jako stan ’

0

in[3] = 1

in[2] = 1

in[1] = 0

in[0] = 0

in[3..0] = 1100

shift left 1 

out[3..0] = 100

0

shift right 1 

out[3..0] = 

0

110

Steve Furber: ARM System-on-Chip Architecture.

2nd Edition. Addison Wesley, 2001, 

p.92

background image

7

Operacje bitowe

(Bitwise operation)

[1#2]

http://en.wikipedia.org/wiki/Bitwise_operation

operacje wykonywane na jednym lub kilku bitach

szybkie operacje 

realizowane najcz

ęś

ciej bezpo

ś

rednio przez 

jednostk

ę

 ALU; stosowane do porówna

ń

 i oblicze

ń

wskazania bitów zgodne z zapisem binarnym; od lewej do prawej

Operacje bitowe

(Bitwise operation)

[2#2]]

Clear/Set/Toggle 

wybranych bitów w R2:  R2

6

, R2

5

, R2

2

i R2

0

.

Clear_bits:

AND

R2, #

NOT Mask

; R2 

R2

AND NOT

Mask

Set_bits

:

OR

R2, #

Mask

; R2 

R2

OR

M

ask

Toggle_bits

:

XOR

R2, #

Mask

; R2 

R2

XOR

M

ask

7

6

5

4

3

2

1

0

rejestr R2:

0

1

1

0

0

1

0

1

;

maska

:

Mask

EQU

0

11

0 0

1

0

1

b

; bity maski

Instrukcje emulowane

(Emulated  Instructions)

nie istniej

ą

 w kodzie maszynowym proc

esora (brak instrukcji)

automatycznie zast

ę

powane 

instrukcji 

emulowanych

przez 

równowa

ż

ne

podstawienie wła

ś

ciwych 

instrukcji

w trakcie asemblacji 

(1 do 1)

łatwiejsza praca 

w asemblerze

MSP430x4xx Family User’s Guide. 

Texas Instruments, SLAU056J, January 2010, p.3-17

MSP430

Emulated  Instructions 

Instr. emulowane

Instr. procesora

INC

dst

ADD

#1, dst

; Increment

INCD dst

ADD

#2, dst

; Double increment

DEC

dst

SUB

#1, dst

; Decrement

INV

dst

XOR #–1, dst

; Invert

TST

dst

CMP #0, dst

; Test destination

BR

dst

MOV dst, PC

; Branch to destination

RLA

dst

ADD

dst, dst

; Rotate left arithmetic 
(shift left 1 bit)

RLC

dst

ADDC dst, dst

; Rotate left through carry

MSP430x4xx Family User’s Guide. 

Texas Instruments, SLAU056J, January 2010, p.3-17

Conditional Data Transfer Instructions

IA-32 Architectures  

[1#2]

Intel 64 and IA-32 Architectures. Software Developer’s Manual. 

Volume 1: Basic Architecture. Intel Corporation, Order Number: 

253665-037US, January 2011

MOV

Move data between general-purpose registers; move data 
between memory and general-purpose or segment registers; 
move immediates to general-purpose registers

CMOVE/CMOVZ

Conditional move if equal/Conditional move if zero

CMOVNE/CMOVNZ

Conditional move if not equal/Conditional move if not zero

CMOVA/CMOVNBE

Conditional move if above/Conditional move if not below or equal

CMOVAE/CMOVNB

Conditional move if above or equal/Conditional move if not below

CMOVB/CMOVNAE

Conditional move if below/Conditional move if not above or equal

CMOVBE/CMOVNA

Conditional move if below or equal/Conditional move if not above

CMOVG/CMOVNLE

Conditional move if greater/Conditional move if not less or equal

CMOVGE/CMOVNL

Conditional move if greater or equal/Conditional move if not less

CMOVL/CMOVNGE

Conditional move if less/Conditional move if not greater or equal

CMOVLE/CMOVNG

Conditional move if less or equal/Conditional move if not greater

CMOVC

Conditional move if carry

CMOVNC

Conditional move if not carry

CMOVO

Conditional move if overflow

Conditional Data Transfer Instructions

IA-32 Architectures  

[2#2]

CMOVNS

Conditional move if not sign (non-negative)

CMOVP/CMOVPE

Conditional move if parity/Conditional move if parity even

CMOVNP/CMOVPO

Conditional move if not parity/Conditional move if parity odd

XCHG

Exchange

BSWAP

Byte swap

XADD

Exchange and add

CMPXCHG

Compare and exchange

CMPXCHG8B

Compare and exchange 8 bytes

PUSH

Push onto stack

POP

Pop off of stack

PUSHA/PUSHAD

Push general-purpose registers onto stack

POPA/POPAD

Pop general-purpose registers from stack

CWD/CDQ

Convert word to doubleword/Convert doubleword to quadword

CBW/CWDE

Convert byte to word/Convert word to doubleword in EAX 
register

MOVSX 

Move and sign extend

MOVZX 

Move and zero extend

background image

8

ARM

Instruction  Set

no 

overflow

V clear

VC

unsigned 

lower

C clear

CC

/

LO

overflow

V set

VS

unsigned 
higher or 

same

C set

CS

/

HS

signed less 

than or equal

Z set, 

or 

N set and V clear, 

or

N clear and V set 

(Z == 1 or N != V)

LE

positive or 

zero

N clear

PL

not equal

Z clear

NE

signed greater 

than

Z clear, and either 

N set and V set, 

or

N clear & V clear 

(Z == 0,N == V)

GT

negative

N set

MI

equal

Z set

EQ

N

Z

C

31 30 29 28

V

0

ARM Architecture Reference Manual.

ARM DDI 0100E. ARM DDI 0027D, June 2000, p.A3-6

Cortex-M0:  xPSR

always

AL

signed less 

than

N set and V clear, 

or

N clear and V set 

(N != V)

LT

signed greater 

than or equal

N set and V set, 

or

N clear and 

V clear (N == V)

GE

unsigned lower 

or same

C clear or Z set

LS

unsigned 

higher

C set and Z clear

HI

Efektywność  instrukcji  ARM

C

instruction:

if (Z == 1)   R1 = R2 + ( R3 

4) ;

Compiled 

ARM

instruction:

EQADDS 

R1, R2, R3, LSL #2

EQ

ADD

S

R1, R2, 

R3, LSL #2

Z=1 

(Equal) EQ

ADD

{cond}

{S}

Rd, Rn

, <Oprnd2>

Logical Shift Left

Rm  LSL  #5bit_Imm 

<Oprnd2>

sets condition flags after instruction 

S

R1 = R2 + R3 SHL 2

Tryby  Adresowania

Natychmiastowy 

(immediate / literal: immediate, pre-indexed immediate 

offset, post-indexed  immediate offset, ..) 

Rejestrowy

(register or pre-indexed register offset, post-indexed register 

offset, ..) 

Bezpo

ś

redni  / absolutny 

(direct / absolute: short, long, ..)

Po

ś

redni / rejestrowo po

ś

redni 

(Indirect / Register indirect: register 

autoincrement indirect, autodecrement register indirect, memory indirect, ..)

Relatywny / symboliczny / indeksowy 

(Relative / Symbolic / Indexed: PC-

relative, PC-relative with index and offset, displacement, relative, base 
register, base plus index, base plus index plus offset addressing, ..)

Stos 

(Stack: register indirect, ..) 

Adresowanie natychmiastowe 

(Immediate  Addressing)

operacje z warto

ś

ci

ą

 stałej zapisanej w pami

ę

ci programu jako cz

ęść

 

wykonywanej instrukcji:

ANL

P1, 

#01110011B

MCS51

:

P1 

P1 and 01110011b 

; zerowanie bitów: 7, 3 i 2 portu P1

add 

A, 

#$15

ST7

:

A + $15

ldi 

r17, 

0xFF

AVR

:

R17 

0FFh

DADD.W

#0x9876

, R5

MSP430

: 9876h + R5 + C 

R5

;

(dziesi

ę

tnie)

LDR

R0, [R1, {

#imm

}]

Cortex-M0

: wpisz do rejestru R0

zawarto

ść

 pami

ę

ci RAM 

o adresie [R1 + 

imm

]

; { } warto

ść

 opcjonalna (do wyboru)

Adresowanie rejstrowe

(Register  Addressing)

operacje na rejestrach:

ANL

B

, #01110011B

C51

:

B and 01110011b 

add 

A

, #$15

ST7

:

A + $15

ldi 

r17

, 0xFF

AVR

:

R17 

0FFh

DADD.W #0x9876, 

R5

MSP430

: 9876h + R5 + C 

R5

;

(dziesi

ę

tnie)

MOV 

R2

R0

, LSL #2 

;

Cortex-M0

:

przesu

ń

 R0 

2-krotnie w

;

lewo i wynik wpisz do R2

;

(R2 

R0 

4)

Adresowanie bezpośrednie

(Direct  Addressing)

operacje z wykorzystaniem adresów komórek pami

ę

ci lub adresów 

rejestrów:

ANL

P1

, #01110011B

C51

:

(P1) 

(P1) and 01110011b 

ld 

A, 

$4B

ST7

:

($4B)

lds 

r12, 

0x00FF

AVR

:

R12 

(00FFh)

MOV

&EDE, &TONI

;

MSP430

: (EDE) 

(TONI)

LDR 

PC, Reset_Addr

ARM:

PC 

(Reset_Addr)

; nie mo

ż

na wpisa

ć

 32-bitowej zmiennej do rejestru w jednym 

; 32-bitowym słowie, poniewa

ż

 instrukcja ma równie

ż

 długo

ść

 

; 32 bitów

background image

9

Adresowanie pośrednie

(Indirect  Addressing)

adres komórki pami

ę

ci RAM lub rejestru jest zawarty w rejestrze lub 

wska

ź

niku:

ADD

A, 

@R1

C51

:

A + (R1), tylko R0, R1

cp 

A, 

[ptr]

ST7

:

Reg CC: {N, Z, C} 

A – ((ptr))

ld 

r10, 

X

AVR

:

R10 

(X), 

; odczytaj komórk

ę

 pami

ę

ci o adresie w X 

; lub Y lub Z i wpisz do r10

cmp

@r6

, r7

;

MSP430

: r7 – (r6) 

Reg SR: {N, Z, C, V}

STR 

R3, 

[R2]

ARM

:

[R2] 

R3,

; wpisz R3 do pami

ę

ci RAM o adresie w R2

Adresowanie indeksowe

(Indexed  Addressing)

MOVC A, 

@A+DPTR

C51

:

(A + DPTR)

CODE

LD

A,

([ptr.w], X)

ST7

([ptr.word], X)

LD 

Rd, 

X

;

AVR

:

Load Indirect from Data Space

LD 

Rd, 

X+

;

to Register using 

Index X

LD

Rd, 

–X

MOV 

2(R5), 6(R6)

;

MSP430

: (2 + (R5)) 

(6 + (R6))

LDRcc R0,

[R1, #12] !

ARM

:

if cc = true, then R1 = R1 + 12

;

R0 

(R1 + 12),

pre-indexed

LDRcc R0,

[R1], #12

ARM

:

R0 

(R1),

post-indexed

if cc = true, then R1 = R1 + 12

Adresowanie względne

(Relative  Addressing)

DJNZ

Rn, 

rel

C51

:

Rn 

Rn – 1

;

if Rn = 0 then PC 

PC + rel

JRcc

label

ST7

if (cc == 1) then

;

PC = PC + oft

;

or PC = PC + (oft)

;

else PC = PC

RJMP

k

;

AVR

:

PC 

 PC + k + 1

;

–2K 

 k < 2K

MOV

EDE

TONI

MSP430

: MOV   X(PC), Y(PC)

;

X = EDE − PC 

Y = TONI − PC

LDR 

Rd,

=const

ARM7

:

LDR  Rn, [PC, #offset to literal pool]

;

load Rn register with one word

;

from the address [PC + offset]

Adresowanie pamięci – tryb 2

Load and Store Word or Unsigned Byte

LDR|STR{<cond>}{B}{T} <Rd>, 

<addressing_mode>

where 

<addressing_mode>

is one of the nine options for Word or Unsigned 

Byte:

[<Rn>, #+/-<offset_12>]

Immediate offset

[<Rn>, +/-<Rm>]

Register offset

[<Rn>, +/-<Rm>, <shift> #<shift_imm>]

Scaled register offset

[<Rn>, #+/-<offset_12>]

!

Immediate 

pre-indexed

[<Rn>, +/-<Rm>]

!

Register 

pre-indexed

[<Rn>, +/-<Rm>, <shift> #<shift_imm>]

!

Scaled register 

pre-indexed

[

<Rn>

]

, #+/-<offset_12>

Immediate 

post-indexed

[

<Rn>

]

, +/-<Rm>

Register 

post-indexed

[

<Rn>

]

, +/-<Rm>, <shift> #<shift_imm>

Scaled register 

post-indexed

RealView

®

Developer Kit. Assembler Guide.

ARM DUI 0283B, Version 2.2 - April 2005

Problemy i pytania

1. Czym jest instrukcja procesora ?

2. Jakie składniki tworz

ą

 instrukcje procesora ?

3. Jakie typy instrukcji s

ą

 dost

ę

pne w procesorach ?

4. Na czym polegaj

ą

 instrukcje SIMD ?

5. Jakie jest przeznaczenie znaczników: N, Z, C, V ?

6. Czym si

ę

 ró

ż

ni

ą

 operacje ‘shift’ od ‘rotate’ ?

7. Na czym polega maskowanie bitów ?

8. Czym s

ą

 instrukcje emulowane ?

9. Czym si

ę

 ró

ż

ni

ą

 instrukcje warunkowe od bezwarunkowych ?

10. Poda

ć

 stosowane w procesorach tryby adresowania.

11. Na czym polega adresowanie natychmiastowe ?

12. Na czym polega adresowanie bezpo

ś

rednie ?

13. Na czym polega adresowanie po

ś

rednie ?

14. Na czym polega adresowanie rejestrowe ?

15. Na czym polega adresowanie indeksowe ?

16. Czym jest etykieta ?