Lecture 8 Working with tables Dr. Dimitrios S. Nikolopoulos CSL/UIUC.

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

There are two types of addressing schemes:
Assembly Programming Notes for Practical2 Munaf Sheikh
University of Tehran 1 Microprocessor System Design Interrupt Omid Fatemi
Procedures and Stacks. Outline Stack organization PUSH and POP instructions Defining and Calling procedures.
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.
Set 20 Interrupts. INTERRUPTS The Pentium has a mechanism whereby external devices can interrupt it. Devices such as the keyboard, the monitor, hard disks.
Assembly Language for Intel-Based Computers Chapter 15: BIOS-Level Programming (c) Pearson Education, All rights reserved. You may modify and.
1 Hardware and Software Architecture Chapter 2 n The Intel Processor Architecture n History of PC Memory Usage (Real Mode)
CS2422 Assembly Language & System Programming November 2, 2006.
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.
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.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 251 Introduction to Computer Organization.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#8) By Dr. Syed Noman.
An Introduction to 8086 Microprocessor.
Interrupts. What Are Interrupts? Interrupts alter a program’s flow of control  Behavior is similar to a procedure call »Some significant differences.
Lecture 11 Last notes on interrupts and exam review Dr. Dimitrios S. Nikolopoulos CSL/UIUC.
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.
1/2002JNM1 Positional Notation (Hex Digits). 1/2002JNM2 Problem The 8086 has a 20-bit address bus. Therefore, it can access 1,048,576 bytes of memory.
Programming the Microprocessor A Course in Microprocessor Electrical Engineering Dept. University of Indonesia.
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.
Types of Registers (8086 Microprocessor Based)
ECE291 Lecture 9 Interrupts I. ECE 291 Lecture 9Slide 2 of 28 Lecture Outline Printed lab manual?Printed lab manual? Interrupt I/OInterrupt I/O Interrupt.
Virtual Memory Review Goal: give illusion of a large memory Allow many processes to share single memory Strategy Break physical memory up into blocks (pages)
ECE291 Lecture 12 Mode 13h Graphics. ECE 291 Lecture 12Page 2 of 27 Lecture outline Color theory Video Hardware Mode 13h Graphics File Formats.
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
ECE291 Computer Engineering II Lecture 15 Josh Potts University of Illinois at Urbana- Champaign.
Lecture 7 A closer look at procedures Dr. Dimitrios S. Nikolopoulos CSL/UIUC.
Video systems. Lesson plan Review the code for the previous exercise Video systems Review for midterm exam.
ECE 353 Introduction to Microprocessor Systems Michael G. Morrow, P.E. Week 7.
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.
ECE291 Lecture 10 Interrupts II. ECE 291 Lecture 9Slide 2 of 22 Lecture outline Installing/Removing ISRsInstalling/Removing ISRs Interrupt SchedulingInterrupt.
Control Structure vs. Assembly Language NASM. If-then-else If conditional then then_actions jump to endif else else_actions endif.
ECE291 Computer Engineering II Lecture 13 Josh Potts University of Illinois at Urbana- Champaign.
BIOS and DOS Interrupts Basic Input /Outpu System Disk Operating System.
Calling Procedures C calling conventions. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
Preocedures A closer look at procedures. Outline Procedures Procedure call mechanism Passing parameters Local variable storage C-Style procedures Recursion.
Internal Programming Architecture or Model
Lecture 11 Text mode video
File Operations. FILE PROCESSING For the purposes of the following discussion, reading means copying all or part of an existing file into memory Writing.
COMPUTER SCIENCE & TECHNOLOGY DEGREE PROGRAMME FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UVA WELLASSA 1 Assembly Language Programming.
BITS Pilani Pilani Campus Pawan Sharma Lecture / ES C263 INSTR/CS/EEE F241 Microprocessor Programming and Interfacing.
7-Nov Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Oct lecture23-24-hll-interrupts 1 High Level Language vs. Assembly.
1 Computer Architecture & Assembly Language Spring 2001 Dr. Richard Spillman Lecture 10 –Assembly V.
Assembly language programming
Format of Assembly language
Microprocessor and Assembly Language
(The Stack and Procedures)
Microprocessor and Assembly Language
Defining Types of data expression Dn [name] expression Dn [name]
Symbolic Instruction and Addressing
BIC 10503: COMPUTER ARCHITECTURE
8086 Registers Module M14.2 Sections 9.2, 10.1.
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Symbolic Instruction and Addressing
(Array and Addressing Modes)
(The Stack and Procedures)
Symbolic Instruction and Addressing
(Array and Addressing Modes)
Morgan Kaufmann Publishers Computer Organization and Assembly Language
Unit:08 Software Interrupts
Chapter 6 –Symbolic Instruction and Addressing
Process.
(The Stack and Procedures)
(The Stack and Procedures)
(Array and Addressing Modes)
Presentation transcript:

