0
Assembly Language Instruction Addressing and Execution Motaz K. Saad Spring 2007 Motaz K. Saad, Dept. of CS
Lesson plan <ul><li>Review some concepts in the first week </li></ul><ul><li>First assembly program with EMU8086 </li></ul...
Recalling main concepts Motaz K. Saad, Dept. of CS
Recalling main concepts Motaz K. Saad, Dept. of CS
Recalling main concepts <ul><li>Segment: special areas defined to contain CODE, DATA and STACK </li></ul><ul><li>Paragraph...
Recalling main concepts Stack Segment Data Segment Code Segment SS DS CS Segment  Registers Motaz K. Saad, Dept. of CS
<ul><li>.MODEL SMALL </li></ul><ul><li>.STACK </li></ul><ul><li>.DATA </li></ul><ul><li>MESSAGE DB &quot;HELLO EVERYBODY! ...
Types of programs <ul><li>*.COM and *.EXE files </li></ul><ul><ul><li>*.COM: consists of one segment containing code, data...
Loading *.exe program <ul><li>Access *.exe from disk </li></ul><ul><li>256-byte  Program Segment Prefix  (PSP) on a paragr...
PSP Motaz K. Saad, Dept. of CS
Assembly directive to define memory model to use in the program . MODEL SMALL, .STACK .DATA MESSAGE DB &quot;HELLO EVERYBO...
Memory Model <ul><li>There are several types of memory:  Memory  model   TINY ,  SMALL ,  COMPACT ,  MEDIUM ,  LARGE ,  HU...
Real and Protected mode Motaz K. Saad, Dept. of CS Real Mode  16-bit Protected Mode  32-bit Protected Mode  Segment base a...
Protected mode <ul><li>Is a type of memory utilization, available on Intel 80286 and later  </li></ul><ul><li>-Support: </...
Booting process <ul><li>What is booting? </li></ul><ul><li>The process of starting or restarting a computer </li></ul>Mota...
Booting process <ul><li>How does a personal computer boot up? </li></ul>processor BIOS hard disk CD-ROM drive (RAM) memory...
How does a personal computer boot up? <ul><li>Step 1: The power supply sends a signal to components in the system unit. </...
How does a personal computer boot up? <ul><li>Step 3: The BIOS performs the POST, which checks components such as the mous...
How does a personal computer boot up? <ul><li>Step 6: The boot program loads the kernel of the operating system into RAM f...
How does a personal computer boot up? <ul><li>The operating system executes programs in the StartUp folder </li></ul><ul><...
BIOS Boot process BIOS routine FFFF0H Interrupt  Vector Table BIOS Data  Areas Access  the bootstrap loader Check ports In...
BIOS Boot process <ul><li>Internally, processor enters the reset state, clear all memory location to zero, perform a parit...
Assembly directive to define stack to use in the program . model small . STACK .DATA MESSAGE DB &quot;HELLO EVERYBODY! I A...
STACK <ul><li>The word is from data structure </li></ul><ul><li>Last In, First Out (LIFO) mechanism </li></ul><ul><li>STAC...
STACK <ul><li>PUSH </li></ul><ul><ul><li>Decrease SP by 2 and store a value there </li></ul></ul><ul><li>POP </li></ul><ul...
Lesson plan <ul><li>Review loading an *.exe file </li></ul><ul><li>Concept of execution of instructions </li></ul><ul><li>...
Loading *.exe file Access *.exe from disk 256-byte  Program Segment Prefix  (PSP) on a paragraph boundary Store the progra...
Loading *.exe file <ul><li>The sequence of segments (code, data, and stack) is given </li></ul><ul><li>SS: contains the ad...
Practice 2B360H PSP Stack Segment Data Segment Code Segment Memory Motaz K. Saad, Dept. of CS
Practice 2B360H PSP Stack Segment Data Segment Code Segment Memory PSP  2B360H PSP size  100 H Offset  0H SS  2B460H (stor...
Practice 2B360H PSP Stack Segment Data Segment Code Segment Memory 2B46H SS PSP  2B360H PSP size  100H Offset  30H     70H...
Practice 2B360H PSP Stack Segment Data Segment Code Segment Memory 2B46H SS CS 2B50H 2B36H 2B36H DS ES SP 0030H Motaz K. S...
Instruction Execution and Addressing <ul><li>Executing an instruction include </li></ul><ul><ul><li>Fetch the next instruc...
Example 4AF0 CS 0013 IP   4AF13H   04B1 DS Motaz K. Saad, Dept. of CS CS segment address: 4AF00H IP offset:   0013H ______...
Example 4AF0 CS 0013 IP   4AF13H A01200 Memory 04B1 DS Decode instruction: AO: MOV [0012] to AL Motaz K. Saad, Dept. of CS
Example 4AF0 CS 0013 IP   04B03H A01200 Memory 04B1 DS 04B22H Motaz K. Saad, Dept. of CS DS segment address:04B10H IP offs...
Example 4AF0 CS 0013 IP   04B03H A01200 1B Memory 04B1 DS 04B22 Data address: 04B22H Motaz K. Saad, Dept. of CS | 1B AX AX...
Upcoming SlideShare
Loading in...5
×

Assembly Language Lecture 1

25,956

Published on

Assembly Language Lecture 1

Published in: Technology, Business
6 Comments
17 Likes
Statistics
Notes
No Downloads
Views
Total Views
25,956
On Slideshare
0
From Embeds
0
Number of Embeds
5
Actions
Shares
0
Downloads
1,482
Comments
6
Likes
17
Embeds 0
No embeds

No notes for slide
  • Transcript of "Assembly Language Lecture 1"

    1. 1. Assembly Language Instruction Addressing and Execution Motaz K. Saad Spring 2007 Motaz K. Saad, Dept. of CS
    2. 2. Lesson plan <ul><li>Review some concepts in the first week </li></ul><ul><li>First assembly program with EMU8086 </li></ul><ul><li>Related concepts with the first program: </li></ul><ul><ul><li>Loading program </li></ul></ul><ul><ul><li>Boot process </li></ul></ul><ul><ul><li>Handling the stack </li></ul></ul>Motaz K. Saad, Dept. of CS
    3. 3. Recalling main concepts Motaz K. Saad, Dept. of CS
    4. 4. Recalling main concepts Motaz K. Saad, Dept. of CS
    5. 5. Recalling main concepts <ul><li>Segment: special areas defined to contain CODE, DATA and STACK </li></ul><ul><li>Paragraph boundary: location evenly divisible by 16 or 10H </li></ul>Motaz K. Saad, Dept. of CS
    6. 6. Recalling main concepts Stack Segment Data Segment Code Segment SS DS CS Segment Registers Motaz K. Saad, Dept. of CS
    7. 7. <ul><li>.MODEL SMALL </li></ul><ul><li>.STACK </li></ul><ul><li>.DATA </li></ul><ul><li>MESSAGE DB &quot;HELLO EVERYBODY! I AM LEARNING ASSEMBLY LANGUAGE!&quot;,&quot;$&quot; </li></ul><ul><li>.CODE </li></ul><ul><li>MAIN PROC </li></ul><ul><li>MOV AX, @DATA </li></ul><ul><li>MOV DS,AX </li></ul><ul><li>MOV AH,09 </li></ul><ul><li>LEA DX,MESSAGE </li></ul><ul><li>INT 21H </li></ul><ul><li>MOV AX,4C00H </li></ul><ul><li>INT 21H </li></ul><ul><li>MAIN ENDP </li></ul><ul><li>END MAIN </li></ul>Motaz K. Saad, Dept. of CS
    8. 8. Types of programs <ul><li>*.COM and *.EXE files </li></ul><ul><ul><li>*.COM: consists of one segment containing code, data and stack </li></ul></ul><ul><ul><li>*.exe: separate code, data and stack segments </li></ul></ul><ul><ul><li>COM is small, (small utility program or can be a resident program). We will focus on EXE program in this course. </li></ul></ul>Motaz K. Saad, Dept. of CS
    9. 9. Loading *.exe program <ul><li>Access *.exe from disk </li></ul><ul><li>256-byte Program Segment Prefix (PSP) on a paragraph boundary </li></ul><ul><li>Store the program immediately following the PSP </li></ul><ul><li>Load address of PSP in the DS & ES </li></ul><ul><li>Load code segment in CS, set IP </li></ul><ul><li>Load address of the stack to SS, set SP </li></ul><ul><li>Transfer control to the program for execution </li></ul><ul><li>PSP : Created by the operating system and contains information about some interrupt vectors, addresses of system fields etc. </li></ul>Motaz K. Saad, Dept. of CS
    10. 10. PSP Motaz K. Saad, Dept. of CS
    11. 11. Assembly directive to define memory model to use in the program . MODEL SMALL, .STACK .DATA MESSAGE DB &quot;HELLO EVERYBODY! I AM LEARNING ASSEMBLY LANGUAGE!&quot;,&quot;$&quot; .CODE MAIN PROC MOV AX, @DATA MOV DS,AX MOV AH,09 LEA DX,MESSAGE INT 21H MOV AX,4C00H INT 21H MAIN ENDP END MAIN Motaz K. Saad, Dept. of CS
    12. 12. Memory Model <ul><li>There are several types of memory: Memory model TINY , SMALL , COMPACT , MEDIUM , LARGE , HUGE , or FLAT . </li></ul><ul><li>Determines size of code and data pointers. This field is required. </li></ul><ul><li>The model does, however, control segment defaults and determine whether data and code are near or far by default, as indicated in the following table. </li></ul><ul><li>The model does not control the type of instructions that we can use. </li></ul>Motaz K. Saad, Dept. of CS
    13. 13. Real and Protected mode Motaz K. Saad, Dept. of CS Real Mode 16-bit Protected Mode 32-bit Protected Mode Segment base address 20-bit 24-bit, from descriptor 32-bit, from descriptor Segment size (limit) 16-bit, 64K bytes (fixed) 16-bit, 1-64K bytes 20-bit, 1-1M bytes or 4K-4G bytes Segment protection no yes yes Segment register segment base address / 16 selector selector
    14. 14. Protected mode <ul><li>Is a type of memory utilization, available on Intel 80286 and later </li></ul><ul><li>-Support: </li></ul><ul><li>protection: each program is protected from interference from other programs. </li></ul><ul><li>extended memory : Enables a single program to access more than 640K of memory. </li></ul><ul><li>virtual memory : Expands the address space to over 1GB. </li></ul><ul><li>Multitasking: </li></ul>Motaz K. Saad, Dept. of CS
    15. 15. Booting process <ul><li>What is booting? </li></ul><ul><li>The process of starting or restarting a computer </li></ul>Motaz K. Saad, Dept. of CS cold boot Process of turning on a computer after it has been powered off completely warm boot Process of restarting a computer that is already powered on Also called a warm start
    16. 16. Booting process <ul><li>How does a personal computer boot up? </li></ul>processor BIOS hard disk CD-ROM drive (RAM) memory modules CMOS floppy disk drive Step 6 expansion cards Motaz K. Saad, Dept. of CS
    17. 17. How does a personal computer boot up? <ul><li>Step 1: The power supply sends a signal to components in the system unit. </li></ul><ul><li>Step 2: The processor looks for the BIOS (Basic Input/Output system) </li></ul>Motaz K. Saad, Dept. of CS
    18. 18. How does a personal computer boot up? <ul><li>Step 3: The BIOS performs the POST, which checks components such as the mouse, keyboard connectors, and expansion cards. (Power On Self Test) </li></ul><ul><li>Step 4: The results of the POST are compared with data in the CMOS chip. (battery power) </li></ul><ul><li>Step 5: The BIOS looks for the system files in drive A (floppy disk drive) and then drive C (hard disk). </li></ul>Motaz K. Saad, Dept. of CS
    19. 19. How does a personal computer boot up? <ul><li>Step 6: The boot program loads the kernel of the operating system into RAM from storage (hard disk). </li></ul><ul><ul><li>The operating system in memory takes control of the computer. </li></ul></ul><ul><li>Step 7: The operating system loads configuration information and displays the desktop on the screen. </li></ul>Motaz K. Saad, Dept. of CS
    20. 20. How does a personal computer boot up? <ul><li>The operating system executes programs in the StartUp folder </li></ul><ul><ul><li>Registry - Several files that contain the system configuration information </li></ul></ul><ul><ul><ul><li>Registry is constantly accessed during the computer's operation </li></ul></ul></ul><ul><ul><li>StartUp folder - Contains a list of programs that open automatically when you boot the computer </li></ul></ul>Motaz K. Saad, Dept. of CS
    21. 21. BIOS Boot process BIOS routine FFFF0H Interrupt Vector Table BIOS Data Areas Access the bootstrap loader Check ports Initialize devices Motaz K. Saad, Dept. of CS
    22. 22. BIOS Boot process <ul><li>Internally, processor enters the reset state, clear all memory location to zero, perform a parity check of a memory, set CS to FFFFH, IP to zero. The first address to execute is FFFF0H (entry point of BIOS in ROM) </li></ul><ul><li>Identify & Initialized devices. </li></ul><ul><li>Established the tables: IVT (Interrupt Vector Table) and BIOS data area (status of attached devices) </li></ul><ul><li>Determine if the disk containing the system file is available. </li></ul>Motaz K. Saad, Dept. of CS
    23. 23. Assembly directive to define stack to use in the program . model small . STACK .DATA MESSAGE DB &quot;HELLO EVERYBODY! I AM LEARNING ASSEMBLY LANGUAGE!&quot;,&quot;$&quot; .CODE MAIN PROC MOV AX, @DATA MOV DS,AX MOV AH,09 LEA DX,MESSAGE INT 21H MOV AX,4C00H INT 21H MAIN ENDP END MAIN Motaz K. Saad, Dept. of CS
    24. 24. STACK <ul><li>The word is from data structure </li></ul><ul><li>Last In, First Out (LIFO) mechanism </li></ul><ul><li>STACK in OS has three main functions: </li></ul><ul><ul><li>Contains return address </li></ul></ul><ul><ul><li>Data </li></ul></ul><ul><ul><li>Content of present registers </li></ul></ul>Motaz K. Saad, Dept. of CS
    25. 25. STACK <ul><li>PUSH </li></ul><ul><ul><li>Decrease SP by 2 and store a value there </li></ul></ul><ul><li>POP </li></ul><ul><ul><li>Return a value from stack and increase SP by 2 </li></ul></ul>Motaz K. Saad, Dept. of CS
    26. 26. Lesson plan <ul><li>Review loading an *.exe file </li></ul><ul><li>Concept of execution of instructions </li></ul><ul><li>Practice: </li></ul><ul><ul><li>Execution of instructions </li></ul></ul>Motaz K. Saad, Dept. of CS
    27. 27. Loading *.exe file Access *.exe from disk 256-byte Program Segment Prefix (PSP) on a paragraph boundary Store the program immediately following the PSP Load address of PSP in the DS & ES Load code segment in CS, set IP Load address of the stack to SS, set SP Transfer control to the program for execution Motaz K. Saad, Dept. of CS
    28. 28. Loading *.exe file <ul><li>The sequence of segments (code, data, and stack) is given </li></ul><ul><li>SS: contains the address of the beginning of the stack </li></ul><ul><li>CS: contains the address of the beginning of the code segment </li></ul><ul><li>DS: contains the address of the beginning of the data segment </li></ul><ul><li>SP: contains the size of stack </li></ul>Motaz K. Saad, Dept. of CS
    29. 29. Practice 2B360H PSP Stack Segment Data Segment Code Segment Memory Motaz K. Saad, Dept. of CS
    30. 30. Practice 2B360H PSP Stack Segment Data Segment Code Segment Memory PSP 2B360H PSP size 100 H Offset 0H SS 2B460H (stored as 2B46) 2B46H SS Motaz K. Saad, Dept. of CS
    31. 31. Practice 2B360H PSP Stack Segment Data Segment Code Segment Memory 2B46H SS PSP 2B360H PSP size 100H Offset 30H 70H CS 2B500H (stored as 2B50) CS 2B50H Motaz K. Saad, Dept. of CS
    32. 32. Practice 2B360H PSP Stack Segment Data Segment Code Segment Memory 2B46H SS CS 2B50H 2B36H 2B36H DS ES SP 0030H Motaz K. Saad, Dept. of CS
    33. 33. Instruction Execution and Addressing <ul><li>Executing an instruction include </li></ul><ul><ul><li>Fetch the next instruction, put to a queue (QUEUE: FIFO vs. STACK LIFO) </li></ul></ul><ul><ul><li>Decode the instruction </li></ul></ul><ul><ul><li>Execute the instruction </li></ul></ul>Motaz K. Saad, Dept. of CS
    34. 34. Example 4AF0 CS 0013 IP 4AF13H 04B1 DS Motaz K. Saad, Dept. of CS CS segment address: 4AF00H IP offset: 0013H ________________________ + Instruction address:
    35. 35. Example 4AF0 CS 0013 IP 4AF13H A01200 Memory 04B1 DS Decode instruction: AO: MOV [0012] to AL Motaz K. Saad, Dept. of CS
    36. 36. Example 4AF0 CS 0013 IP 04B03H A01200 Memory 04B1 DS 04B22H Motaz K. Saad, Dept. of CS DS segment address:04B10H IP offset: 0012H ________________________ + Data address:
    37. 37. Example 4AF0 CS 0013 IP 04B03H A01200 1B Memory 04B1 DS 04B22 Data address: 04B22H Motaz K. Saad, Dept. of CS | 1B AX AX AH AL
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×