O slideshow foi denunciado.
Seu SlideShare está sendo baixado. ×
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Anúncio
Carregando em…3
×

Confira estes a seguir

1 de 26 Anúncio

Mais Conteúdo rRelacionado

Diapositivos para si (15)

Semelhante a Chap 01[1] (20)

Anúncio

Chap 01[1]

  1. 1. Chapter 1: Context of Assembly Language Slides to Accompany Assembly Language for Intel-Based Computers, Third Edition Copyright 1999-2000, Prentice-Hall Incorporated Updated 08/00
  2. 2. Table 1. Software Hierarchy Levels. Level Description Application Program Software designed for a particular class of applications. High-Level Language (HLL) Programs are compiled into either assembly language or machine language. Each statement usually translates into multiple machine language instructions. Examples are C++, Pascal, Java, and Visual Basic. Operating System Contains procedures that can be called from programs written in either high-level language or assembly language. This system may also contain an application programming interface (API). Assembly Language (ASM) Uses instruction mnemonics that have a one-to-one correspondence with machine language. Machine Language (ML) Numeric instructions and operands that can be stored in memory and directly executed by the computer processor.
  3. 3. Essential Tools • An assembler is a program that converts source-code programs into a machine language (object file). • A linker joins together two or more object files and produces a single executable file. • A debugger loads an executable program, displays the source code, and lets the programmer step through the program one instruction at a time, and display and modify memory.
  4. 4. Figure 1. Machine Language Generation by ASM and HLL programs. ASM ML ML ML ML ML HLL
  5. 5. Table 2. Comparison of Assembly Language to HLLs. Type of Application High-Level Language Assembly Language Business application Formal structures make it software, written for easy to organize and single platform, medium maintain large sections of to large size. code. No formal structure. Programmer must impose an artificial structure. Hardware device driver. Language may not provide for direct hardware access. Awkward coding techniques must be used, resulting in possible maintenance problems. Hardware access is straightforward and simple. Easy to maintain when the programs are short and well documented. Business application written for multiple platforms (different operating systems). Usually very portable. The source code can be recompiled on each target operating system with minimal changes. Must be recoded separately for each platform, often using an assembler with a different syntax. Difficult to maintain. Embedded systems and computer games requiring direct hardware access. Produces too much executable code, and may not run efficiently. Ideal, because the executable code is small and runs quickly.
  6. 6. Figure 2. Assembly Language Subroutines Used as Hardware Interfaces. Application Program Interface Subroutine Operating System Device Driver Subroutine Hardware
  7. 7. Machine Language • Consists of binary numbers • The "native" language of the computer • 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
  8. 8. Page 7: Bits, Bytes, and Doublewords: byte byte 0 0 1 0 0 1 1 0 0 1 1 0 1 0 1 0 bit word Each 1 or 0 is called a bit.
  9. 9. Table 3. Storage Sizes and Ranges of Unsigned Integers. Storage Type Bits Range (low - high) Unsigned byte 8 0 to 255 Unsigned word 16 0 to 65,535 Unsigned doubleword 32 0 to 4,294,967,295 Unsigned quadword 64 0 to 18,446,744,073,709,551,615
  10. 10. Table 4. Digits in Various Number Systems. System Base Possible Digits Binary 2 0 1 Octal 8 0 1 2 3 4 5 6 7 Decimal 10 0 1 2 3 4 5 6 7 8 9 Hexadecimal 16 0 1 2 3 4 5 6 7 8 9 A B C D E F
  11. 11. Page 9. ASCII Digit String. Format Value ASCII binary "01000001" ASCII decimal "65" ASCII hexadecimal "41" ASCII octal "101"
  12. 12. Table 5. Binary Bit Position Values. 2n Decimal Value 2n Decimal Value 20 1 28 256 21 2 29 512 22 4 210 1024 23 8 211 2048 24 16 212 4096 25 32 213 8192 26 64 214 16384 27 128 215 32768
  13. 13. Figure 3. Converting Binary to Decimal. 8 + 1 9
  14. 14. Table 6. Binary, Decimal, and Hexadecimal Equivalents. Binary Decimal Hexadecimal Binary Decimal Hexadecimal 0000 0 0 1000 8 8 0001 1 1 1001 9 9 0010 2 2 1010 10 A 0011 3 3 1011 11 B 0100 4 4 1100 12 C 0101 5 5 1101 13 D 0110 6 6 1110 14 E 0111 7 7 1111 15 F
  15. 15. Table 7. Powers of 16, in Decimal. 16n Decimal Value 16n Decimal Value 160 1 164 65,536 161 16 165 1,048,576 162 256 166 16,777,216 163 4096 167 268,435,456
  16. 16. Figure 4. Converting 3BA4 Hexadecimal to Decimal. 3 * 4096 = 12,288 11 * 256 = 2,816 10 * 16 = 160 4 * 1 = + 4 Total: 15,268 3 B A 4
  17. 17. 1 1 1 1 0 1 1 0 0 0 0 0 1 0 1 0 = = sign bit – 10 + 10 1.2.4 Signed Numbers
  18. 18. Table 8. Signed Integer Storage and Ranges. Storage Type Bits Range (low - high) Signed byte 7 -128 to +127 Signed word 15 –32,768 to +32,767 Signed doubleword 31 –2,147,483,648 to 2,147,483,647 Signed quadword 63 –9,223,372,036,854,775,808 to +9,223,372,036,854,775,807
  19. 19. 1.2.5 Character Storage Page 14. ASCII Representation of 123: ' 1 ' ' 2 ' ' 3 ' 00110001 00110010 00110011 123 01111011 = = "1 2 3" 1 2 3
  20. 20. 1.3 Introducing Assembly Language • An instruction is a symbolic representation of a single machine instruction • Consists of: – label always optional – mnemonic always required – operand(s) required by some instructions – comment always optional • Examples: start: mov ax,20 ; initialize the AX register inc bx ; increment the BX register stc ; set the Carry flag
  21. 21. 1. 2. 3. 4. mov ax, 5 add ax, 10 add ax, 20 ax 05 ax ax mov [0120], ax ax 15 35 35 Memory 011C 35 0120 5. int 20 011E 0122 0124 0126 Figure 5. Sample Program Written in Debug.
  22. 22. Running DEBUG.EXE, Assembling a Program C:>debug -A 100 0AFE:0100 mov ax,5 0AFE:0103 add ax,10 0AFE:0106 add ax,20 0AFE:0109 mov [120],ax 0AFE:010C int 20 0AFE:010E assemble, starting at offset 100 Press ENTER to return to command mode
  23. 23. Tracing the Sample Program. -T AX=0005 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000 DS=0AFE ES=0AFE SS=0AFE CS=0AFE IP=0103 NV UP EI PL NZ NA PO NC 0AFE:0103 051000 ADD AX,0010 -T AX=0015 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000 DS=0AFE ES=0AFE SS=0AFE CS=0AFE IP=0106 NV UP EI PL NZ NA PO NC 0AFE:0106 052000 ADD AX,0020 -T AX=0035 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000 DS=0AFE ES=0AFE SS=0AFE CS=0AFE IP=0109 NV UP EI PL NZ NA PE NC 0AFE:0109 A32001 MOV [0120],AX
  24. 24. Tracing the Sample Program (2) MOV [0120],AX -D 120,121 0AFE:0120 35 00 AX=0035 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000 DS=0AFE ES=0AFE SS=0AFE CS=0AFE IP=010C NV UP EI PL NZ NA PE NC 0AFE:010C CD20 INT 20 -G Program terminated normally
  25. 25. Table 9. Commonly Used Debug Commands. Command Description A Starts assembling a program, placing each instruction in memory. Optionally, an integer argument can be supplied, which specifies the hexadecimal location where the first instruction is to be inserted. G Executes the remainder of the program. Q Quits Debug R Displays the CPU registers. T Traces (execute) one program instruction.
  26. 26. The End

×