1 / 19

8051 Assembly Language

8051 Assembly Language. Disciplina: Microcontroladores Prof. Remy Eskinazi, MSc. Modos de endereçamento 8051 (1). Imediato ( Direto) - (Label ou Número) MOV PSW,05 ; M(PSW) R5 MOV A,045 10 ; Acc M(45 10 )

nalani
Download Presentation

8051 Assembly Language

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 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 Microcontroladores - Prof. Remy Eskinazi

  3. 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 Microcontroladores - Prof. Remy Eskinazi

  4. Modos de endereçamento 8051 (3) • Saltos e desvios (controle de programa) Exemplos: Salto Incodicional: JMP (Address16) AJMP (Address11) SJMP (Address8) LJMP (Address16) Salto condicional: JC (Address8) JNC (Address8) JB (Address8) JNB (Address8) Microcontroladores - Prof. Remy Eskinazi

  5. Exemplo de Programa Assembly ; **** Programa Exemplo *** ; **** Objetivo: Explicar campos de um programa assembly 8051 **** Valor: equ 02h org 0h ;Reset sjmp inicio org 03 ; Int. Externa 0 sjmp ext0 Inicio: mov A, #0FFh mov R1, #valor DB 02h DB ‘A’ ; ASCII do caractere A End ; Fim de programa p/ compilação Microcontroladores - Prof. Remy Eskinazi

  6. 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) Microcontroladores - Prof. Remy Eskinazi

  7. Instruções 8051 – Movimentação de Dados • MOVE • MOV A, #n A Immediate • Direct A Direct R A Register • @Ri A Register Indirect MOV Rn, # Rn Immediate Direct … A MOV Direct, # DirectImmediate Direct … R @R A MOV @Ri, # M(Ri) Immediate Direct … A Microcontroladores - Prof. Remy Eskinazi

  8. 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 Microcontroladores - Prof. Remy Eskinazi

  9. Instruções 8051 – Aritméticas • Add/Subtract • ADD A, # Acc A+Immediate • D R • @R ADDC A, # Acc A+Immediate+Carry D R @R SUBB A, # Acc Acc-Immediate-Carry D R @R Microcontroladores - Prof. Remy Eskinazi

  10. Instruções 8051 – Aritméticas • Inc/Dec • INC A Acc Acc+1 • D R • @R • DPTR • 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 ) Microcontroladores - Prof. Remy Eskinazi

  11. Instruções 8051 – Lógicas • AND,OR,XOR • AND A, # • ORL D XRL R • @R • D, A • D, # • Outras CLR A Acc 0 CPL A Acc Acc SWAP A Acc(7-4) Acc(3-0) Microcontroladores - Prof. Remy Eskinazi

  12. Instruções 8051 – Lógicas • Rotações • RL A • RLC A • RR A • RRC A 7 0 Acc 7 0 C Acc 7 0 Acc 7 0 Acc C Microcontroladores - Prof. Remy Eskinazi

  13. Instruções 8051 – Manipulação de Bits • Clear/Set/Complement • CLR C Carry 0 • bit bit 0 SETB C • bit • CPL C • bit • And, Or, Move • ANL C, bit Carry Carry AND bit • C, /bit Carry Carry AND bit ORL C, bit • C, /bit • MOV C, bit • bit, C Microcontroladores - Prof. Remy Eskinazi

  14. 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) Microcontroladores - Prof. Remy Eskinazi

  15. Instruções 8051 – Controle do Programa • Saltos • AJMP label-A Absolute Jump- 11 bits(2K) • LJMP label-L Long Jump - 16 bits (64K) SJMP label Short Jump • JMP @A+DPTR Jump Indirect PC (A+DPTR) JZ label Jump if zero • JNZ label Jump if not zero • Compara e Salta • CJNE A, #, label Compare 1st op to 2nd op and • A, D, label jump to label if not Equal • R, #, label • @R,#, label Microcontroladores - Prof. Remy Eskinazi

  16. Instruções 8051 – Controle do Programa • Decrementa e Salta • DJNZ 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 Subroutine • RETI Return from ISR: • PC m(SP), SP SP-2 Microcontroladores - Prof. Remy Eskinazi

  17. Programa Acha Zero – Algoritmo INÍCIO DPTR  ENDEREÇO INICIAL Objetivo: Determinar se em um range de memória existe um byte 0 A  M(DPTR) S F0  1 A=0 ? N DPTR  DPTR+1 N FIM? S RET Microcontroladores - Prof. Remy Eskinazi

  18. 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 Microcontroladores - Prof. Remy Eskinazi

  19. Programa Acha Maior Ponteiro <-- pos. inicial ( DPTR <-- 0 ) B <-- 0 Próxima posição (DPTR <-- DPTR + 1) Preserva dado e end. ( B <-- Acc ) ( R1R0 <-- DPTR ) Acc <-- DPh Acc <-- B DPTR <-- R1R0 Acc <-- (Ponteiro) (Acc <-- ( DPTR )) Acc > B ? DPh = 01H ? RET INICIO Ent.: DPTR = End. Inicial Subrotina AchaMaior Saída.: Acc = Maior valor DPTR = End. Maior dado S N N S Microcontroladores - Prof. Remy Eskinazi

More Related