1 / 79

Microprocessors

Monday, Apr. 16 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University. Microprocessors. Topics of Today. Reading: Brey : Section 6.3: Procedures. Section 6.4: Introduction to Interrupts. Mazidi : Section 4.0: BIOS and DOS Programming in Assembly and C.

Download Presentation

Microprocessors

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. Monday, Apr. 16 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University Microprocessors

  2. Topics of Today • Reading: • Brey: • Section 6.3: Procedures. • Section 6.4: Introduction to Interrupts. • Mazidi: • Section 4.0: BIOS and DOS Programming in Assembly and C. • Section 4.1: BIOS INT 10H Programming. • Section 4.2: DOS Interrupt 21H.

  3. Topics of Today • Procedures. • Introduction to Interrupts. • BIOS and DOS Programming in Assembly and C. • DOS Interrupt 21H. • BIOS INT 10H Programming.

  4. Procedures • A Procedure: • A group of instructions that usually performs one task. • Subroutine, method, or function is an important part of any system’s architecture. • A reusable section of the software stored in memory once, used as often as necessary. • Advantages: saves memory space and makes it easier to develop software.

  5. Procedures • A Procedure’s Disadvantage: • It takes a time the computer to link to, and return from it. • CALL links to the procedure; the RET (return) instruction returns from the procedure. • CALL pushes the address of the instruction following the CALL (return address) on the stack. • The return address is popped from the stack when RET is executed.

  6. Procedures • A Procedure: • Begins with the PROC directiveand ends with the ENDP directive. • Each directive appears with the procedure name. • PROC is followed by the type of procedure: NEAR or FAR.

  7. Procedures Note that, a procedure’s body lies after the end of the main program.

  8. Procedures • A Procedure: • Example:

  9. Procedures • Near CALL: • The near CALL is a 3-byte long instruction. • Effect of a near CALL on the stack and on the instruction pointer (IP):

  10. Procedures • Near CALL: • Effect of a near RET on the stack and on the instruction pointer (IP):

  11. Procedures • Far CALL: • The far CALL is a 5-bytes long instruction. • Effect of far CALL

  12. Topics of Today • Procedures. • Introduction to Interrupts. • BIOS and DOS Programming in Assembly and C. • DOS Interrupt 21H. • BIOS INT 10H Programming.

  13. Introduction to Interrupts • An Interrupt: • Is a hardware-generated CALL. • Externally derived from a hardware signal. • Or a software-generated CALL. • Internally derived from the execution of an instruction or by some other internal event. • Some times, an internal interrupt is called an exception. • Both types, interrupt the program by calling an interrupt service procedure (ISP) or interrupt handler.

  14. Introduction to Interrupts • Interrupt Vectors: • The TPA: • DOS memory map.

  15. Introduction to Interrupts • Interrupt Vectors: • An interrupt vector is a 4-byte number stored in the first 1024 bytes of memory (00000H–003FFH) in real mode. • In protected mode, the vector table is replaced by an interrupt descriptor table that uses 8-byte descriptors to describe each of the interrupts. • 256 different interruptvectors. • Each vector contains the address of an interrupt service procedure (CS:IP).

  16. Introduction to Interrupts • Interrupt Vectors: (Cont.)

  17. Introduction to Interrupts • Interrupt Instructions: • Three different interrupt instructions available: • INT, INTO, and INT 3. • In real mode, each fetches a vector from the vector table, and then calls the procedure stored at the location addressed by the vector. • In protected mode, each fetches an interrupt descriptor from the interrupt descriptor table. • Similar to a far CALL instruction because it places the return address (IP/EIP and CS) on the stack.

  18. Introduction to Interrupts • INTs: • 256 different software interrupt instructions (INTs) available to the programmer. • Each INT instruction has a numeric operand whose range is 0 to 255 (00H–FFH). • Example: INT 100, uses interrupt vector 100, which appears at memory address 190H–193H.

  19. Introduction to Interrupts • INTs: (Cont.) • Address of the interrupt vector is determined by multiplying the interrupt type number by 4. • Example: INT 10H, calls the ISP whose address is stored beginning at memory location (10H x 4 = 40H) in real mode. • In protected mode, the interrupt descriptor address is located by multiplying the type number by 8, because each descriptor is 8 bytes long.

  20. Introduction to Interrupts • INTs: (Cont.) • Each INT instruction is 2-bytes long. • The first byte contains the opcode. • The second byte contains the vector type number. • Exception: • The INT 3 instruction a 1-bytespecial software interrupt used for breakpoints.

  21. Introduction to Interrupts • INTs: (Cont.) • When a software interrupt executes, it: • Pushes the flags onto the stack. • Clears the T and I flag bits. • Pushes CS onto the stack. • Fetches the new value for CS from the interrupt vector. • Pushes IP/EIP onto the stack. • Fetches the new value for IP/EIP from the interrupt vector. • Jumps to the new location addressed by CS and IP/EIP.

  22. Introduction to Interrupts • INTs: (Cont.) • INT performs as a far CALL. • Differences: • Not only pushes CS & IP onto the stack, also pushes the flags onto the stack. • The INT instruction performs the operation of a PUSHF, followed by a far CALL instruction. • INT instruction is 2-bytes long, whereas the far CALL is 5-bytes long. • Each time that the INT instruction replaces a far CALL, it saves 3-bytes of memory.

  23. Introduction to Interrupts • INTs: (Cont.) • Software interrupts are most commonly used to call system procedures because the address of the function need not be known. • The interrupts often control printers, video displays, and disk drives.

  24. Introduction to Interrupts • IRET/IRETD: • Used only with software or hardware ISPs (different than RET in normal programmer’s procedures). • IRET instruction will: • Pops stack data back into the IP. • Pops stack data back into CS. • Pops stack data back into the flag register. • Accomplishes the same tasks as the POPF followed by a far RET instruction. • Restores the contents of I and T from the stack, preserves the state of these flag bits. • If interrupts were enabled before an ISP, they are automatically re-enabled by the IRET instruction.

  25. Introduction to Interrupts • INT 3: • A special software interrupt designed to function as a breakpoint. • A 1-byte instruction, while others are 2-byte. • Common to insert an INT 3 in software to interrupt or break the flow of the software. • Function is called “a breakpoint”. • Breakpoints help to debug faulty software. • A breakpoint occurs for any software interrupt, but because INT 3 is 1 byte long, it is easier to use for this function.

  26. Introduction to Interrupts • INTO: • A conditional software interrupt (Interrupt on overflow that tests overflow flag (O)). • If O = 0, INTO performs no operation. • If O = 1 and an INTO executes, an interrupt occurs via vector type number 4. • The INTO instruction appears in software that adds or subtracts signed binary numbers. • In these operations, it is possible to have an overflow • Either JO or INTO instructions detect the overflow.

  27. Introduction to Interrupts • An Interrupt Service Procedure: • Interrupts are usually reserved for system events. • Suppose a procedure is required to add the contents of DI, SI, BP, and BX and save the sum in AX. • As a common task, it may be worthwhile to develop the task as a software interrupt. USES directive, an optional keyword used with PROC. Tells the CPU to push the value of registers that should be preserved (and that will be altered by your procedure) on the stack and pop them off when the procedure returns.

  28. Topics of Today • Procedures. • Introduction to Interrupts. • BIOS and DOS Programming in Assembly and C. • DOS Interrupt 21H. • BIOS INT 10H Programming.

  29. BIOS and DOS Programming in Assembly and C • The INT instruction is somewhat like a FAR CALL. • Saves CS:IP and the flags on the stack and goes to the subroutine associated with that interrupt. • In x86 processors, 256 interrupts, numbered 00H to FFH. • INT 10H and INT 21H are the most widely used with various functions selected by the value in the AH register.

  30. Topics of Today • Procedures. • Introduction to Interrupts. • BIOS and DOS Programming in Assembly and C. • DOS Interrupt 21H. • BIOS INT 10H Programming.

  31. DOS Interrupt 21H • So far, a fixed set of data was defined in the data segment & results viewed in a memory dump. • This section uses information inputted from the keyboard, and displayed on the screen. • A much more dynamic way of processing information. • When the OS is loaded, INT 21H can be invoked to perform some extremely useful functions. • Commonly referred to as DOS INT 21H function calls.

  32. DOS Interrupt 21H • INT 21H Option 09: Outputting a String of Data to the Monitor: • INT 21H can send a set of ASCII data to the monitor. • Set AH = 09 and DX = offset address of the ASCII data. • Displays ASCII data string pointed at by DX until it encounters the dollar sign "$". • Example: display the message "The earth is but one country“ on screen:

  33. DOS Interrupt 21H • INT 21H Option 02: Outputting a Single Character to the Monitor: • To output only a single character, 02 is put in AH, and DL is loaded with the character to be displayed. • Example: display the letter "J“ on screen:

  34. DOS Interrupt 21H • INT 21H Option 01: Inputting a Single Character with Echo: • This functions waits until a character is inputted from the keyboard, then echoes (display) it to the monitor. • Example: • After the interrupt, the input character will be in AL.

  35. DOS Interrupt 21H • INT 21H Option 0AH: Inputting a String of Data from the Keyboard: • A means by which one can get data from keyboard & store it in a predefined data segment memory area. • Set register AH = 0AH. • DX = offset address at which the string of data is stored. This memory area is commonly referred to as a buffer area.

  36. DOS Interrupt 21H • INT 21H Option 0AH: Inputting a String of Data from the Keyboard: • DOS requires the buffer area be defined in the data segment as follows: • The first byte specifies the size of the buffer (size of the string + CR (Enter key)). • The second byte specifies the number of characters will (actally) be inputted from the keyboard. • Keyed-in data placed in the buffer starts at the third byte.

  37. DOS Interrupt 21H • INT 21H Option 0AH: Inputting a String of Data from the Keyboard: • Example: this program accepts up to six characters from the keyboard, including the CR key. • Six buffer locations were reserved, and filled with FFH. • Memory contents of offset 0010H: • The PC won’t exit INT 21H until it encounters a RETURN.

  38. DOS Interrupt 21H • INT 21H Option 0AH: Inputting a String of Data from the Keyboard: • Example: this program accepts up to six characters from the keyboard, including the CR key. • The PC won’t exit INT 21H until it encounters a CR. • Assuming the data entered was "USA" <RETURN>, the contents of memory locations will be: 0011H = 03 The keyboard was activated three times (excluding the CR key) to input letters U, S, and A.

  39. DOS Interrupt 21H • INT 21H Option 0AH: Inputting a String of Data from the Keyboard: • Inputting more than the buffer size: • Causes the computer to sound the speaker. • In previous example, entering more than six characters (five + the CR = 6), e. g., “USA a country in hjjjkkkk”, the contents of the buffer will look like this:

  40. DOS Interrupt 21H • INT 21H Option 0AH: Inputting a String of Data from the Keyboard: • If only the CR key is activated & no other character: • Example: • 0AH is placed in memory 0020H. • 0021H is for the count = 00. • 0022H is the first location to have data that was entered. If only the CR is activated, 0022H has 0DH, the hex code for CR. The actual number of characters entered is 0 at location 0021.

  41. DOS Interrupt 21H • INT 21H Option 07: Keyboard Input without Echo: • This option requires the user to enter a single character, which is not displayed (or echoed) on the screen. • The PC waits until a single character is entered and provides the character in AL. • Example:

  42. DOS Interrupt 21H • INT 21H: Using LABEL Directive to Define a String Buffer: • The LABEL directive can be used in the data segment to assign multiple names to data. • The attribute can be: • BYTE; WORD; DWORD; FWORD; QWORD; TBYTE.

  43. DOS Interrupt 21H • INT 21H: Using LABEL Directive to Define a String Buffer: • Example: • The offset address assigned to JOEis the same offset address for TOMsince the LABEL directive does not occupy any memory space.

  44. DOS Interrupt 21H • INT 21H: Using LABEL Directive to Define a String Buffer: • Using this directive to define a buffer area for the string keyboard input: • In the code segment the data can be accessed by name as follows:

  45. Topics of Today • Procedures. • Introduction to Interrupts. • BIOS and DOS Programming in Assembly and C. • DOS Interrupt 21H. • BIOS INT 10H Programming.

  46. BIOS INT 10H Programming • Monitor Screen in Text Mode: • The monitor screen in the x86 PC is divided into 80 columns and 25 rows in normal text mode. • Columns are numbered from 0 to 79. • Rows are numbered 0 to 24. Cursor Locations (row, column)

  47. BIOS INT 10H Programming • Clearing the Screen using INT 10H Function 06H: • To clear the screen, use INT 10H and set the registers as follows: • AH = 06, AL = 00, BH = 07, CX = 0000, DH = 24, DL = 79. • Option AH = 06calls the scroll function, to scroll upward. • CH & CL registers hold starting row & column. • DH & DL registers hold ending row & column.

  48. BIOS INT 10H Programming • Clearing the Screen using INT 10H Function 06H: • To clear the screen, use INT 10H and set the registers as follows: • AH = 06, AL = 00, BH = 07, CX = 0000, DH = 24, DL = 79.

  49. BIOS INT 10H Programming • INT 10H Function 02: Setting the Cursor to a Specific Location: • INT 10H function AH = 02 will change the position of the cursor to any location. • Desired position is identified by row/column values in DX. • Where DH = row and DL = column. • Video RAM can have multiple pages of text. • When AH = 02, page zero is chosen by making BH = 00.

  50. BIOS INT 10H Programming • INT 10H Function 02: Setting the Cursor to a Specific Location: • Example:

More Related