Lecture 8 Working with tables Dr. Dimitrios S. Nikolopoulos CSL/UIUC

Outline Arrays Lookup tables Hash tables Jump tables Where this is leading…

Arrays Collection of sequentially addressable equally sized data in memory Only first element is labeled Index from there given size of each array element

Arrays - declaring ;declare and initialize a five element byte array MyByteArrayDB00h,0afh,12,83,83h ;declare a 50 element word array MyWordArray1RESW50 MyWordArray2RESB100 MyWordArray3RESD25 ;declare and initialize a 16 element char array MyCharArrayDB “ ECE291 Rocks!!! ”, 0

Arrays - accessing /* C array example */ int intWordArray[25]; for (int i = 0; i < 25; i++) { intWordArray[i] = i * i; /*Same as: *(intWordArray + 2*i) = i * i;*/ } /* This code segment declares a 25-element word array (50 bytes) and fills each element with the square of its index */

Arrays - accessing ;Assembly array example intWordArrayRESW25 mov cx, 25 begin_loop: mov bx, cx imul ax, cx, cx dec bx shl bx mov [intWordArray + bx], ax loop begin_loop

Arrays in 2-dimensions AB CDEF A1B1C1D1E1F A2B2C2D2E2F A3B 3C3D3E3F A4B4C4D4E4F This is a 12 col by 7 row 2-D byte array It has 12 * 7 = 84 = 54h elements Addresses increase as you traverse a row Each row begins NUMCOLS addresses after the previous row Address of element (row, col) = row*NUMCOLS + col NUMCOLSEQU12 NUMROWSEQU7 My2DArray RESB NUMCOLS * NUMROWS mov bx, 4 mul bx, NUMCOLS add bx, 6 mov al, [My2DArray + bx] ;[My2DArray + 36]  AL ;[My2DArray + 36]  AL

Lookup tables Lookup tables are special purpose arrays commonly used to convert 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

Lookup tables Consider movement in a 2- dimensional array by one element to an adjacent element (up, down, left, or right) 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 16 instructions Mbegin CMP[DIR], UP JEMoveUP CMP[DIR], RIGHT JEMoveRT CMP[DIR], DN JEMoveDOWN CMP[DIR], LEFT JEMoveDown MoveUP SUB[Pos], COLSIZE JMPMDone MoveRT ADD[Pos],1 JMPMDone MoveDN ADD[Pos],COLSIZE JMPMDone MoveLT SUB[Pos],1 JMPMDone MDone

Lookup tables Fast and Compact Table-lookup Code Eliminate conditional jumps by defining a table of movements indexed by the Direction 4 instructions + 4 word-sized variables 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!

