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