EE 5340/7340 Motorola 68HC11 Microcontroler Lecture 1 Carlos E. Davila, Electrical Engineering Dept. Southern Methodist University
What is Assembly Language? Assembly language is a programming language that is specific to every type of processor, i.e. it s machine dependent. Each processor has its own assembly language instruction set. Higher level language is machine independent, i.e. C, Fortran can be run on any machine (DEC, IBM, ) Generally, assembly language does very simple things like load a register with a number or add a number to an accumulator. One high level language instruction often does the equivalent of many assembly language instructions.
Elements of an Assembly Language Program assembler directives: tell the assembler to do certain things, not part of the processor instruction set. assembly language instructions: tell the processor what to do. labels: used for branching, etc. documentation: used to remind us what the program is doing. Effective use of assembly language requires that we know something about the processor architecture.
Motorola 68HC11 Architecture CPU A/D Converter Serial Port Memory Timer Address Bus Data Bus Memory (RAM, ROM, EPROM)
CPU 8-bit accumulators A and B (or 16-bit accumulator D) Program counter (16-bit) Condition Code register 16-bit index registers X and Y Stack pointer (16-bit)
Accumulators A and B Registers which can be used to store 8-bit numbers. We can also add a number to the current contents of an accumulator, which are then replaced by the sum i.e. (A) = 4 contents of A is 4 ADDA #7 adds the number 7 to current contents (A) = 11 contents of A are now 4 + 7 = 11 Data in memory can be transferred to an accumulator using the LDAA or LDAB instructions. Accumulator data can be written to memory via the STAA and STAB instructions.
Memory Model 0000 0001 0002. FFFF $FFFF = 64K 8-bit memory words
OP Codes For every instruction, there corresponds an OP code, a binary number which is stored in program memory. The OP code is what is understood by the processor. The reference manual indicates what OP codes correspond to what instructions. Many instructions have 16-bit (1-word) OP codes. Other instructions have OP code lengths which vary depending on the type of addressing mode used. Addressing modes are the different ways that the processor accesses/writes data from/to memory.
Program Counter (PC) 16-bit Program Counter (PC) contains address of current instruction to be executed. During sequential execution: PC = PC + length of current instruction (LOCI). Branch instruction causes PC to be loaded with 16 bit operand immediately following the branch instruction. During a call to a subroutine, PC+LOCI is pushed on the stack (we ll look at the stack later). And PC is loaded with starting address of subroutine. Return instruction pops the return address from the top of the stack back into the PC. Interrupt, causes PC to be pushed on the stack and PC is loaded with address of interrupt vector (we ll look at interrupts later.
Assembly Language Instruction Fields [label] mnemonic [operand] [comment] labels must begin in column 1, all other fields must be preceded by at least one blank. [ ] = optional each field must be separated by one or more blanks mnemonic can be either an instruction or an assembler directive Comment can also be in column 1 if preceded by a *
Addressing Modes ex) LDAA dat ;load acc A with number dat addressing mode determines how the number dat is fetched addressing modes: Immediate Direct Extended Indexed Relative
Immediate Addressing num EQU 31 ;num is set to 31 LDAA #31 ;load acc A with 31 LDAB #$1Fh ;load acc B with 31 LDAA #num ;load acc A with 31
Direct Addressing Can use direct addressing to get the number 31 in memory: dat RMB 1 reserve 1 memory byte for dat LDAA #31 STAA dat When the assembler encounters the RMB line, it associates the symbol dat with a memory address (usually in data RAM). Direct addressing then references the memory location where the desired operand is stored: LDAB dat load acc B with number ;stored in address dat Only the low address byte goes in program memory! The upper byte is assumed to be $00.
Extended Addressing LDAA dat ;load acc A with number ;stored in address dat Assume dat = $8015, the following OP code is placed in program memory: $B6 $80 $15 so instruction uses up 3 words of program memory.
Indexed Addressing Index registers X and Y are used to point to memory locations by loading them with the address we wish to access. Contents of X or Y can be offset Index registers can be incremented with INX instruction to point to the next byte Ex) LDX dat LDAA 0, X contents of address dat go in ACC A (zero offset)
Condition Code Register S X H I N Z V C C: set if there if a carry was generated V: set if there is a 2 s complement overflow N: set if result is negative Z: set if result is zero
68HC11 Software Development Tools Text Editor: used to create an ASCII text file (*.ASM) containing the assembly language program Assembler: converts the assembly language instructions in *.asm to hex object code file *.s19 Loader and Debugger: used to load object file into memory, allows you to step through the program one instruction at a time to check your code. Let s you view the contents of the processor s memory, registers, and accumulators as your step through the program.
Assembler Directives ORG: start at this address ORG $2000 RMB: reserve memory bytes ORG $2000 dat RMB 1 means that dat * corresponds to $2000 EQU: equate a symbol with a constant const EQU 31 FCB: form constant byte ORG $2000 dat FCB 31 location $2000 contains 31