Download presentation
Presentation is loading. Please wait.
Published byRolf Barker Modified over 8 years ago
1
Ass. Prof. Dr Masri Ayob TK 6123 Lecture 13: Assembly Language Level (Level 4)
2
3 June 2016Prepared by: Dr Masri Ayob 2 Why Use Assembly Language? Assembly language programming is difficult. Writing a program in assembly language takes much longer than writing the same program in a high-level language. Much longer to debug and much harder to maintain. Why use assembly language? Performance Access to the machine
3
3 June 2016Prepared by: Dr Masri Ayob 3 Why Use Assembly Language? Performance An expert assembly language programmer can often produce code that is much smaller and faster than a high- level language programmer can. Some application – speed and size are critical. E.g. embedded application (code on a smart card, handphone, etc.) Access to the machine. Some procedure need complete access to the hardware. E.g. low-level interrupt, trap handlers in OS, device controller, etc. This is usually impossible in high-level language.
4
3 June 2016Prepared by: Dr Masri Ayob 4 Why Use Assembly Language? Comparison of assembly language and high-level language programming, with and without tuning.
5
3 June 2016Prepared by: Dr Masri Ayob 5 Assembly Language Assembly language: Assembly language is used for most programming because it is extremely difficult to program a microprocessor in its native, that is hexadecimal machine language. Assembler: An assembler is a program that converts software written in symbolic machine language (the source program) into hexadecimal machine language (object program). The primary reason to use assembler is because development and modification are always difficult in machine language.
6
3 June 2016Prepared by: Dr Masri Ayob 6 Assembly Language Instruction is a command to the microprocessor to perform a given task on specified data. Each instruction has two parts: one is the task to be performed, called the operation code (op-code), the second is the data to be operated on, called the operand. The operand (or data) can be specified in various ways. It may include an internal register or a memory location. In some instructions, the operand is implicit.
7
3 June 2016Prepared by: Dr Masri Ayob 7 Assembly Language The Two-pass Assembler : Read programme two times. 1. Generate a table of the labels/symbols within the source program. 2. Develop hexadecimal version of the source program. Allow forward addressing (the software can jump ahead to an instruction in a program).
8
3 June 2016Prepared by: Dr Masri Ayob 8 Assembly Language
9
3 June 2016Prepared by: Dr Masri Ayob 9 The assembler always assumes that the first instruction of the program is stored at memory address 0000H unless otherwise directed by the ORG command. Assembly Language
10
3 June 2016Prepared by: Dr Masri Ayob 10 Pass One: The assembler scans the source program during the first pass and generates a table of the labels found within the source program. Each entry in the label table contains the label and the address where the label appears in the program. During the first pass the assembler determines the length of each instruction by updating an internal program counter. This internal program counter allows the assembler to complete the label table by equating each label with the counter. Once the label table is complete the second pass begin. Assembly Language
11
3 June 2016Prepared by: Dr Masri Ayob 11 Pass Two: During the second pass of the source program, the assembler forms the object program. This occurs by referring to the label table for any labels that appear in the program and to an instruction table. The instruction table contains all the opcodes in both symbolic and machine language forms. The tables help convert the source program into the object program. Assembly Language
12
3 June 2016Prepared by: Dr Masri Ayob 12 Assembly Language Statement: Format : Label Field. Contains a symbolic memory address that refers to the statement in a program. Labels are optional. Labels are constructed from alphanumeric characters and must begin with any letter of the alphabet. Assembly Language
13
3 June 2016Prepared by: Dr Masri Ayob 13 Format of an Assembly Language Statement (1) Computation of N = I + J. (a) Pentium 4.
14
3 June 2016Prepared by: Dr Masri Ayob 14 Format of an Assembly Language Statement (2) Computation of N = I + J. (b) Motorola 680x0.
15
3 June 2016Prepared by: Dr Masri Ayob 15 Format of an Assembly Language Statement (3) Computation of N = I + J. (c) SPARC.
16
3 June 2016Prepared by: Dr Masri Ayob 16 Opcode field: This field must contain opcodes. Operand field: May contain register name, data or labels. If more than one of these is present, they must be separated with comma. Data must be encoded as decimal, binary, octal, hexadecimal, or ASCII. ASCII must appear as one of more letters surrounded by apostrophe. Assembly Language
17
3 June 2016Prepared by: Dr Masri Ayob 17 Operand arithmetic operations. Assembly Language
18
3 June 2016Prepared by: Dr Masri Ayob 18 Comment field. Must begin with semicolon in most 8085 assemblers and may continue to the end of the line only. Use asterisk * or semicolon ; if the comment should continue into the next line. Example : Assembly Language
19
3 June 2016Prepared by: Dr Masri Ayob 19 Assembler pseudo operations. Directives to the assembler program that may or may not generate machine code. Examples : END, DB, DW, DS, ORG, EQU, IF, ENDIF, SET, GLB, EXT, TITLE, SPC. All pseudo operations must appear in the opcode field of a statement. Pseudoinstructions
20
3 June 2016Prepared by: Dr Masri Ayob 20 Define Byte (DB). Defines 8-bit memory data for a program. Multiple one byte data, comma (, ) as a separator. Pseudoinstructions
21
3 June 2016Prepared by: Dr Masri Ayob 21 Assembly Language : Example
22
3 June 2016Prepared by: Dr Masri Ayob 22 Origin (ORG). Changes the starting location of the program to another address besides 0000H. Can be used at any place in a program to change the location of the assembled machine language instructions or data. Pseudoinstructions
23
3 June 2016Prepared by: Dr Masri Ayob 23 Assembly Language : Example
24
3 June 2016Prepared by: Dr Masri Ayob 24 Define Word (DW). Pseudo operation stores a 16-bit number in the memory for use by a program. Defines no only numeric data but also memory addresses and label. Pseudoinstructions
25
3 June 2016Prepared by: Dr Masri Ayob 25 Assembly Language : Example
26
3 June 2016Prepared by: Dr Masri Ayob 26 Define Storage (DS). Reserves space in a program for variable data. Does not place any specific data into the reserved area of memory. Pseudoinstructions
27
3 June 2016Prepared by: Dr Masri Ayob 27 Assembly Language : Example
28
3 June 2016Prepared by: Dr Masri Ayob 28 Equate (Equ). Equates a label to another label or value. Note that the EQU statement label does not contain a colon ( : ). Pseudoinstructions
29
3 June 2016Prepared by: Dr Masri Ayob 29 Assembly Language
30
3 June 2016Prepared by: Dr Masri Ayob 30 Assembly language programmer frequently need to repeat sequence of instructions several times within a program. Solution: Use subroutine (CALL instruction). Disadvantage: Procedure CALL overhead. Use Macro Easy and efficient solution Is a way to give name to a piece of text. Macro
31
3 June 2016Prepared by: Dr Masri Ayob 31 Macro Definition, Call, Expansion (1) Assembly language code for interchanging P and Q twice. (a) Without a macro. (b) With a macro. Macro
32
3 June 2016Prepared by: Dr Masri Ayob 32 Macro Definition, Call, Expansion (2) Comparison of macro calls with procedure calls.
33
3 June 2016Prepared by: Dr Masri Ayob 33 Macros with Parameters Nearly identical sequences of statements. (a) Without a macro. (b) With a macro.
34
3 June 2016Prepared by: Dr Masri Ayob 34 Thank you Q&A
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.