Presentation is loading. Please wait.

Presentation is loading. Please wait.

Microprocessors Monday, Apr. 16 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.

Similar presentations


Presentation on theme: "Microprocessors Monday, Apr. 16 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University."— Presentation transcript:

1 Microprocessors Monday, Apr. 16 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University

2 Topics of Today Reading: 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 A Procedure: 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. Procedures

5 A Procedure’s Disadvantage: 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. Procedures

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

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

8 A Procedure: A Procedure: – Example: Procedures

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

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

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

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

13 An Interrupt: 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. Introduction to Interrupts

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

15 Interrupt Vectors: 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 interrupt vectors. Each vector contains the address of an interrupt service procedure (CS:IP). Introduction to Interrupts

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

17 Interrupt Instructions: 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. Introduction to Interrupts

18 INTs: 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. Introduction to Interrupts

19 INTs: (Cont.) 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. Introduction to Interrupts

20 INTs: (Cont.) 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-byte special software interrupt used for breakpoints. Introduction to Interrupts

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

22 INTs: (Cont.) 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. Introduction to Interrupts

23 INTs: (Cont.) 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. Introduction to Interrupts

24 IRET/IRETD: 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. Introduction to Interrupts

25 INT 3: 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. Introduction to Interrupts

26 INTO: 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. Introduction to Interrupts

27 An Interrupt Service Procedure: 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. Introduction to Interrupts 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 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. BIOS and DOS Programming in Assembly and C

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

31 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. DOS Interrupt 21H

32 INT 21H Option 09: Outputting a String of Data to the Monitor: 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: DOS Interrupt 21H

33 INT 21H Option 02: Outputting a Single Character to the Monitor: 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: DOS Interrupt 21H

34 INT 21H Option 01: Inputting a Single Character with Echo: 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. DOS Interrupt 21H

35 INT 21H Option 0AH: Inputting a String of Data from the Keyboard: 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. DOS Interrupt 21H

36 INT 21H Option 0AH: Inputting a String of Data from the Keyboard: 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. DOS Interrupt 21H

37 INT 21H Option 0AH: Inputting a String of Data from the Keyboard: 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. DOS Interrupt 21H

38 INT 21H Option 0AH: Inputting a String of Data from the Keyboard: 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", the contents of memory locations will be: DOS Interrupt 21H 0011H = 03 The keyboard was activated three times (excluding the CR key) to input letters U, S, and A.

39 INT 21H Option 0AH: Inputting a String of Data from the Keyboard: 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: DOS Interrupt 21H

40 INT 21H Option 0AH: Inputting a String of Data from the Keyboard: 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. DOS Interrupt 21H 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 INT 21H Option 07: Keyboard Input without Echo: 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: DOS Interrupt 21H

42 INT 21H: Using LABEL Directive to Define a String Buffer: 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. DOS Interrupt 21H

43 INT 21H: Using LABEL Directive to Define a String Buffer: INT 21H: Using LABEL Directive to Define a String Buffer: – Example: The offset address assigned to JOE is the same offset address for TOM since the LABEL directive does not occupy any memory space. DOS Interrupt 21H

44 INT 21H: Using LABEL Directive to Define a String Buffer: 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: DOS Interrupt 21H

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

46 Monitor Screen in Text Mode: 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. BIOS INT 10H Programming Cursor Locations (row, column)

47 Clearing the Screen using INT 10H Function 06H: 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 = 06 calls the scroll function, to scroll upward. – CH & CL registers hold starting row & column. – DH & DL registers hold ending row & column. BIOS INT 10H Programming

48 Clearing the Screen using INT 10H Function 06H: 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. BIOS INT 10H Programming

49 INT 10H Function 02: Setting the Cursor to a Specific Location: 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. BIOS INT 10H Programming

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

51 INT 10H Function 03: Get Current Cursor Position: INT 10H Function 03: Get Current Cursor Position: – In text mode, determine where the cursor is located at any time by executing the following: After execution of the program, registers DH & DL will have current row & column positions. – CX provides information about the shape of the cursor. In text mode, page 00 is chosen for the currently viewed page. BIOS INT 10H Programming

52 Changing the Video Mode: Changing the Video Mode: – To change the video mode, use INT 10H with AH = 00 and AL = video mode. BIOS INT 10H Programming

53 Attribute Byte in the Monochrome Monitors: Attribute Byte in the Monochrome Monitors: – An attribute associated with each character on the screen provides information to the video circuitry. Character (foreground) & background color/intensity. BIOS INT 10H Programming Actual character displayed. For foreground only.

54 Attribute Byte in the Monochrome Monitors: Attribute Byte in the Monochrome Monitors: – Possible variations of attributes: BIOS INT 10H Programming

55 Attribute Byte in CGA Text Mode: Attribute Byte in CGA Text Mode: – CGA mode (Color Graphics Adapter) is the common denominator for all color monitors, as all color monitors & video circuitry are upwardly compatible, – CGA attribute byte bit definition is as shown: BIOS INT 10H Programming

56 Attribute Byte in CGA Text Mode: Attribute Byte in CGA Text Mode: – The background can take eight different colors by combining the prime colors red, green, and blue. – The foreground can be any of 16 different colors by combining red, green, blue and intensity. – The attribute byte is put in the BL register. BIOS INT 10H Programming

57 Attribute Byte in CGA Text Mode: Attribute Byte in CGA Text Mode: BIOS INT 10H Programming Some possible CGA colors and byte variations.

58 Attribute Byte in CGA Text Mode: Attribute Byte in CGA Text Mode: – Example: BIOS INT 10H Programming

