Assembly Language for x86 Processors 6th Edition

Slides:



Advertisements
Similar presentations
DOS and BIOS Interrupts DOS and BIOS interrupts are used to perform some very useful functions, such as displaying data to the monitor, reading data from.
Advertisements

Assembly Language for Intel-Based Computers, 4 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify and.
Assembly Language for x86 Processors 6th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy this slide.
Mouse handling Suthida Chaichomchuen
More about procedures and Video Processing. Lesson plan Review existing concepts More about procedures and boolean expression Video processing.
Video systems (continue). Practice Modify the program to get a string from a keyboard to display the input string on the middle of the screen with reverse.
Lab6 – Debug Assembly Language Lab
Important Irvine Library Procedures Randomize Randomize –Initializes the seed of the random-number formula by both the Random32 and the RandomRange procedures.
Assembly Language for Intel-Based Computers Chapter 15: BIOS-Level Programming (c) Pearson Education, All rights reserved. You may modify and.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You may modify.
Assembly Language for Intel-Based Computers Chapter 5: Procedures Kip R. Irvine.
CS2422 Assembly Language & System Programming November 2, 2006.
Chapter 7 Programming with DOS and BIOS Function Calls Objectives: The use of DOS and BIOS function call How to read the PC’s keyboard How to send text.
8.7 Memory management Program E Program D System memory DOS INT 21, function 48H: Allocate Memory Specification: allocates a number of memory paragraphs.
Kip Irvine: Assembly Language for Intel-Based Computers Overview Stack Operations (PUSH and POP) Procedures Procedure Parameters Software Interrupts MS-DOS.
Kip Irvine: Assembly Language for Intel-Based Computers
Assembly Language for Intel-Based Computers Chapter 16: Expert MS-DOS Programming (c) Pearson Education, All rights reserved. You may modify.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
Overview Chapter 13: 16-bit MS-DOS Programming MS-DOS and the IBM-PC
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify.
8.4 Instruction Execution Times TOBIN PROC FAR SUB AX,AX MOV DX,AX MOV CX,4 NEXTD: PUSH CX SUB BP,BP MOV CX,4 GETNUM: RCL BX,1 RCL BP,1 LOOP GETNUM.
Practical Session No. 10 Input &Output (I/O). I/O Devices Input/output (I/O) devices provide the means to interact with the “outside world”. An I/O device.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 1: Basic Concepts (c) Pearson Education, All rights reserved. You may modify.
Assembly Language for Intel-Based Computers, 5 th Edition Chapter 15: BIOS-Level Programming (c) Pearson Education, All rights reserved. You.
Chapter 15 BIOS-Level Programming
ICS312 Set 4 Program Structure. Outline for a SMALL Model Program Note the quiz at the next lecture will be to reproduce this slide.MODEL SMALL.586 ;
ORG ; FOUR INT 21H and INT 10H Programming and Macros Dec Hex Bin
Assembly Language for x86 Processors 7th Edition
Lecture 11 Last notes on interrupts and exam review Dr. Dimitrios S. Nikolopoulos CSL/UIUC.
BIOS1 Basic Input Output System BIOS BIOS refers to a set of procedures or functions that enable the programmer have access to the hardware of the computer.
ECE291 Computer Engineering II Lecture 13 Dr. Zbigniew Kalbarczyk University of Illinois at Urbana- Champaign.
ECE291 Computer Engineering II Lecture 9 Josh Potts University of Illinois at Urbana- Champaign.
Chapter 1: Basic Concepts
The x86 PC Assembly Language, Design, and Interfacing By Muhammad Ali Mazidi, Janice Gillespie Mazidi and Danny Causey © 2010, 2003, 2000, 1998 Pearson.
BIOS and DOS Programming in DOS INT 10 and 21H. Interrupts There are some extremely useful subroutines within BIOS or DOS that are available to the user.
1 Screen and Keyboard Operations Suthida Chaichomchuen
Assembly Language for Intel-Based Computers, 6 th Edition Chapter 8: Advanced Procedures (c) Pearson Education, All rights reserved. You may.
1 Chapter 5: Procedures and Interrupts Assembly Language for Intel-Based Computers, Kip R. Irvine 3rd edition 3/17/2000.
Lab 8 Bit-Mapped Graphics Moving from text-based graphics to bit- mapped graphics. Easy to draw graphic points and lines using INT 10h, Function 0Ch (write.
Functions available for Writing to the Video Display Three different ways to write to the display –Irvine library functions –DOS Video Functions (Interrupt.
Text-Mode Programming Question #1 What are the three levels of access to the video display when writing characters on the screen in text mode?
Lecture 10: BIOS and DOS Programming
Practical Session 11 Computer Architecture and Assembly Language Input &Output (I/O)
Mouse Question #1 Which INT number is used for the mouse?
File I/O MS-DOS Interrupt 21h has many functions dealing with file and directory I/O services. Both MS-DOS and MS_Windows use 16- bit integers called HANDLES.
Assembly Language for Intel-Based Computers Chapter 7: Integer Arithmetic (c) Pearson Education, All rights reserved. You may modify and copy.
Video systems. Lesson plan Review the code for the previous exercise Video systems Review for midterm exam.
8086 Microprocessor Interrupts By: Vijay Kumar. K Reference From Slide Share.
21/11/2005CAP2411 Input & Output Instructions CPU communicates with the peripherals through I/O registers called I/O ports. There are 2 instructions, IN.
3 Types of Video Output for Text DOS-level INT (Int 21) Output can be easily redirected to other devices (printer, disk) Slow Speed Cannot control the.
10H Interrupt. Option 0H – Sets video mode. Registers used: – AH = 0H – AL = Video Mode. 3H - CGA Color text of 80X25 7H - Monochrome text of 80X25 Ex:
String Instructions String instructions were designed to operate on large data structures. The SI and DI registers are used as pointers to the data structures.
EEL 3801 Part IV The Assembler. OFFSET Operator Returns address of variable used as operand. Actually, it represents the offset from the beginning of.
Microprocessors Monday, Apr. 16 Dr. Asmaa Farouk Faculty of Engineering, Electrical Department, Assiut University.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures Lecture 19: Procedures Procedure’s parameters (c) Pearson Education, 2002.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 13: 16-Bit MS-DOS Programming Interrupts (c) Pearson Education, All rights reserved.
Lecture 11 Text mode video
Computer and Information Sciences College / Computer Science Department CS 206 D Computer Organization and Assembly Language.
File Operations. FILE PROCESSING For the purposes of the following discussion, reading means copying all or part of an existing file into memory Writing.
Chapter 5: Procedures and Interrupts
ECE291 Computer Engineering II Lecture 12 Josh Potts University of Illinois at Urbana- Champaign.
Practical Session 11 Computer Architecture and Assembly Language Input &Output (I/O)
1 Chapter 1: Introduction Appendix A: Binary and Hexadecimal Tutorial Assembly Language for Intel-Based Computers, 3rd edition Kip R. Irvine.
Computer Graphics Lecture 04 Point Taqdees A. Siddiqi
Assembly Language for x86 Processors 6th Edition
9/17/2018 Kiến Trúc Máy Tính.
Microprocessor and Assembly Language
Computer Architecture and Assembly Language
Unit:08 Software Interrupts
Presentation transcript:

Assembly Language for x86 Processors 6th Edition Kip R. Irvine Chapter 16: BIOS-Level Programming Slide show prepared by the author Revision date: 2/15/2010 (c) Pearson Education, 2010. All rights reserved. You may modify and copy this slide show for your personal use, or for use in the classroom, as long as this copyright statement, the author's name, and the title are not changed.

Chapter Overview Introduction Keyboard Input with INT 16h VIDEO Programming with INT 10h Drawing Graphics Using INT 10h Memory-Mapped Graphics Mouse Programming Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

Personalities Bill Gates: co-authored QBASIC interpreter Gary Kildall: creator of CP/M-86 operating system multitasking capabilities Peter Norton: Inside the IBM-PC first book to thoroughly explore IBM-PC software and hardware created the Norton Utilities software Michael Abrash: columnist, expert programmer worked on Quake and Doom computer games optimized graphics code in Windows NT book: The Zen of Code Optimization Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

PC-BIOS The BIOS (Basic Input-Output System) provides low-level hardware drivers for the operating system. accessible to 16-bit applications written in assembly language, of course source code published by IBM in early 1980's Advantages over MS-DOS: permits graphics and color programming faster I/O speeds read mouse, serial port, parallel port low-level disk access Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

BIOS Data Area Fixed-location data area at address 00400h Contents: this area is also used by MS-DOS this area is accessible under Windows 98 & Windows Me, but not under Windows NT, 2000, or XP. Contents: Serial and parallel port addresses Hardware list, memory size Keyboard status flags, keyboard buffer pointers, keyboard buffer data Video hardware configuration Timer data Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

What's Next Introduction Keyboard Input with INT 16h VIDEO Programming with INT 10h Drawing Graphics Using INT 10h Memory-Mapped Graphics Mouse Programming Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

Keyboard Input with INT 16h How the Keyboard Works INT 16h Functions Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

How the Keyboard Works Keystroke sends a scan code to the keyboard serial input port Interrupt triggered: INT 9h service routine executes Scan code and ASCII code inserted into keyboard typeahead buffer Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

Keyboard Flags 16-bits, located at 0040:0017h – 0018h. Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

INT 16h Functions Provide low-level access to the keyboard, more so than MS-DOS. Input-output cannot be redirected at the command prompt. Function number is always in the AH register Important functions: set typematic rate push key into buffer wait for key check keyboard buffer get keyboard flags Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

Function 10h: Wait for Key If a key is waiting in the buffer, the function returns it immediately. If no key is waiting, the program pauses (blocks), waiting for user input. .data scanCode BYTE ? ASCIICode BYTE ? .code mov ah,10h int 16h mov scanCode,ah mov ASCIICode,al Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

Function 12h: Get Keyboard Flags Retrieves a copy of the keyboard status flags from the BIOS data area. .data keyFlags WORD ? .code mov ah,12h int 16h mov keyFlags,ax Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

Clearing the Keyboard Buffer Function 11h clears the Zero flag if a key is waiting in the keyboard typeahead buffer. L1: mov ah,11h ; check keyboard buffer int 16h ; any key pressed? jz noKey ; no: exit now mov ah,10h ; yes: remove from buffer int 16h cmp ah,scanCode ; was it the exit key? je quit ; yes: exit now (ZF=1) jmp L1 ; no: check buffer again noKey: ; no key pressed or al,1 ; clear zero flag quit: Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

What's Next Introduction Keyboard Input with INT 16h VIDEO Programming with INT 10h Drawing Graphics Using INT 10h Memory-Mapped Graphics Mouse Programming Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

VIDEO Programming with INT 10h Basic Background Controlling the Color INT 10h Video Functions Library Procedure Examples Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

Video Modes Graphics video modes Text video modes draw pixel by pixel multiple colors Text video modes character output, using hardware or software-based font table mode 3 (color text) is the default default range of 80 columns by 25 rows. color attribute byte contains foreground and background colors Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

Three Levels of Video Access MS-DOS function calls slow, but they work on any MS-DOS machine I/O can be redirected BIOS function calls medium-fast, work on nearly all MS-DOS-based machines I/O cannot be redirected Direct memory-mapped video fast – works only on 100% IBM-compatible computers cannot be redirected does not work under Windows NT, 2000, or XP Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

Controlling the Color Mix primary colors: red, yellow, blue Examples: called subtractive mixing add the intensity bit for 4th channel Examples: red + green + blue = light gray (0111) intensity + green + blue = white (1111) green + blue = cyan (0011) red + blue = magenta (0101) Attribute byte: 4 MSB bits = background 4 LSB bits = foreground Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

Constructing Attribute Bytes Color constants defined in Irvine32.inc and Irvine16.inc: Examples: Light gray text on a blue background: (blue SHL 4) OR lightGray White text on a red background: (red SHL 4) OR white Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

INT 10h Video Functions AH register contains the function number 00h: Set video mode text modes listed in Table 15-5 graphics modes listed in Table 15-6 01h: Set cursor lines 02h: Set cursor position 03h: Get cursor position and size 06h: Scroll window up 07h: Scroll window down 08h: Read character and attribute Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

INT 10h Video Functions (cont) 09h: Write character and attribute 0Ah: Write character 10h (AL = 03h): Toggle blinking/intensity bit 0Fh: Get video mode 13h: Write string in teletype mode Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

Displaying a Color String Write one character and attribute: mov si,OFFSET string . . . mov ah,9 ; write character/attribute mov al,[si] ; character to display mov bh,0 ; video page 0 mov bl,color ; attribute or bl,10000000b ; set blink/intensity bit mov cx,1 ; display it one time int 10h Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

Gotoxy Procedure ;-------------------------------------------------- ; Sets the cursor position on video page 0. ; Receives: DH,DL = row, column ; Returns: nothing ;--------------------------------------------------- pusha mov ah,2 mov bh,0 int 10h popa ret Gotoxy ENDP Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

Clrscr Procedure Clrscr PROC pusha mov ax,0600h ; scroll window up mov cx,0 ; upper left corner (0,0) mov dx,184Fh ; lower right corner (24,79) mov bh,7 ; normal attribute int 10h ; call BIOS mov ah,2 ; locate cursor at 0,0 mov bh,0 ; video page 0 mov dx,0 ; row 0, column 0 int 10h popa ret Clrscr ENDP Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

What's Next Introduction Keyboard Input with INT 16h VIDEO Programming with INT 10h Drawing Graphics Using INT 10h Memory-Mapped Graphics Mouse Programming Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

Drawing Graphics Using INT 10h INT 10h Pixel-Related Functions DrawLine Program Cartesian Coordinates Program Converting Cartesian Coordinates to Screen Coordinates Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

INT 10h Pixel-Related Functions Slow performance Easy to program 0Ch: Write graphics pixel 0Dh: Read graphics pixel Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

DrawLine Program Draws a straight line, using INT 10h function calls Saves and restores current video mode Excerpt from the DrawLine program (DrawLine.asm): mov ah,0Ch ; write pixel mov al,color ; pixel color mov bh,0 ; video page 0 mov cx,currentX int 10h Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

Cartesian Coordinates Program Draws the X and Y axes of a Cartesian coordinate system Uses video mode 6A (800 x 600, 16 colors) Name: Pixel2.asm Important procedures: DrawHorizLine DrawVerticalLine Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

Converting Cartesian Coordinates to Screen Coordinates Screen coordinates place the origin (0,0) at the upper-left corner of the screen Graphing functions often need to display negative values move origin point to the middle of the screen For Cartesian coordinates X, Y and origin points sOrigX and sOrigY, screen X and screen Y are calculated as: sx = (sOrigX + X) sy = (sOrigY – Y) Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

What's Next Introduction Keyboard Input with INT 16h VIDEO Programming with INT 10h Drawing Graphics Using INT 10h Memory-Mapped Graphics Mouse Programming Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

Memory-Mapped Graphics Binary values are written to video RAM video adapter must use standard address Very fast performance no BIOS or DOS routines to get in the way Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

Mode 13h: 320 X 200, 256 Colors Mode 13h graphics (320 X 200, 256 colors) Fairly easy to program read and write video adapter via IN and OUT instructions pixel-mapping scheme (1 byte per pixel) Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

Mode 13h Details OUT Instruction Color Indexes 16-bit port address assigned to DX register output value in AL, AX, or EAX Example: mov dx,3c8h ; port address mov al,20h ; value to be sent out dx,al ; send to the port Color Indexes color integer value is an index into a table of colors called a palette Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

Color Indexes in Mode 13h Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

RGB Colors Additive mixing of light (red, green, blue). Intensities vary from 0 to 255. Examples: Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

What's Next Introduction Keyboard Input with INT 16h VIDEO Programming with INT 10h Drawing Graphics Using INT 10h Memory-Mapped Graphics Mouse Programming Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

Mouse Programming MS-DOS functions for reading the mouse Mickey – unit of measurement (200th of an inch) mickeys-to-pixels ratio (8 x 16) is variable INT 33h functions Mouse Tracking Program Example Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

Reset Mouse and Get Status INT 33h, AX = 0 Example: mov ax,0 int 33h cmp ax,0 je MouseNotAvailable mov numberOfButtons,bx Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

Show/Hide Mouse INT 33h, AX = 1 (show), AX = 2 (hide) Example: mov ax,1 ; show int 33h mov ax,2 ; hide Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

Get Mouse Position & Status INT 33h, AX = 4 Example: mov ax,4 mov cx,200 ; X-position mov dx,100 ; Y-position int 33h Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

Get Button Press Information INT 33h, AX = 5 Example: mov ax,5 mov bx,0 ; button ID int 33h test ax,1 ; left button down? jz skip ; no - skip mov X_coord,cx ; yes: save coordinates mov Y_coord,dx Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

Other Mouse Functions AX = 6: Get Button Release Information AX = 7: Set Horizontal Limits AX = 8: Set Vertical Limits Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

Mouse Tracking Program Tracks the movement of the text mouse cursor X and Y coordinates are continually updated in the lower-right corner of the screen When the user presses the left button, the mouse’s position is displayed in the lower left corner of the screen Source code (c:\Irvine\Examples\ch15\mouse.asm) Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

Set Mouse Position INT 33h, AX = 3 Example: mov ax,3 int 33h test bx,1 jne Left_Button_Down test bx,2 jne Right_Button_Down test bx,4 jne Center_Button_Down mov Xcoord,cx mov yCoord,dx Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

Summary Working at the BIOS level gives you a high level of control over hardware Use INT 16h for keyboard control Use INT 10h for video text Use memory-mapped I/O for graphics Use INT 33h for the mouse Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.

The End Irvine, Kip R. Assembly Language for x86 Processors 6/e, 2010.