1 / 20

ECE291 Computer Engineering II Lecture 13

ECE291 Computer Engineering II Lecture 13. Josh Potts University of Illinois at Urbana- Champaign. Outline. Material covered on Exam 1 Lookup tables Jump tables Interrupt vectors Interrupt function examples. Exam Outline. Exam Outline. Fundamentals Number Systems Base Conversion

luisa
Download Presentation

ECE291 Computer Engineering II Lecture 13

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. ECE291Computer Engineering IILecture 13 Josh Potts University of Illinois at Urbana- Champaign

  2. Outline • Material covered on Exam 1 • Lookup tables • Jump tables • Interrupt vectors • Interrupt function examples

  3. Exam Outline

  4. Exam Outline • Fundamentals • Number Systems • Base Conversion • 2’s Complement • Basic Processor Architecture • Registers • Memory • Busses • Addressing Modes • Segment Offset Notation • Mode Bytes • Instruction Format and Opcodes This is essentially Lectures 1 through 3

  5. Exam Outline • Arithmetic and Logic Operations • All the instructions we learned (i.e. ADD, SUB, IMUL, SHL) • Know how they work and what they do • Be able to do the calculations by hand that these instructions accomplish • Know how they affect the flags Lecture 4Lecture 6

  6. Exam Outline • Stack Operations • Understand how data is accessed in the stack using PUSH, POP and the Base Pointer (BP) register • Be able to analyze a segment of code that uses the stack and determine what effect the segment has on the stack and the registers • Understand how procedure calls use the stack • Understand how recursive functions work Lecture 7Lecture 8

  7. Exam Outline • Memory Addressing • Know how your programs are arranged and stored in the memory • Understand the physical arrangement of memory into banks • Understand addressing • Understand how variable declarations affect the contents of memory • Be able to interpret instructions thatuse a variety of addressing modes Lecture 2Lecture 3

  8. Exam Outline • Branching • Know the difference between jump commands for signed and unsigned comparisons • Be able to determine the result of a jump command given the contents of the flag register or the preceding instruction • Understand the difference between near and far jumps Lecture 5

  9. Exam Outline • Text Mode Video • Understand how the 80x25 text mode uses memory • Know where the various pages are located in memory • Understand how characters are stored in memory (e.g that they use two bytes, an attribute byte and an ASCII byte) • Given the coordinates of a character on a given page, be able to calculate the physical address that stores that character Lecture 9

  10. Exam Outline • Coding Problem • We’ll give you a function definition, inputs, outputs, algorithm and ask you to code it. • The algorithm could be anything, but it won’t be too complex. You should be able to do it with about 10 instructions, not including register pushes and pops to save state. • The main thing is that you understand: • how parameters get passed to functions • how results are returned • appropriate use of the stack • the overall procedure call mechanism

  11. 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 (260 -256 -1)

  12. Consider movement in an array by one element Array = Matrix of ROWSIZE x COLSIZE elements Pos = Position in array = Row * COLSIZE + Column Dir = Direction (UP=0, RIGHT=1, DOWN=2,LEFT=3) Slow and Tedious Original Code: Compares each possible direction value Mbegin CMP [DIR],UP JE MoveUP CMP [DIR],RIGHT JE MoveRT CMP [DIR],DN JE MoveDOWN CMP [DIR],LEFT 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! Table-Lookup FunctionsExample 1

  13. 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 ; Movement[0] == Go UP dw +1 ; Movement[1] == Go RIGHT dw +COLSIZE ; Movement[2] == Go DOWN dw -1 ; Movement[3] == Go LEFT Mbegin MOV BX, [DIR] ; Direction = {0..3} SHL BX, 1 ; Index words, not bytes MOV AX, [Movement + BX] ADD [Pos], AX ; Position += Movement MDone: Finished!

  14. DAYS PUSH DX PUSH SI MOV SI, DTAB XOR AH, AH ;clear AH ADD AX, AX ;double AX ADD SI, AX ;modify table address MOV DX, CS:[SI] ;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 $’ Table LookupExample 2 Converts numbers 0 to 6 to days of the week The number is passed in AL register

  15. 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 ; Input BX = Command SHL BX,1 ; Words, not bytes JMP Jtable[BX] ; Jump to function Jtable dw Funct0 dw Funct1 .. dw FunctN-1 Funct0 do something .. RET Funct1 do something else .. RET FunctN-1 do something else .. RET

  16. 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 segment:offset) pointer Memory address (hex) Interrupt function pointer 003FC INT 255 4 * x INT x 00008 INT 2 00004 INT 1 00000 INT 0

  17. 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., 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

  18. Interrupt Functions Examples DOS Functions • To execute one of the many DOS functions, you can specify a sub-function by loading a value into AH just before calling INT 21 • INT 21h, Subfunction: AH=3Dh: Open File AH=3Fh: Read File AH=3Eh: Close File AH=13h: Delete File (!) AH=2Ah: Get system date AH=2Ch: Get system time AH=2Ch: Read DOS Version AH=47h: Get Current Directory AH=48h: Allocate Memory block (specified in paragraphs==16 bytes) AH=49h: Free Memory block AH=4Ch: Terminate program (and free resources)

  19. 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 AX=sub-function. INT 10h, Subfunction: AH=0,AL=2h: 80x25 Text AH=0,AL=13h: 320x200, 256-color graphic Interrupt Functions Examples BIOS Functions

  20. MOUSE Functions : INT 33h Routines to read position and status of mouse AX=0000h: Reset AX=0001h: Show Mouse AX=0003h: Get Position & Status BX = Buttons Pressed: bit[0]=left, bit[1]=right 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 Interrupt Functions ExamplesMOUSE & Hardware Functions

More Related