1 / 63

Fundamental of Assembly Language Programming (for Microprocessor)

Prima Dewi Purnamasari Microprocessor Electrical Engineering Department Universitas Indonesia. Fundamental of Assembly Language Programming (for Microprocessor). Computer Language. High Level language Pascal, C, C++, Java, etc Low Level Language Assembly Machine Codes

cliff
Télécharger la présentation

Fundamental of Assembly Language Programming (for Microprocessor)

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. Prima DewiPurnamasari Microprocessor Electrical Engineering Department Universitas Indonesia Fundamental of Assembly Language Programming (for Microprocessor)

  2. Computer Language • High Level language • Pascal, C, C++, Java, etc • Low Level Language • Assembly • Machine Codes • 010010001010100101010  in binary • 1234 FFAB 1234 H  in hexadecimal Microprocessor (c) Prima Dewi Purnamasari 2011

  3. Why Assembly? • Assembly has several features that make it a good choice many some situations. • It's fast – Assembly programs are generally faster than programs created in higher level languages. Often, programmers write speed-essential functions in assembly. • It's powerful – You are given unlimited power over your assembly programs. Sometimes, higher level languages have restrictions that make implementing certain things difficult. • It's small – Assembly programs are often much smaller than programs written in other languages. This can be very useful if space is an issue. Microprocessor (c) Prima Dewi Purnamasari 2011

  4. Preparation for Assembly Programming • Basically you will need: • Program editor  as simple as Notepad • Assembler • MASM  http://www.masm32.com/. • TASM  Made by Borland, a commercial product • NASM  http://sourceforge.net/projects/nasm/ • Be careful in writing your programs, because it runs directly on your microprocessor! Microprocessor (c) Prima Dewi Purnamasari 2011

  5. Steps to Create a Program Microprocessor (c) Prima Dewi Purnamasari 2011

  6. MASM32 Microprocessor (c) Prima Dewi Purnamasari 2011

  7. TASM Microprocessor (c) Prima Dewi Purnamasari 2011

  8. Emulator • an emulator is hardware and/or software that duplicates (or emulates) the functions of a first computer system in a different second computer system, so that the behavior of the second system closely resembles the behavior of the first system. Microprocessor (c) Prima Dewi Purnamasari 2011

  9. Emu8086 Microprocessor (c) Prima Dewi Purnamasari 2011

  10. Individual Assignment • Download and install • emu8086 (trial) • http://www.emu8086.com/ • Find corresponding tutorial on how to use it (available on the Internet!), self study! Microprocessor (c) Prima Dewi Purnamasari 2011

  11. Group assignment • Each group is responsible to bring at minimum 1 laptop (with emu8086 installed) to class every session Microprocessor (c) Prima Dewi Purnamasari 2011

  12. Creating an Assembly Language Program • An assembly language program should be written with any text editor and have the extension filename.asm. • The assembler and Linker • The assembler program converts a symbolic source module (file) into a hexadecimal object file • The linker program executes as the second part of ML, reads the object files, created by the assembler program, and links them into a single execution file (.EXE) Microprocessor (c) Prima Dewi Purnamasari 2011

  13. Microprocessor (c) Prima Dewi Purnamasari 2011

  14. Assembly Program Structure Microprocessor (c) Prima Dewi Purnamasari 2011

  15. Microprocessor (c) Prima Dewi Purnamasari 2011

  16. LIST File, generated automatically after program successfully assembled MemoryAddress Machine codes Microprocessor (c) Prima Dewi Purnamasari 2011

  17. Writing Structure • NEXT: MOV AX, [BX] ; comment • 1= label, followed by “:” • 2= opcode • 3= operand • 4= comment, preceded with”;” 1 2 3 4 Microprocessor (c) Prima Dewi Purnamasari 2011

  18. Writing Structure • Each statement in an assembly language program consists of four parts or fields. • The leftmost field is called the label. • used to store a symbolic name for the memory location it represents • All labels must begin with a letter or one of the following special characters: @, $, -, or ?. • a label may have any length from 1 to 35 characters • The label appears in a program to identify the name of a memory location for storing data and for other purposes. Microprocessor (c) Prima Dewi Purnamasari 2011

  19. The next field to the right is the opcode field. • designed to hold the instruction, or opcode • the MOV part of the move data instruction is an example of an opcode • Right of the opcode field is the operand field. • contains information used by the opcode • the MOV AL,BL instruction has the opcode MOV and operands AL and BL • The comment field, the final field, contains a comment about the instruction(s). • comments always begin with a semicolon (;) Microprocessor (c) Prima Dewi Purnamasari 2011

  20. Try it in emulator! • Click “View” and look the changes in every menu list: • registers • Data • Screen • Flags • etc Microprocessor (c) Prima Dewi Purnamasari 2011

  21. Computer Data Formats Microprocessor (c) Prima Dewi Purnamasari 2011

  22. Computer Data Formats • ASCII and Unicode Data • Binary Coded Decimal (BCD) • Byte-Sized Data • Word-Sized Data • Doubleword-Sized Data • Real Numbers Microprocessor (c) Prima Dewi Purnamasari 2011

  23. ASCII Data • American Standard Code for Information Interchange (ASCII) data represent alphanumeric characters in the memory of a computer system (Table 1.7) • The standard ASCII code is a 7-bit code with the eighth and MSB used to hold parity in some systems • ASCII are most often stored in memory using a special directive to the assembler program called define byte(s) or DB Microprocessor (c) Prima Dewi Purnamasari 2011

  24. Microprocessor (c) Prima Dewi Purnamasari 2011

  25. BCD Data • Binary-Coded Decimal (BCD) information is stored in either packed or unpacked forms • Packed BCD data are stored as two digits per byte • Unpacked BCD data are stored as one digit per byte • The range of a BCD digit extends from 00002 to 10012 or 0-9 decimal • Table 1.9 shows some decimal numbers converted to both packed ad unpacked BCD Microprocessor (c) Prima Dewi Purnamasari 2011

  26. Microprocessor (c) Prima Dewi Purnamasari 2011

  27. Byte-Sized Data • Byte-size data are stored as unsigned and signed integers • Negative signed numbers are stored in the 2’s complement form • Whenever a number is 2’s complement, its sign changes from negative to positive or positive to negative • See example 1-22, 1-23 Microprocessor (c) Prima Dewi Purnamasari 2011

  28. Microprocessor (c) Prima Dewi Purnamasari 2011

  29. Define bit(DB) directive is used to store 8-bit data in memory Microprocessor (c) Prima Dewi Purnamasari 2011

  30. Word-sized Data • A word (16-bits) is formed with two bytes of data • The LSB is always stored in the lowest-numbered memory location, the MSB in the highest (i.e., little endian format)—used with Intel family of microprocessor • An alternate method (i.e., big endian format) is used with the Motorola family of micro-processors Microprocessor (c) Prima Dewi Purnamasari 2011

  31. Word-sized Data • Fig 1.11(a) & (b) shows the weight of each bit position in a word of data Microprocessor (c) Prima Dewi Purnamasari 2011

  32. Microprocessor (c) Prima Dewi Purnamasari 2011

  33. Example 1.25 shows several signed and unsigned word-sized data stored in memory using the assembler program • Note that define word(s) directive or DW causes the assembler to store words in the memory Microprocessor (c) Prima Dewi Purnamasari 2011

  34. Microprocessor (c) Prima Dewi Purnamasari 2011

  35. Doubleword-sized Data • Doubleword-sized data requires four bytes of memory (32-bit number) • Doubleword-sized data appear as a product after a multiplication and also as a dividend before a division • Fig. 1-12 shows the form used to store doublewords in the memory and the binary weights of each bit position Microprocessor (c) Prima Dewi Purnamasari 2011

  36. Microprocessor (c) Prima Dewi Purnamasari 2011

  37. To define doubleword-sized data, use assembler directive define doubleword or DD Microprocessor (c) Prima Dewi Purnamasari 2011

  38. Real Numbers • A real number (floating-point number) contains two parts: a mantissa, significant, or fraction and an exponent • Fig. 1-13 and example 1-27 depicts both the 4-byte (single precision) and 8-byte (double precision) forms of real numbers Microprocessor (c) Prima Dewi Purnamasari 2011

  39. Microprocessor (c) Prima Dewi Purnamasari 2011

  40. The exponent is stored as a biased exponent • an exponent of 23 is represented as a biased exponent of 127+3 or 130 (82H) in the single- precision form or as 1026 (402H) in the double-precision form Microprocessor (c) Prima Dewi Purnamasari 2011

  41. Microprocessor (c) Prima Dewi Purnamasari 2011

  42. Assembler detail From chapter 4 42 Microprocessor (c) Prima Dewi Purnamasari 2011 Microprocessor (c) Prima Dewi Purnamasari 2011

  43. Directives • Indicate how an operand or section of program is to be processed by the assembler • Storing Data in a Memory Segment: DB, DW, DD, SEGMENT, .DATA, ENDS, DUP, ALIGN e.g.: Example 4.12 • THIS refers the data as byte or word Microprocessor (c) Prima Dewi Purnamasari 2011

  44. Memory is reserved for use in the future by using a question mark (?) as an operand for a DB, DW, or DD directive. • when ? is used in place of a numeric or ASCII value, the assembler sets aside a location and does not initialize it to any specific value • DUP: creates array with or without initial values • It is important that word-sized data are placed at word boundaries and doubleword-sized data are placed at doubleword boundaries. • if not, the microprocessor spends additionaltime accessing these data types Microprocessor (c) Prima Dewi Purnamasari 2011

  45. Microprocessor (c) Prima Dewi Purnamasari 2011

  46. EQU, ORG ASSUME • Equate directive (EQU) equates a numeric, ASCII, or label to another label. • equates make a program clearer and simplify debugging • EX: TEN EQU 10 …. MOV AL,TEN • TheORG (origin) statement changes the starting offset address of the data or codesegments. • At times, the origin of data or the code must be assigned to an absolute offset address with the ORG statement. • ASSUME tells the assemblerwhat names have been chosen for the code, data, extra, and stack segments. • Used only with full-segment definition Microprocessor (c) Prima Dewi Purnamasari 2011

  47. Microprocessor (c) Prima Dewi Purnamasari 2011

  48. PROC and ENDP Indicate start and end of a procedure (subroutine). they force structure because the procedure is clearly defined Both the PROC and ENDP directives require a label to indicate the name of the procedure. RET instruction executed the end of the proc. USES directive indicates which registers are used by the proc. The assembler automatically save and restore them using the stack instructions. EX: PRC1 PROC USES AX BX CX Use .LISTALL directive to view all instruction generated by assembler Microprocessor (c) Prima Dewi Purnamasari 2011

  49. Microprocessor (c) Prima Dewi Purnamasari 2011

  50. Microprocessor (c) Prima Dewi Purnamasari 2011

More Related