1 / 59

Assembly Language (CSW 353)

Assembly Language (CSW 353). Introduction of Assembly Language. Content. Course Description Basic Concepts of Assembly Language Welcome to Assembly Language Virtual Machine Concept Data Representation Boolean Operations. Course Description. The general aims of course :

larrymiller
Download Presentation

Assembly Language (CSW 353)

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. Assembly Language (CSW 353) Introduction of Assembly Language

  2. Content • Course Description • Basic Concepts of Assembly Language • Welcome to Assembly Language • Virtual Machine Concept • Data Representation • Boolean Operations

  3. Course Description • The general aims of course : • The computer architecture • Low-level programming in assembly language • Intended Learning Outcomes of Course: • Describing main components of computer system and their functionality. • Understanding the register level. • Understanding the basic assembly programming. • Describing techniques for the performance and reliability of processors, memory, I/O devices. • Explaining the use of parallelism, caching, error-detection and correction. • Understanding of the aspects of computer arithmetic. • Explaining the need for resource management in a computer system. • Illustrating the multiprogramming and identifying synchronization.

  4. Reasons for using assembly Course Description • Understanding how CPUs and compilers work. • Developing compilers, debuggers and other development tools. • Hardware drivers and system code. • Embedded systems. • Developing libraries. • Accessing instructions that are not available through high-level languages. • Optimizing for speed or space.

  5. Course Description • Prerequisites: • Structured Programming Language • Textbook References: • Assembly Language for Intel-Based Computers. • Assembly language for x86 processors • The Art of Assembly Language • Resources: • http://web.sau.edu/LillisKevinM/csci240/masmdocs/ • http://kipirvine.com/asm/4th/asmsources/ • http://forum.codecall.net/topic/62064-assembly-language-resources/

  6. Course Description • Grading : • Final Exam 65 • Year work 10 • Oral 10 • Laboratory and Practice 15 • Sum 100 • Timing: • Lecture 3 • Practice 2 • Exam 3

  7. Content • Course Description • Basic Concepts of Assembly Language • Welcome to Assembly Language • Virtual Machine Concept • Data Representation • Boolean Operations

  8. Basic Concepts • Welcome to Assembly Language • Some Good Questions to Ask • Virtual Machine Concept • Data Representation • Boolean Operations

  9. Welcome to Assembly Language • Some Good Questions to Ask • What is Assembly Language? • Why Learn Assembly Language? • What is Machine Language? • How is Assembly related to Machine Language? • What is an Assembler? • How is Assembly related to High-Level Language? • Is Assembly Language portable?

  10. What is Assembly Language? • A low-levelprocessor-specific programming language design to match the processor’s machine instruction set. • Each assembly language instruction matches exactly one machine language instruction. • We will focus to Intel based Assembly Instructions. • It covers many different versions of CPUs that followed, from Intel; the 80188, 80186, 80286, 80386, 80486, Pentium, Pentium Pro, and so on. • It describes the basics of 32-bit assembly language programming.

  11. What is Assembly Language? • A Hierarchy of Languages

  12. Why Learn Assembly Language? • To learn how high-level language code gets translated into machine language. • To learn the computer’s hardware by direct access to memory, video controller, sound card, keyboard… • To speed up applications by direct access to hardware.

  13. What is Machine Language ML? • Machine languages are lowest-level programming language and are the only languages understood by computers without translation. • While easily understood by computers, machine languages are almost impossible for humans because they consist entirely of binary digits. • Every CPU has its own specific machine language.

  14. What is Machine Language ML? • Each ML instruction contains an op code (operation code) and zero or more operands. • Examples: Opcode Operand Meaning ------------------------------------------- 40 increment the AX register 05 0005 add 0005 to AX

  15. How is Assembly related to Machine Language? • Machine language • Native to a processor: executed directly by hardware • Instructions consist of binary code: 1s and 0s • Assembly language • Slightly higher-level language • Readability of instructions is better than machine language • One-to-one correspondence with machine language instructions • Assemblers translate assembly to machine code • Compilers translate high-level programs to machine code • Either directly, or • Indirectly via an assembler

  16. What is an Assembler? • An assembler is a type of computer program that interprets software programs written in assembly language into machine language, code and instructions that can be executed by a computer. • For Example, MASM (Macro Assembler from Microsoft)

  17. How is Assembly related to High-Level Language?

  18. Basic Concepts • Welcome to Assembly Language • Some Good Questions to Ask • Assembly Language Applications • Virtual Machine Concept • Data Representation • Boolean Operations

  19. Virtual Machine Concept • A virtual machine (VM) is a software program or operating system that • exhibits the behavior of a separate computer. • is capable of performing tasks such as running applications and programs in a separate computer. • VM virtual machine is a layer of abstraction that gives a program one simplified interface for interacting with a variety of physical computers and their operating systems.

  20. Translating languages English: Display the sum of A times B plus C. C++: cout << (A * B + C); Intel Machine Language: A1 00000000 F7 25 00000004 03 05 00000008 E8 00500000 Assembly Language: moveax,A mul B add eax,C call WriteInt

  21. Virtual machines Abstractions for computers

  22. High-level language • Level 5 • Application-oriented languages • Programs are compiled into assembly language (Level 4) cout << (A * B + C);

  23. Assembly language • Level 4 • Instruction mnemonics that have a one-to-one correspondence to machine language • Calls functions written at the operating system level (Level 3) • Programs are translated into machine language (Level 2) moveax, A mul B add eax, C call WriteInt

  24. Operating system • Level 3 • Provides services • Programs translated and run at the instruction set architecture level (Level 2)

  25. Instruction set architecture • Level 2 • Also known as conventional machine language • Executed by Level 1 program (microarchitecture, Level 1) A1 00000000 F7 25 00000004 03 05 00000008 E8 00500000

  26. Micro-architecture • Level 1 • Interprets conventional machine instructions (Level 2) • Executed by digital hardware (Level 0)

  27. Digital logic • Level 0 • CPU, constructed from digital logic gates • System bus • Memory

  28. Basic Concepts • Welcome to Assembly Language • Some Good Questions to Ask • Assembly Language Applications • Virtual Machine Concept • Data Representation • Boolean Operations

  29. Data representation • Computer is a construction of digital circuits with two states: on and off • You need to have the ability to translate between different representations to examine the content • Common number systems: binary, octal, decimal and hexadecimal

  30. 0 1 0 3.3V 2.8V 0.5V 0.0V Binary representations • Electronic Implementation • Easy to store with bi-stable elements • Reliably transmitted on noisy and inaccurate wires

  31. Binary numbers • Digits are 1 and 0 (a binary digit is called a bit) 1 = true 0 = false • MSB –most significant bit • LSB –least significant bit • Bit numbering: • A bit string could have different interpretations

  32. Unsigned binary integers • Each digit (bit) is either 1 or 0 • Each bit represents a power of 2: Every binary number is a sum of powers of 2

  33. Translating binary to decimal • Weighted positional notation shows how to calculate the decimal value (dec) of each binary bit: dec = (Dn-12n-1) + (Dn-2 2n-2) + ... + (D1 21) + (D0 20) D = binary digit binary 00001001 = decimal 9: (1 23) + (1 20) = 9

  34. Translating unsigned decimal to binary • Repeatedly divide the decimal integer by 2. Each remainder is a binary digit in the translated value: 37 = 100101

  35. Binary addition • Starting with the LSB, add each pair of digits, include the carry if present.

  36. Integer storage sizes Standard sizes: Practice: What is the largest unsigned integer that may be stored in 20 bits?

  37. Large measurements • Kilobyte (KB), bytes • Megabyte (MB), bytes • Gigabyte (GB), bytes • Terabyte (TB), bytes • Petabyte, bytes • Exabyte, bytes • Zettabyte, bytes • Yottabyte, bytes

  38. Hexadecimal integers • All values in memory are stored in binary. Because long binary numbers are hard to read, we use hexadecimal representation.

  39. Translating binary to hexadecimal • Each hexadecimal digit corresponds to 4 binary bits. • Example: Translate the binary integer 000101101010011110010100 to hexadecimal:

  40. Converting hexadecimal to decimal • Multiply each digit by its corresponding power of 16: dec = (D3 163) + (D2 162) + (D1 161) + (D0 160) Examples: • Hex 1234 equals (1  163) + (2  162) + (3  161) + (4  160), or decimal 4,660. • Hex 3BA4 equals (3  163) + (11 * 162) + (10  161) + (4  160), or decimal 15,268.

  41. Converting decimal to hexadecimal decimal 422 = 1A6 hexadecimal

  42. Hexadecimal addition • Divide the sum of two digits by the number base (16). The quotient becomes the carry value, and the remainder is the sum digit. 1 1 36 28 28 6A 42 45 58 4B 78 6D 80 B5 Important skill: Programmers frequently add and subtract the addresses of variables and instructions.

  43. Hexadecimal subtraction • When a borrow is required from the digit to the left, add 10h to the current digit's value: -1 C6 75 A2 47 24 2E Practice: The address of var1 is 00400020. The address of the next variable after var1 is 0040006A. How many bytes are used by var1?

  44. Signed integers • The highest bit indicates the sign. 1 = negative, 0 = positive If the highest digit of a hexadecimal integer is > 7, the value is negative. Examples: 8A, C5, A2, 9D

  45. Two's complement notation For Binary Steps: • Complement (reverse) each bit • Add 1 Note that 00000001 + 11111111 = 00000000

  46. Hexadecimal Two’s Complement Steps: • Complement (reverse) each digit (to reverse the bits of a hexadecimal digit is to subtract the digit from 15.) • Add 1

  47. Binary subtraction • When subtracting A – B, convert B to its two's complement • Add A to (–B) 0 1 0 1 0 0 1 0 1 0 – 0 1 0 1 1 1 0 1 0 1 1 1 1 1 1

  48. Ranges of signed integers • The highest bit is reserved for the sign. This limits the range:

  49. Basic Concepts • Welcome to Assembly Language • Some Good Questions to Ask • Assembly Language Applications • Virtual Machine Concept • Data Representation • Boolean Operations

More Related