ECE291 Computer Engineering II Lecture 13 - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

ECE291 Computer Engineering II Lecture 13

Description:

Example 1 (cont.) Fast and Compact ... e.g., anomalous event within a program, such as an attempt to divide by ... SYSTEM BIOS Functions. All PCs come with a ... – PowerPoint PPT presentation

Number of Views:22
Avg rating:3.0/5.0
Slides: 13
Provided by: ZbigniewK9
Category:

less

Transcript and Presenter's Notes

Title: ECE291 Computer Engineering II Lecture 13


1
ECE291Computer Engineering IILecture 13
  • Josh Potts
  • University of Illinois at Urbana- Champaign

2
Outline
  • Lookup tables
  • Jump tables
  • Interrupt vectors
  • Interrupt functions examples

3
Lookup Tables
  • Lookup tables are often used to convert from one
    data form to another
  • A lookup table is formed in the memory as a list
    of data that is referenced by a procedure to
    perform conversions
  • XLAT instruction can often be used to lookup data
    in a table
  • place the offset of the array in the BX and
  • the desired index value in AL
  • XLAT returns the byte element in AL
  • AL cannot contain an index value greater than 255
  • you can use XLAT with arrays containing more than
    256 elements, simply treat each 256-byte block of
    the array as a smaller sub-array, e.g., to
    retrieve the 260th element add 256 to BX and set
    AL 3 (I.e. the 260th element is at offset 259
    which equals 256 3)

4
Table-Lookup FunctionsExample 1
  • MBegin CMP DIR,UP
  • JE MoveUP
  • CMP DIR,RT
  • JE MoveRT
  • CMP DIR,DN
  • JE MoveDOWN
  • CMP DIR,LT
  • JE MoveDown
  • MoveUP SUB Pos,COLSIZE
  • JMP MDone
  • MoveRT ADD Pos,1
  • JMP MDone
  • MoveDN ADD Pos,COLSIZE
  • JMP MDone
  • MoveLT SUB Pos,1
  • JMP MDone
  • MDone Finished!
  • Consider movement in an array by one element
  • Let Array
  • Matrix of ROWSIZE x COLSIZE elements
  • Let Pos Position in array
  • Row COLSIZE Column
  • Let Dir
  • Direction (UP0, RIGHT1, DOWN2, LEFT3)
  • Slow and Tedious Original Code
  • Compares each possible direction value

5
Table-Lookup FunctionsExample 1 (cont.)
  • Fast and Compact Table-lookup Code
  • Eliminate conditional jumps by defining a table
    of movements indexed by the Direction.
  • Movement dw -COLSIZE Movement0
    Go UP
  • dw 1 Movement1
    Go RIGHT
  • dw COLSIZE Movement2
    Go DOWN
  • dw -1 Movement3
    Go LEFT
  • MBegin MOV BX, DIR Direction
    0..3
  • SHL BX, 1
    Index words, not bytes
  • MOV AX, MovementBX
  • ADD Pos, AX
    Position Movement
  • MDone Finished!

6
Table LookupExample 2
  • DAYS PROC FAR
  • PUSH DX
  • PUSH SI
  • MOV SI, OFFSET DTAB
  • XOR AH, AH clear AH
  • ADD AX, AX double AX
  • ADD SI, AX modify table address
  • MOV DX, CSSI get string address
  • MOV AX, CS change data segment
  • PUSH DS
  • MOV DS, AX
  • MOV AH, 09h
  • INT 21h
  • POP DS
  • POP SI
  • POP DX
  • RET
  • DTAB DW SUN, MON, TUE, WED, THU, FRI, SAT
  • SUN DB Sunday
  • MON DB Monday
  • TUE DB Tuesday
  • WED DB Wednesday
  • THU DB Thursday
  • FRI DB Friday
  • SAT DB Saturday
  • DAYS ENDP

