8051 Assembly Language

advertisement

Assembly Language

Computer language hierarchy

• High Level Language

• Assembly language

• Machine language

• Compiled or interpreted

• One statement maps to one or more assembly language statement

• Assembled

• One statement maps to one machine language instruction

• Loaded directly into the processor memory

• One statement maps to one or more RTL statements

Computer language hierarchy

• You can toss in the scripting languages

(PERL, Python, PHP, VBScript…)

• You can toss in the interpreted languages

(BASIC, Haskell, Lisp, Forth)

• And other categories

• The seem to fit somewhere between HLL and

Assembly but don’t run directly on the hardware (virtual machine/interpreter)

Assembly language

• This is as close as you ever get to the hardware (without actually keying in binary values – which no one ever does anymore)

• Requires a major shift in mindset from programming HLLs

Programming

• In HLL programming you concern yourself with variables, datatypes, and control statements

– int, float, char, if, for, while, arrays, etc.

• In assembly language programming you concern yourself with memory and instruction

– RAM, ROM, registers, instruction classes, addressing modes

Programming

• In HLL programming you concern yourself with keywords and grammars

– Statements, expressions, etc.

• In assembly language programming you concern yourself with mnemonics and circuit components

– Instruction names, arithmetic units, control units, etc.

Programming

• In HLL programming you sit down with a

“how to” textbook to guide you

• In assembly language programming you sit down with a chip specification document to guide you

Programming

• In HLL programming you might be able to estimate how long a program will take to run and how much memory it will use

• In assembly language programming you can calculate how long a program will take to run and how much memory it will use

Assembly programming

• You must have an understanding of the architecture on which you are running your program

• Each architecture [or family] has it’s own assembly language

– The language is intimately tied to the design of the architecture

The 8051 architecture

• 8-bit CPU with A (accumulator) and B registers

• 16-bit program counter and data pointer

• 8-bit program status word

• 8-bit stack pointer

• Internal ROM

• Internal RAM

– Four register banks of 8 registers each

– Sixteen bytes of bit addressable locations

– Eighty bytes of general purpose data memory

– Thirty two input/output pins

• Two 16-bit timer/counters

• Various control registers

• Serial port

• Interrupt sources

The 8051 instruction set

• Instruction classes

– Arithmetic operations

– Logical operations

– Data transfer

– Boolean variable manipulation

– Program branching

The 8051 instruction set

• The processor status word (PSW)

– Carry flag

– Auxiliary carry flag

– General purpose flags (2)

– Register bank selector (2 bits)

– Overflow flag

– Parity flag

The 8051 instruction set

• Addressing modes

– Register

– Direct

– Indirect-register

– Constant 8-bit

– Constant 16-bit

– Address 16-bit

– Address 11-bit

– Relative

– Bit

Addressing modes

• Rn where 0 ≤ n ≤ 7 – the contents of register n;

• 0x00 (or other hex number) – the contents of a memory location

• @Ri where 0 ≤ i ≤ 1 – indirect, register holds the memory address

• #0x00 (or other hex number) – 8-bit constant number

• #0x00 16 (or other hex number) – 16-bit constant number

• There are a few others but these are the most commonly used modes

Data transfer instructions

• MOV op-code

• Various operands dependant on desired addressing mode

– Some examples:

MOV A, R0 ; A = R0

MOV A, #0x00 ; A = 0

MOV A, 0x00 ; A = memory[0]

MOV A, @R0 ; A = memory[R0]

MOV R0, A ; R0 = A

Simulator

• We don’t have an 8051 processor

• The next best thing is a simulator

• Download EdSim51 from EdSim51

– This is a Java executable (.jar) file that runs on both Windows and MacOS

• Documentation is available on the download site

Download