Presentation is loading. Please wait.

Presentation is loading. Please wait.

HTP Programme: Assembler

Similar presentations


Presentation on theme: "HTP Programme: Assembler"— Presentation transcript:

1 HTP Programme: Assembler
Principles and Examples Joe Finney

2 Aims Today we’re going to… Discuss the purpose for Assembly Language
Review the common principles on which Assembly Languages are based Study a REAL assembly language Read and write simple assembly programs

3 Assembly Language Computer Processors
Execute machine code instructions. Every clock tick, the next instruction is executed* Machine code is essentially a processor specific, binary representation of a simple instruction. Provide the smallest “building block” we use to create computer programs. All higher level languages (C, Python, Java…) are ultimately translated one way or another into machine code. Assembly Language is a textual, humanly readable* programming language 1:1 mapping between an ASSEMBLY instruction and a MACHINE CODE instruction. Abstract Java / Python / C#... Assembly Language Machine Code Reality

4 Assembly Language Why? Sometimes (but rarely) we want to write code at this very low level… Programs with extremely tight timing constraints… times to execute line of code are deterministic. May need access to processor in a way not supported by high level languages. E.g. If you were writing a scheduler. If you were stuck on an alien planet with no software. You could write the first compiler in assembler.  Abstract Java / Python / C... Assembly Language Machine Code Reality

5 Assembly Language Principles One assembler instruction per line
One assembler instruction matches one machine instruction. An assembler instruction has one operator and zero or more comma separated operands. Operators are instructions (things to do) Include instructions like ADD, SUB, GOTO, BZ… Defined by the processor’s capabilities. e.g. ADD R0, 1 Operands are parameters (data to work on) Use on of four addressing modes.

6 Assembly Language Addressing Modes Operands can be immediate
Operand contains a literal value. Typically denoted by a # Operands can be direct Operand contains memory address of the value Typically the default. Operands can be indexed Operand contains memory address of the value plus and offset Typically uses a + sign Operands can be indirect Operand contains the memory address of the memory address that holds the value ADD R0, #1 ADD R0, 1 ADD R0, 1+16 ADD R0, [1]

7 Assembly Language Example Worlds smallest commercial 8 bit computer
Size is 3mm x 2mm x 0.9 mm Cost is around 30 pence per unit (retail) Weighs considerably less than one gram Capable of one million operations /sec Highly reliable – designed to benefit in situ for decades at a time (40 years data retention) Consumes less than 15uW at low speeds

8 PIC Assembler Syntax PIC Assembler has strict formatting…
[Label:] [<opcode> [<operand>][, <destination>]] Everything is TAB separated. (one or more) At most one opcode per line (instruction to execute) Depending on the opcode, may also have an operand and a destination. Operand is opcode specific, either a RAM address or literal a value. Destination (if present) is always either W or F. W = Working Register F = File (the one specified in the operand) Let‘s Review its Instruction set…

9 Assembly Language Write a program to…
Add together two numbers, which are stored in memory addresses 0x40 and 0x41. The result should be stored in memory location 0x42. MOVF 0x40, W ADDWF 0x41, W MOVWF 0x42 END

10 Assembly Language Write a program to…
Determine if the number stored in memory location 0x40 is odd or even. Write the ASCII value for the letter ‘E’ or ‘O’ to memory location 0x41 to store the result. MOVLW 69 BTFSC 0x40, 0 MOVLW 79 MOVWF 0x41 END

11 Assembly Language Write a program to…
Perform a countdown from the value five to the value one. Write each number to memory location 0x41 in turn. MOVLW 5 MOVWF 0x40 COUNTDOWN: MOVF 0x40, W MOVWF 0x41 DECFSZ 0x40, F GOTO COUNTDOWN END

12 References…

13 References…

14 References…


Download ppt "HTP Programme: Assembler"

Similar presentations


Ads by Google