Top Banner
8051 Assembly Language Disciplina: Microcontroladores Prof. Remy Eskinazi, MSc
21

8051 Assembly Language Disciplina: Microcontroladores Prof. Remy Eskinazi, MSc.

Apr 22, 2015

Download

Documents

Internet User
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 2: 8051 Assembly Language Disciplina: Microcontroladores Prof. Remy Eskinazi, MSc.

2Microcontroladores - Prof. Remy Eskinazi

Revisão: Alguns Registradores Importantes

A

B

R0

R1

R2

R3

R4

R5

R6

R7

DPH

PC

DPL

SP

7F

00

08

10

18

20

30

Scratch Pad Area

RAM

Bit Addressable RAM

Bank 3

Bank 2

Bank 1

Bank 0R0R7R0

R7R0R7

R0

R7

User & Stack

Page 3: 8051 Assembly Language Disciplina: Microcontroladores Prof. Remy Eskinazi, MSc.

3Microcontroladores - Prof. Remy Eskinazi

Instruções 8051

• Tipos de instruções– Movimentação de Dados– Aritméticas– Lógicas– Manipulação de Bit– Controle de programa (Saltos e Desvios)

Page 4: 8051 Assembly Language Disciplina: Microcontroladores Prof. Remy Eskinazi, MSc.

4Microcontroladores - Prof. Remy Eskinazi

Modos de endereçamento 8051 (1)

• Imediato (Direto) - (Label ou Número)

MOV PSW,05 ; M(PSW) R5

MOV A,04510 ; Acc M(4510)

