Docsity

Assembly Microcontroller 8051, Manuais, Projetos, Pesquisas de Programação Assembly

Pré-visualização parcial do texto

Baixe Assembly Microcontroller 8051 e outras Manuais, Projetos, Pesquisas em PDF para Programação Assembly, somente na Docsity!

Week 2

8051 Assembly Language

ProgrammingChapter 2

Outline2.1^ Inside the 80512.2^ Introduction to 8051 Assemblyprogramming2.3^ Assembling and running an 8051 program2.4^ The program counter and ROM space inthe 80512.5^ 8051 data types and directives2.6^ 8051 flag bits and the PSW register2.7^ 8051 register banks and stack

On-chip RAM

8051 Registers ‰^ Registers are used to store informationtemporarily. ‰^ The 8051 has 8-bit registers and 16-bitregisters.^ ❍^ many 8-bit registers in Figure 2-1 (a)^ ❍^ two 16-bit registers in Figure 2-1(b)

16 bit Registers ‰^ DPTR: data pointer - the 16-bit addressfor the data located in program (ROM) orexternal RAM^ ❍^ DPL low byte of DPTR^ ❍^ DPH high byte of DPTR ‰^ PC program counter - the address of thenext instruction

Special Function Registers SFR

Instruction Set SummaryTable A-1: 8051 Instruction Set Summary1. Data Transfer

:get or store data

❍^ MOV, PUSH, POP2. Arithmetic Operations

❍^ ADD, SUB, INC, DEC, MUL, DIV3. Logical Operations

❍^ ANL, ORL, XRL, CLR4. Program Branching

:jump, loop, call

instruction^ ❍^ LCALL, RET, LJMP, JZ, JNZ, NOP

MOV Instruction ‰^ Copy the source operand to the destinationoperand.^ MOV destination, source

copy MOV^ A,#55H

;load value 55H into reg. A;now A=55H (H:

hexadecimal

)

MOV^ R6,#

;load 12

decimal

into R ;now R6=12=0CH MOV^ R0,A

;copy contents of A into R0;now A=55H, R0=55H ❍^ The pound sign ”

#” indicates that it is an

immediate value.

❍^ You can write your command after the semicolon “

;”.

MOV - more ‰^ Other examples^ MOV^

A,#’4’^

;load ASCII ‘4’ into A;now A=34H

-^ The immediate value can be copied to A, B,R0-R7.

ADD Instruction ‰^ Add the source operand to register A andput the result in A.^ ADD A, source

A + source

→^ A MOV^ A,#25H

;load 25H into A MOV^ R2,#34H ;load 34H into R2ADD^ A,R

;add R2 to A=A+R2;now A=59H, R2=34H

‰^ Register A must be the destination of anyarithmetic operation.^ ADD

R0,A^

;illegal

Assembly Language Programming ‰^ Machine language^ ❍^ a program that consists of 0s and 1’s.^ ❍^ CPU can work on machine language directly.^ ❍^ Example 7D25 ‰^ Low-level language^ ❍^ It deals directly with the internal structure ofthe CPU.^ ❍^ Programmers must know all details of the CPU.^ ❍^ Example MOV R5,#25H 8051 assembly language ‰^ High-level language^ ❍^ Machine independent^ ❍^ Example a=37;C++

Assembly Language Programming ‰^ Assembly languages were developed whichprovided mnemonics for the machine codeinstructions, plus other features.^ ❍^ Mnemonic: the instruction• Example: MOV, ADD^ ❍^ Provide decimal numbers, named registers,labels, comments^ ❍^ programming faster and less prone to error. ‰^ Assembly language programs must betranslated into machine code by a programcalled an assembler.

Assembly Language Programs ‰^ An Assembly language program (see Program 2-1)is a series of statements.^ [label:]

mnemonic

[operands]

[;comment]

❍^ Brackets indicate that a field is optional. ❍^ Label is the name to refer to a line of program code. Alabel referring to an instruction must be followed by acommon “

:”. Here: SJMP HERE ❍^ Mnemonic and operand(s) perform the real work of theprogram. ❍^ The comment field begins with a semicolon “

;”.

Mnemonic vs Directives ‰^ Two types of assembly statements^ ❍^ Mnemonic tells the CPU what to do• Example MOV, ADD• These instructions are translated into machine codefor the CPU to execute.^ ❍^ Pseudo-instruction gives directions to theassembler• Example ORG 0H, END• Pseudo-instructions are called directives, too.• Pseudo-instructions do not generate any machine codeand are used only by the assembler.