1 / 34

TK 2123

TK 2123. Lecture 13: Assembly Language Level (Level 4). 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.

Download Presentation

TK 2123

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. TK 2123 Lecture 13: Assembly Language Level (Level 4)

  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 Prepared 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. Prepared by: Dr Masri Ayob

  4. Why Use Assembly Language? Comparison of assembly language and high-level language programming, with and without tuning. Prepared 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. Prepared 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. Prepared by: Dr Masri Ayob

  7. Assembly Language • The Two-pass Assembler : • Read programme two times. • Generate a table of the labels/symbols within the source program. • Develop hexadecimal version of the source program. • Allow forward addressing (the software can jump ahead to an instruction in a program). Prepared by: Dr Masri Ayob

  8. Assembly Language Prepared by: Dr Masri Ayob

  9. Assembly Language • The assembler always assumes that the first instruction of the program is stored at memory address 0000H unless otherwise directed by the ORG command. Prepared by: Dr Masri Ayob

  10. Assembly Language • 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. Prepared by: Dr Masri Ayob

  11. Assembly Language • 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. Prepared by: Dr Masri Ayob

  12. Assembly Language • 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. Prepared by: Dr Masri Ayob

  13. Format of an Assembly Language Statement (1) Computation of N = I + J. (a) Pentium 4. Prepared by: Dr Masri Ayob

  14. Format of an Assembly Language Statement (2) Computation of N = I + J. (b) Motorola 680x0. Prepared by: Dr Masri Ayob

  15. Format of an Assembly Language Statement (3) Computation of N = I + J. (c) SPARC. Prepared by: Dr Masri Ayob

  16. Assembly Language • 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. Prepared by: Dr Masri Ayob

  17. Assembly Language • Operand arithmetic operations. Prepared by: Dr Masri Ayob

  18. Assembly Language • 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 : Prepared by: Dr Masri Ayob

  19. Pseudoinstructions • 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. Prepared by: Dr Masri Ayob

  20. Pseudoinstructions • Define Byte (DB). • Defines 8-bit memory data for a program. • Multiple one byte data, comma ( , ) as a separator. Prepared by: Dr Masri Ayob

  21. Assembly Language : Example Prepared by: Dr Masri Ayob

  22. Pseudoinstructions • 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. Prepared by: Dr Masri Ayob

  23. Assembly Language : Example Prepared by: Dr Masri Ayob

  24. Pseudoinstructions • 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. Prepared by: Dr Masri Ayob

  25. Assembly Language : Example Prepared by: Dr Masri Ayob

  26. Pseudoinstructions • Define Storage (DS). • Reserves space in a program for variable data. • Does not place any specific data into the reserved area of memory. Prepared by: Dr Masri Ayob

  27. Assembly Language : Example Prepared by: Dr Masri Ayob

  28. Pseudoinstructions • Equate (Equ). • Equates a label to another label or value. • Note that the EQU statement label does not contain a colon ( : ). Prepared by: Dr Masri Ayob

  29. Assembly Language Prepared by: Dr Masri Ayob

  30. Macro • 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. Prepared 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 Prepared by: Dr Masri Ayob

  32. Macro Definition, Call, Expansion (2) Comparison of macro calls with procedure calls. Prepared by: Dr Masri Ayob

  33. Macros with Parameters Nearly identical sequences of statements. (a) Without a macro. (b) With a macro. Prepared by: Dr Masri Ayob

  34. Thank youQ&A Prepared by: Dr Masri Ayob

More Related