• Constante Imediata – (# Label ou Número)

MOV R6,#14 ; R6 1410

MOV A,#0CAh ; Acc CA16

MOV DPTR,#loc ; DPTR Valor associado a “loc”

• Registrador – (Rn)

MOV R1,A ; R1 Acc

MOV B,R3 ; B R3

Page 5: 8051 Assembly Language Disciplina: Microcontroladores Prof. Remy Eskinazi, MSc.

5Microcontroladores - Prof. Remy Eskinazi

Modos de endereçamento 8051 (2)

• Indireto por Registrador - @R0, @R1, @DPTR

MOV @R0,#250 ; M(R0) 250 10

MOV A,@R1 ; A M(R1) MOVX @DPTR,A ; External data M(DPTR) A

• Indexado (Registrador Indireto) - @A+DPTR, @A+PC

MOVC A,@A+DPTR ; A ROM(A+DPTR) MOVC A,@A+PC ; A ROM(A+PC) JMP @A+DPTR ; PC (A+DPTR)

• Bit – Número do bit, label.bit ou bit label

MOV C,IE.0 ; cy bit 0 do IE reg. (EX0) MOV C,EX0 ; identico SETB 07Fh ; Bit 7F 1 SETB 2F.7 ; identico

Page 6: 8051 Assembly Language Disciplina: Microcontroladores Prof. Remy Eskinazi, MSc.

6Microcontroladores - Prof. Remy Eskinazi

Modos de endereçamento 8051 (3)

• Saltos e desvios (controle de fluxo de programa)

Exemplos:

Salto Incodicional: JMP (Address16)AJMP (Address11)SJMP (Address8)LJMP (Address16)

Salto condicional:JC (Address8)JNC (Address8)JB (Address8)JNB (Address8)

Page 7: 8051 Assembly Language Disciplina: Microcontroladores Prof. Remy Eskinazi, MSc.

7Microcontroladores - Prof. Remy Eskinazi

Exemplo de Programa Assembly

; **** Programa Exemplo ***; **** Objetivo: Explicar campos de um programa assembly 8051 ****

Valor: equ 02h ; uso da diretiva equate

org 0h ;Resetsjmp inicio

org 03 ; Int. Externa 0sjmp ext0

Inicio: mov A, #0FFhmov R1, #valorDB 02hDB ‘A’ ; ASCII do caractere A

End ; Fim de programa p/ compilação

Page 8: 8051 Assembly Language Disciplina: Microcontroladores Prof. Remy Eskinazi, MSc.

8Microcontroladores - Prof. Remy Eskinazi

Instruções 8051 – Movimentação de Dados

MOV Rn, # Rn Immediate

Direct … A

MOVE

MOV A, #n A Immediate

Direct A Direct R A Register

@Ri A Register Indirect

MOV Direct, # Direct Immediate

Direct … R

@R

A MOV @Ri, # M(Ri) Immediate

Direct … A

Page 9: 8051 Assembly Language Disciplina: Microcontroladores Prof. Remy Eskinazi, MSc.

9Microcontroladores - Prof. Remy Eskinazi

Instruções 8051 – Movimentação de Dados

Move From Program Memory

MOVC A, @A+DPTR Acc Rom(A+DPTR)

A, @A+PC Acc Rom(A+PC) Move External Data RAM

MOVX A, @R

A, @DPTR

MOVX @R, A

@DPTR, A Others

PUSH D SP SP+1, m(SP) D

POP D D m(SP), SP SP - 1

XCH A, R SWAP Acc Rn

D

@R

Page 10: 8051 Assembly Language Disciplina: Microcontroladores Prof. Remy Eskinazi, MSc.

10Microcontroladores - Prof. Remy Eskinazi

Instruções 8051 – Aritméticas

ADDC A, # Acc A+Immediate+Carry

D R @R

Add/Subtract

ADD A, # Acc A+Immediate

D R

@R

SUBB A, # Acc Acc-Immediate-Carry

D

R

@R

Page 11: 8051 Assembly Language Disciplina: Microcontroladores Prof. Remy Eskinazi, MSc.

11Microcontroladores - Prof. Remy Eskinazi

Instruções 8051 – Aritméticas

Inc/Dec

INC A Acc Acc+1

D R

@RDPTR

• DEC A Acc Acc-1

D R

@R Mul/Div

MUL AB B:A Acc * B (unsigned)

DIV AB A Quo ( A/B ) (unsigned) B Rem( A/B )

Page 14: 8051 Assembly Language Disciplina: Microcontroladores Prof. Remy Eskinazi, MSc.

14Microcontroladores - Prof. Remy Eskinazi

Instruções 8051 – Manipulação de Bits

Clear/Set/Complement

CLR C Carry 0

bit bit 0SETB C

bitCPL C

bit And, Or, Move

ANL C, bit Carry Carry AND bit

C, /bit Carry Carry AND bitORL C, bit

C, /bitMOV C, bit

bit, C

Page 15: 8051 Assembly Language Disciplina: Microcontroladores Prof. Remy Eskinazi, MSc.

15Microcontroladores - Prof. Remy Eskinazi

Instruções 8051 – Manipulação de Bits

Saltos

JC label Jump if Carry set

JNC label Jump if Carry clear

JB bit, label Jump if bit set

JNB bit, label Jump if bit clear

JBC bit, label Jump if bit set, then clear bit

label = PC relative (+ 127)

Page 16: 8051 Assembly Language Disciplina: Microcontroladores Prof. Remy Eskinazi, MSc.

16Microcontroladores - Prof. Remy Eskinazi

Instruções 8051 – Controle do Programa

SaltosAJMP label-A Absolute Jump- 11 bits(2K) LJMP label-L Long Jump - 16 bits (64K)SJMP label Short JumpJMP @A+DPTR Jump Indirect PC (A+DPTR)JZ label Jump if zeroJNZ label Jump if not zero

Compara e SaltaCJNE A, #, label Compare 1st op to 2nd op and

A, D, label jump to label if not EqualR, #, label @R,#, label

Page 17: 8051 Assembly Language Disciplina: Microcontroladores Prof. Remy Eskinazi, MSc.

17Microcontroladores - Prof. Remy Eskinazi

Instruções 8051 – Controle do Programa

Decrementa e SaltaDJNZ R, label Rn = Rn-1 , Jump if not zero

D, label

Subrotinas (Chamadas de Funções)ACALL label-A Absolute Call - 11 bits (2K)LCALL label-L Long Call - 16 bits (64K)RET Return from SubroutineRETI Return from ISR:

PC m(SP), SP SP-2

Page 18: 8051 Assembly Language Disciplina: Microcontroladores Prof. Remy Eskinazi, MSc.

18Microcontroladores - Prof. Remy Eskinazi

Programa Acha Zero – Algoritmo

INÍCIO

DPTR ENDEREÇO INICIAL

A M(DPTR)

A=0 ?F0 1

DPTR DPTR+1

FIM?

RET

S

N

S

N

Objetivo: Determinar se em um range de memória existe um byte 0

Page 19: 8051 Assembly Language Disciplina: Microcontroladores Prof. Remy Eskinazi, MSc.

19Microcontroladores - Prof. Remy Eskinazi

Programa Acha Zero – Código Fonte

; Programa Acha Zero

; Autores: Turma Dispositivos

; Descrição: O Programa faz a busca no range 0000h a 01FFh de um byte 0.

; Se existir, sinalizamos com flag F0=1 e saímos do programa com DPTR=Posição

; do byte 0.

INICIO: MOV DPTR, #0h ; Inicia Ponteiro

CLR F0 ; Limpa Flag F0

REPETE: MOVX A, @DPTR ; Poe o dado da posição indicada pelo DPTR no

; Acumulador

CJNE A, #0h, CONTINUA ; Pula para CONTINUA se A=! 0

ACHOU: SETB F0 ; Sinaliza o encontro do valor zero com F0=1

SJMP FIM ;

CONTINUA: INC DPTR ; Se não encontrou byte zero, aponta para proxima posicao

MOV A, DPH ;

CJNE A, #02h, REPETE ; Se DPTR<0200h pula para REPETE

FIM: RET ; FIM

END ; Fim de Arquivo p/ compilação

Page 20: 8051 Assembly Language Disciplina: Microcontroladores Prof. Remy Eskinazi, MSc.

20Microcontroladores - Prof. Remy Eskinazi

Programa Acha MaiorPonteiro <-- pos. inicial( DPTR <-- 0 )

B <-- 0

Acc <-- (Ponteiro)(Acc <-- ( DPTR ))

Acc > B ?

Próxima posição(DPTR <-- DPTR + 1)

Preserva dado e end.( B <-- Acc )

( R1R0 <-- DPTR )

Acc <-- DPh

DPh = 01H ?

Acc <-- BDPTR <-- R1R0

RET

INICIO

S

N

S

N

SubrotinaAchaMaior

Ent.: DPTR = End. Inicial

Saída.: Acc = Maior valorDPTR = End. Maior dado