79
Microprocesso rs Monday, Apr. 16 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University

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

Embed Size (px)

DESCRIPTION

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

Citation preview

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

MicroprocessorsMonday, Apr. 16

Dr. Asmaa FaroukFaculty of Engineering, Electrical Department,

Assiut University

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

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.

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

Topics of Today

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

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

• 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

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

• 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

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

• 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

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

Procedures

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

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

• A Procedure: A Procedure: – Example:

Procedures

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

• Near CALL:Near CALL:– The near CALL is a 3-byte long

instruction.– Effect of a near Effect of a near CALL CALL on the stack and on the instruction pointer (IP):

Procedures

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

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

Procedures

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

• Far CALL:Far CALL:– The far CALL is a 5-bytes long

instruction.– Effect of far CALLEffect of far CALL

Procedures

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

Topics of Today

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

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

• 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

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

• Interrupt Vectors:Interrupt Vectors:– The The TPATPA::

• DOS memory map.

Introduction to Interrupts

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

• 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

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

• Interrupt Vectors: (Cont.)Interrupt Vectors: (Cont.)

Introduction to Interrupts

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

• 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

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

• 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

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

• 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

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

• 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

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

• 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

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

• 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

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

• 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

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

• 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

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

• 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

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

• 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

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

• 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.

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

Topics of Today

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

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

• 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

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

Topics of Today

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

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

• 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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

DOS Interrupt 21H

0011H = 03 The keyboard was activated three times (excluding the CR key) to input letters U, S, and A.

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

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

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

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

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

• INT 21H Option 07: INT 21H Option 07: Keyboard Input without Keyboard Input without Echo: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

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

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

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

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

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

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

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

Topics of Today

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

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

• 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)

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

• 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

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

• 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

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

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

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

• INT 10H Function 02: INT 10H Function 02: Setting the Cursor to a Setting the Cursor to a Specific Location:Specific Location:– Example:

BIOS INT 10H Programming

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

• INT 10H Function 03: INT 10H Function 03: Get Current Cursor Get Current Cursor Position: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

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

• 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

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

• 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.For foreground only.

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

• Attribute Byte in the Monochrome Monitors:Attribute Byte in the Monochrome Monitors:– Possible variations of attributes:

BIOS INT 10H Programming

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

• 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

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

• 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

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

• Attribute Byte in CGA Text Mode:Attribute Byte in CGA Text Mode:

BIOS INT 10H Programming

Some possible CGAcolors and byte variations.

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

• Attribute Byte in CGA Text Mode:Attribute Byte in CGA Text Mode:– Example:

BIOS INT 10H Programming

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

• Attribute Byte in CGA Text Mode:Attribute Byte in CGA Text Mode:– Example:

BIOS INT 10H Programming

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

• 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.

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

• 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.

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

• 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

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

• 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

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

• 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

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

• 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

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

• 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

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

• 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

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

• 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

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

• 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

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

• Drawing Lines in the Graphics Mode: Drawing Lines in the Graphics Mode: – Example:

BIOS INT 10H Programming

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

• Drawing Lines in the Graphics Mode: Drawing Lines in the Graphics Mode: – Example:

BIOS INT 10H Programming

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

• Drawing Lines in the Graphics Mode: Drawing Lines in the Graphics Mode: – Example:

BIOS INT 10H Programming

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

• Drawing Lines in the Graphics Mode: Drawing Lines in the Graphics Mode: – Example:

BIOS INT 10H Programming

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

Questions?Questions?

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

The EndThe End

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

• 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)Projects (1)

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

• Example: Enter a sentence:My name is Asmaa. I live in Assiut.Enter a word:AsmaaD (Delete), R (Replace), L (Leave):REnter another word:AlyFinal sentence:My name is Aly. I live in Assiut.

Projects (1)Projects (1)

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

• 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: 8130Time:2:15:30

Projects (2)Projects (2)

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

• 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-2005Day:17Month:December

Projects (3)Projects (3)