Converts numbers 0 to 6 to days of the week The
number is passed in AL register
7
Jump Tables
  • Suppose table entries are pointers to functions
  • Suppose BX holds a command in the range of
    0..N-1.
  • Let cmd index a function
  • JFUNCTION PROC NEAR/FAR Input BX
    Command
  • SHL BX,1
    Words, not bytes
  • JMP JtableBX
    Jump to function
  • Jtable dw offset
    Funct0
  • dw offset
    Funct1
  • ..
  • dw offset
    FunctN-1
  • Funct0 do something ..
  • RET
  • Funct1 do something else ..
  • RET
  • FunctN-1 do something else ..
  • RET
  • JFUNCTION ENDP

8
Interrupt Vectors
  • Jump Tables are the basis for interrupt vectors
  • On 80x86, low 1024 bytes of memory hold vector
    table
  • There are 256 pointers in the table
  • Each entry is a far (4 byte segmentoffset)
    pointer
  • Memory address (hex) Interrupt
    function pointer
  • 003FC INT 255
  • 4 x INT x
  • 00008 INT 2
  • 00004 INT 1
  • 00000 INT 0

9
Interrupt Vectors
  • The term interrupt is used in three different
    contexts
  • Software interrupts (e.g., 21h)
  • provide a mechanism whereby the programmer can
    use the int instruction to access blocks of code
    that already exist and are resident in machine
    memory
  • Hardware interrupts
  • triggered by hardware events external to the
    microprocessor, rather than resulting from an
    int or any other instruction
  • e.g., a request for service by external devices
    such as disk drives
  • Exceptions
  • hardware origin within the microprocessor itself
  • e.g., anomalous event within a program, such as
    an attempt to divide by zero

10
Interrupt Functions Examples DOS Functions
  • To execute one of many DOS functions, you can
    specify a sub-function by loading a value into AH
    just before calling INT 21
  • INT 21h, Subfunction
  • AH3Dh Open File
  • AH3Fh Read File
  • AH3Eh Close File
  • AH13h Delete File (!)
  • AH2Ah Get system date
  • AH2Ch Get system time
  • AH2Ch Read DOS Version
  • AH47h Get Current Directory
  • AH48h Allocate Memory block
    (specified in paragraphs16 bytes)
  • AH49h Free Memory block
  • AH4Ch Terminate program
    (and free resources)

11
Interrupt Functions Examples BIOS Functions
  • SYSTEM BIOS Functions
  • All PCs come with a BIOS ROM (or EPROM).
  • The BIOS contains standard 80x86 opcodes to
    provide basic functions such as bootstraping and
    primitive I/O.
  • INT 19h Reboot system
  • INT 11h Get equipment configuration
  • INT 16h Keyboard I/O
  • VIDEO BIOS Functions
  • Video cards come with 80x86 commands burned in a
    ROM. Video BIOS is located at C0000-C7FFF and
    holds routines for handling basic functions.
  • To execute a function in video BIOS ROM, call INT
    10 with AXsub-function.
  • INT 10h, Subfunction
  • AH0,AL2h 80x25 Text
  • AH0,AL13h 320x200, 256-color graphic

12
Interrupt Functions ExamplesMOUSE Hardware
Functions
  • MOUSE Functions INT 33h
  • Routines to read position and status of mouse
  • AX0000h Reset
  • AX0001h Show Mouse
  • AX0003h Get Position Status
  • BX Buttons Pressed bit0left, bit2right
  • CX Column Position
  • DX Row Position
  • HARDWARE Functions
  • IRQ 0-7 FUNCTIONS INT 8-Fh
  • System timer (IRQ 0 INT 8h)
  • Keyboard (IRQ 1 INT 9h)
  • Bus/DMA (IRQ 2 INT Ah)
  • Serial Port (IRQ 3 INT Bh)
  • SoundBlaster (IRQ 5 INT Dh)
  • INT 8 IRQ
  • IRQ 8-15 FUNCTIONS INT 70h-77h
  • SCSI Request (IRQ 10d INT 72h)
  • INT 68h IRQ
Write a Comment
User Comments (0)
About PowerShow.com