Lookup tables DAYS PUSH DX PUSH SI MOV SI, DTAB;si points to table XOR AH, AH;clear AH ADD AX, AX;double AX ADD SI, AX;index to right day MOV DX, [SI];get string address MOV AH, 09h;display char magic INT 21h POP SI POP DX RET SUN DB ‘ Sunday$ ’ MON DB ‘ Monday$ ’ TUE DB ‘ Tuesday$ ’ WED DB ‘ Wednesday$ ’ THU DB ‘ Thursday$ ’ FRI DB ‘ Friday$ ’ SAT DB ‘ Saturday$ ’ ;Lookup table contains addresses of ;day of week strings. It converts ;0 to “ Sunday ”, 1 to “ Monday ”, etc. DTAB DWSUN, MON, TUE, WED, THU, FRI, SAT Converts numbers 0 to 6 to days of the week The number is passed in AL register

Hash functions Consider using a lookup table when the input can span a large range of values but is sparsely populated. Example: –Count incoming packets from each of 100 hosts scattered throughout the Internet using the 32-bit IP source address –A Table-Lookup would require 4 billion table entries, most of which would be empty This is what we call “A Bad Thing.”

Hash functions Hash functions re-map large sparsely populated data sets (like the set of all IP addresses) into smaller more manageable data sets. Large sparsely populated data set Hash Function Small tightly packed data set

Hash functions A Hash Function, H(x), can be used to re-map the four-byte (W.X.Y.Z) IP address to a smaller (8-bit) value. H(W.X.Y.Z)=W xor X xor Y xor Z H( ) = 0 H( ) = 17 H( ) = 190 H( ) = 14 Hash Table IndexIP address … … … …

Hash functions Collisions can occur when two inputs map to the same output –H( ) and H( ) for example Collision resolution—Linear Probing Use next-available location in the hash table Add an extra column in the table for identifiers or tags to distinguish different entries in the table tag = IP_addressTag index = h(IP_address); if (ht[index].tag == IP_addressTag) then else end if

Jump tables Suppose table entries are pointers to functions BX holds a command in the range of 0..N Let BX 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 Funct0;do something.. RET Funct1;do something else.. RET FunctN;do something else.. RET

Where this is leading… Interrupts! These are triggers that cause the CPU to perform various tasks on demand Three kinds: –Software interrupts –Hardware interrupts –Exceptions Regardless of source, they are handled the same –Each interrupt has a unique interrupt number from 0 to 255. These are called interrupt vectors. –For each interrupt vector, there is an entry in the interrupt vector table. –The interrupt vector table is simply a jump table containing segment:offset addresses of procedures to handle each interrupt –These procedures are called interrupt handlers or interrupt service routines

Where this is leading… The first 1024 bytes of memory (addresses – 003FF) always contain the interrupt vector table. Always. Each of the 256 vectors requires four bytes—two for segment, two for offset Memory address (hex) Interrupt function pointer 003FC 4 * x INT 255 INT x INT 2 INT 1 INT 0

Software interrupts The operating system has handlers for many interrupts. These routines provide various built-in functions: –Displaying text to the screen (formerly known as “magic”) –Opening files –Rebooting the system (black magic) –Changing video modes Accessed with the INT instruction

DOS function dispatcher INT 21h is the DOS function dispatcher. It gives you access to dozens of functions built into the operating system. 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 sub-functions –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)

System BIOS functions All PCs come with a BIOS ROM (or EPROM). The BIOS contains procedures that 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 procedures stored in a ROM Collectively known as the video BIOS Located at C0000-C7FFF and holds routines for handling basic video adapter functions To execute a function in video BIOS ROM, do an INT 10h with video sub-function number stored in AX INT 10h, Sub-function examples –AH=0, AL=2h: 80 column x 25 row text display mode –AH=0, AL=13h: 320x200 pixel, 256-color graphics display mode

Where is all this stuff? Interrupt vector table FF 640KB of RAM 9FFFF Video RAM Memory usable by your real mode programs A0000 BFFFF C0000 C7FFF Video BIOS functions D0000 System BIOS functions FFFFF ROM or EPROM on the video display adapter ROM or EPROM on system motherboard