59 Attribute Byte in CGA Text Mode: Attribute Byte in CGA Text Mode: – Example: BIOS INT 10H Programming

60 Attribute Byte in CGA Text Mode: Attribute Byte in CGA Text Mode: – Example: BIOS INT 10H Programming INT 10H / AH = 09H - Write a character with attribute at cursor position. Input: AL = character to display. BH = page number. BL = attribute. CX = number of times to write the character.

61 Attribute Byte in CGA Text Mode: Attribute Byte in CGA Text Mode: – Example: BIOS INT 10H Programming CX hold number of times. 800 = 80 x 25.

62 Graphics: Pixel Resolution and Color: Graphics: Pixel Resolution and Color: – In text mode, the screen is viewed as a matrix of rows and columns of characters. – In graphics mode, the screen is viewed as a matrix of horizontal & vertical pixels. Number of pixels depends on monitor resolution & video board. – Two things associated with every pixel on the screen must be stored in the video RAM: Location of the pixel. Attributes of the pixel (color and intensity). BIOS INT 10H Programming

63 Graphics: Pixel Resolution and Color: Graphics: Pixel Resolution and Color: – The higher the number of pixels and colors, the larger the amount of memory that is needed to store them. Memory requirements go up with resolution & number of colors. – CGA mode can have a maximum of 16K bytes of video memory due to its inherent design structure. BIOS INT 10H Programming

64 Graphics Modes: Graphics Modes: – Text mode of 80 × 25 characters. A total of 2K (80×25 = 2000) for characters, plus 2K for attributes, as each character has one attribute byte. Each screen (frame) takes 4K, which results in CGA supporting a total of four pages of data, where each page represents one full screen. In this mode, 16 colors are supported. To select this mode, use AL = 03 for mode selection in INT 10H option AH = 00. BIOS INT 10H Programming

65 Graphics Modes: Graphics Modes: – Graphics mode of 320 × 200 (medium resolution). 64,000 pixels (320 columns × 200 rows = 64,000). Dividing total video RAM of 128K bits (16K×8 bits = 128K) by 64,000 pixels gives 2-bits for the color of each pixel. 2 bits give four possibilities, thus 320 × 200 resolution CGA can support no more than 4 colors. To select this mode, use AL = 04 for mode selection in INT 10H option AH = 00. BIOS INT 10H Programming

66 Graphics Modes: Graphics Modes: – Graphics resolution of 640 × 200 (high resolution). 128,000 pixels (200 × 640 = 128,000). Dividing gives 1 bit (128,000/128,000 = 1) for color, which can be on (white) or off (black). 640 × 200 high-resolution CGA can support only black and white. To select this mode, use AL = 06 for mode selection in INT 10H option AH = 00. BIOS INT 10H Programming

67 Graphics Modes: Graphics Modes: – With a fixed amount of video RAM, the number of supported colors decreases as resolution increases. To create more colors in video boards there must be memory available to store the extra colors. BIOS INT 10H Programming

68 INT10H and Pixel Programming: INT10H and Pixel Programming: – To address a single pixel on the screen, use INT 10H with AH = 0CH. The X (column) and Y (row) coordinates of the pixel must be known, and vary, depending on monitor resolution. – CX = column point (X coordinate). – DX = row point (Y coordinate). – To turn the pixel on/off, AL=1 or AL=0 for white and black. The value of AL can be modified for various colors. – If the display mode supports more than one page, BH = page number. BIOS INT 10H Programming X Y

69 Drawing Lines in the Graphics Mode: Drawing Lines in the Graphics Mode: – To draw a horizontal line: Set CX, DX = starting point coordinates. Increment CX (column) and keep DX (row) constant until it reaches the end of the line. – To draw a vertical line: Set CX, DX = starting point coordinates. Increment DX (row) and keep CX (column) constant until it reaches the end of the line. – To draw any line: Linear equation Y = mX + b can be used for any line. BIOS INT 10H Programming

70 Drawing Lines in the Graphics Mode: Drawing Lines in the Graphics Mode: – Example: BIOS INT 10H Programming

71 Drawing Lines in the Graphics Mode: Drawing Lines in the Graphics Mode: – Example: BIOS INT 10H Programming

72 Drawing Lines in the Graphics Mode: Drawing Lines in the Graphics Mode: – Example: BIOS INT 10H Programming

73 Drawing Lines in the Graphics Mode: Drawing Lines in the Graphics Mode: – Example: BIOS INT 10H Programming

74 Questions?

75 The End

76 Write an assembly program that ask the user to input a sentence and a word. The program should search for the word and find it in the sentence and ask the user to: – Replace or, – Delete or, – Leave it. If the user chose to replace it, the user have to input another word. Finally print the new string on the screen. Projects (1)

77 Example: Enter a sentence: My name is Asmaa. I live in Assiut. Enter a word: Asmaa D (Delete), R (Replace), L (Leave): R Enter another word: Aly Final sentence: My name is Aly. I live in Assiut. Projects (1)

78 Write an assembly program that lets the user to enter the time in seconds (up to 65535), and outputs the time as hours, minutes, and seconds. Example: Enter seconds: 8130 Time: 2:15:30 Projects (2)

79 Write an assembly program to read today's date through keyboard and then display the corresponding day and month’s name. Example: Enter date (dd-mm-yyyy): 17-12-2005 Day: 17 Month: December Projects (3)


Download ppt "Microprocessors Monday, Apr. 16 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University."

Similar presentations


Ads by Google