46
Assembly Language Assembly Language Lecture 21-23 Lecture 21-23 Presented By Presented By Shery khan Shery khan 10:00 to 11:00 10:00 to 11:00 [email protected] [email protected] www.sherykhan.jimdo.com www.sherykhan.jimdo.com

Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 [email protected]

Embed Size (px)

Citation preview

Page 1: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

Assembly Language Assembly Language Lecture 21-23Lecture 21-23Presented By Presented By Shery khanShery khan

10:00 to 11:0010:00 to 11:[email protected]@gmail.comwww.sherykhan.jimdo.comwww.sherykhan.jimdo.com

Page 2: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

Agenda Agenda

►What are interrupts?What are interrupts?►What are types of Interrupts?What are types of Interrupts?►Working of Interrupts?Working of Interrupts?►Software & Hardware Interrupt?Software & Hardware Interrupt?►Hooking An Interrupts?Hooking An Interrupts?►Bios & dos Interrupts?Bios & dos Interrupts?►Hardware Interrupts?Hardware Interrupts?►Example…..Example…..

Page 3: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

What are interrupts?What are interrupts?

► INT are ASYNCHOROUS & UnpredictableINT are ASYNCHOROUS & Unpredictable► Current State of Processor or Working is Not Current State of Processor or Working is Not

Disturbed or Currently Executing InstructionDisturbed or Currently Executing Instruction► Asynchronous mean which point of Asynchronous mean which point of

instruction were instruction is Executed.instruction were instruction is Executed.► Un predictable : means at which time Un predictable : means at which time

interrupt will come interrupt will come ► IN Generally : the event that occur outside IN Generally : the event that occur outside

the processor and the processor must be the processor and the processor must be informed informed

Page 4: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

What are types of Interrupts?What are types of Interrupts?

►8088 processor divides it in two major 8088 processor divides it in two major classesclasses

►Software InterruptsSoftware Interrupts►Hardware InterruptsHardware Interrupts

Hardware INT: Generated by External world Hardware INT: Generated by External world

Software INT: Not Generated by External Software INT: Not Generated by External world they are just Extended Far Callworld they are just Extended Far Call

Extended Far Call: Push Extended Far Call: Push Segment+offset+FlagSegment+offset+Flag

Page 5: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

Continue:Continue:

► Why Flag is Saved ?Why Flag is Saved ?► Sunario is That let suppose I want to Compare Sunario is That let suppose I want to Compare

two instruction and Then Jump but in between two instruction and Then Jump but in between Interrupt comes here comparison is done but Interrupt comes here comparison is done but not performed Jump instead processor now not performed Jump instead processor now execute interrupt routine now there Flag execute interrupt routine now there Flag registers are changed now I return on actual registers are changed now I return on actual instruction instruction

► Here the Jump will be the Instruction but Jump Here the Jump will be the Instruction but Jump will not be legal because Flags are Changed in will not be legal because Flags are Changed in Interrupt routine . So to avoid this we save Interrupt routine . So to avoid this we save Flags.Flags.

Page 6: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

IVT IVT

►When ever Interrupt comes some operation When ever Interrupt comes some operation is done in arrival of Interruption is done in arrival of Interruption

► So the Relation between Interrupt and So the Relation between Interrupt and Operation is performed on the basis of Operation is performed on the basis of Interrupt vector tableInterrupt vector table

► Boiler Example like that When Temperature Boiler Example like that When Temperature Increases The Interrupt Signal is Invoked and Increases The Interrupt Signal is Invoked and Processor Will read this Interruption and do Processor Will read this Interruption and do some operation to reduce the Heat of Boiler . some operation to reduce the Heat of Boiler . So Arrival of Interrupt Processor take ActionSo Arrival of Interrupt Processor take Action

Page 7: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

ISR/HOOKISR/HOOK

►So every Interrupt we can made we So every Interrupt we can made we can build a routine in relation with can build a routine in relation with interrupt which we can called as interrupt which we can called as Interrupt Service Routine .or we say Interrupt Service Routine .or we say the Mechanism for Interrupt to served the Mechanism for Interrupt to served is called ISRis called ISR

►The Co-Relationship between Interrupt The Co-Relationship between Interrupt and Interrupt service routine is and Interrupt service routine is Generally called HOOKINGGenerally called HOOKING

Page 8: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

SyntaxSyntax

► INT nINT n►Here we use Int key word with num in byte Here we use Int key word with num in byte ► INT 0-255INT 0-255►Number tells us which Interrupt is used to Number tells us which Interrupt is used to

achieve the respective results achieve the respective results ► INT opcode is CD and the Num is Co-related INT opcode is CD and the Num is Co-related

to Interrupt to route the service routine(ISR)to Interrupt to route the service routine(ISR)► IT IS 2 BYTE IT IS 2 BYTE

Page 9: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

RESERVED INTERRUPTSRESERVED INTERRUPTS

►Generally we do not use these Generally we do not use these Reserved INTReserved INT

►Because these are related to processorBecause these are related to processor

Like INT 0 is divide by zero Int Like INT 0 is divide by zero Int

Such interrupts are programmed in Such interrupts are programmed in the hardware to generate the the hardware to generate the designated interrupts when specific designated interrupts when specific condition arisescondition arises

Page 10: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

Co-relation INT & NumCo-relation INT & Num

►We use a Table IVT We use a Table IVT ► IVT Location is Fixed to Physical Memory IVT Location is Fixed to Physical Memory

address zero address zero ►Each Entry of Table is four Byte long Each Entry of Table is four Byte long

contain the segment & offset of Interrupt contain the segment & offset of Interrupt routine for corresponding interrupt routine for corresponding interrupt Number Number

►First two byte Contain Offset First two byte Contain Offset ►Next Two Segment Next Two Segment

Page 11: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

ContinueContinue

►Mathematically offset of the Interrupt Mathematically offset of the Interrupt n will be n will be n*4n*4 while while segment will be segment will be n*4+2n*4+2

►One entry in this table is called VectorOne entry in this table is called Vector►So Here vector for INT 0So Here vector for INT 0► Is 0*4=4Is 0*4=4► Int 0Int 0►0,1,0,1,2,3 Colored Vectors are offset 2,3 Colored Vectors are offset ►2,3 is Segment 2,3 is Segment

Page 12: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

continuecontinue

► INT 1INT 11*4=41*4=4So 4,5,6,7So 4,5,6,7► INT 2INT 2► 2*4=82*4=8► So 8,9,10,11So 8,9,10,11► Int 3Int 3► 2*3=6 --------------?question 2*3=6 --------------?question ► respectivelyrespectively

Page 13: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

Working of INTWorking of INT

►First Push the Flag RegisterFirst Push the Flag Register►Secondly Push the CS Segment RegisterSecondly Push the CS Segment Register►Then IP is Pushed to Stack Then IP is Pushed to Stack ►Here two flags Automatically IF=0,TF=0Here two flags Automatically IF=0,TF=0►So the other Up coming Interrupts are So the other Up coming Interrupts are

Disable When One is In IVT Table so Disable When One is In IVT Table so First come First Served Basis Other are First come First Served Basis Other are Not allowed Disabled Not allowed Disabled

Page 14: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

continuecontinue

►After these step the ISR is Called and After these step the ISR is Called and Control goes to Interrupt service Control goes to Interrupt service RoutineRoutine

►For Returning from this Routine Use For Returning from this Routine Use iretiret

Page 15: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

Story Story

►When An interrupt arrived Processor take When An interrupt arrived Processor take Action and go to IVT table and Call the Action and go to IVT table and Call the Routine after Some Specific Operation it Routine after Some Specific Operation it Return and How it can Return we Use IRET Return and How it can Return we Use IRET

► iRet for this Purpose iRet for this Purpose ► Iret is Working Reverse first Iret is Working Reverse first ► POP the IP into IpPOP the IP into Ip► Pop the CS Pop the CS ► POP the Flag POP the Flag

Page 16: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

Why we not use Ret Far instead Why we not use Ret Far instead of Iret???of Iret???

►Ret Far not use it is used when we use Ret Far not use it is used when we use Call farCall far

►And Ret Far take 2 words IP,Cs leave And Ret Far take 2 words IP,Cs leave the Flag the Flag

►So we Can use IRETSo we Can use IRET

Page 17: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

Working Int NWorking Int N

►Push flagPush flag► IFIF►TFTF►Push csPush cs► IP [0:4*n]-------------------offsetIP [0:4*n]-------------------offset►Cs [0:4*n+2]------------ SegmentCs [0:4*n+2]------------ Segment► ISR ExecuteISR Execute

0

0

Page 18: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

Iret Iret

► Ip Ip ►SP sp+2SP sp+2►Cs [ss:sp]Cs [ss:sp]►Sp +2Sp +2►Flag [ss:sp]Flag [ss:sp]►Sp sp+2Sp sp+2►Control return to Next instruction Control return to Next instruction

which is pointed by IPwhich is pointed by IP

[ss:sp]

Page 19: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

Example Example

Page 20: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

Example Example

Page 21: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

Example Example

Page 22: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

ExampleExample

Page 23: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

ExampleExample

Page 24: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

Example Example

Page 25: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

ExampleExample

Page 26: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

ExampleExample

Page 27: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

Lecture 22Lecture 22

►For Example For Example ►BOOK with its Content in Start Like BOOK with its Content in Start Like ►Chapter 4 started from Page 240Chapter 4 started from Page 240►Here Page 240 is Vector and Chapter 2 Here Page 240 is Vector and Chapter 2

is Interrupt so the Processor go the is Interrupt so the Processor go the page 240 Not 220 so in IVT has 256 page 240 Not 220 so in IVT has 256 chapter and Interrupt mechanism look chapter and Interrupt mechanism look up appropriate chapter num to read the up appropriate chapter num to read the desire page and find the Interrupt desire page and find the Interrupt routineroutine

Page 28: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

VECTOR TABLEVECTOR TABLE

► In table Content are Fixed always In table Content are Fixed always placed at the start of book so same placed at the start of book so same case the Vector table position is fixed case the Vector table position is fixed zero for IVT and occupy exactly 1 kilo zero for IVT and occupy exactly 1 kilo byte of memory byte of memory

►256*4=1kb 256 is num of possible 256*4=1kb 256 is num of possible interrupts while size of one vector is 4 interrupts while size of one vector is 4 byte byte

Page 29: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

IVTIVT

Page 30: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

Software / Hardware INTSoftware / Hardware INT

► Software Interrupt Break the program flow Software Interrupt Break the program flow ► Un programmed interruption is Hardware IntUn programmed interruption is Hardware Int

Reserved Interrupts of 8088Reserved Interrupts of 8088

INT 0INT 0

INT 1INT 1

INT 2,INT 3,INT 4 INT 2,INT 3,INT 4

These Five Interrupts are automatically tied These Five Interrupts are automatically tied with processorwith processor

Page 31: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

INT 0INT 0

► Is Same as when we Divide by 0Is Same as when we Divide by 0►We know that when quotient did not fit We know that when quotient did not fit

in the destination register let say div in the destination register let say div Bl Bl

►Quotient in ALQuotient in AL►Reminder Ah Divide Overflow Reminder Ah Divide Overflow ►System automatically call INT 0 Invoke System automatically call INT 0 Invoke

when Divide Overflowwhen Divide Overflow

Page 32: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

INT 1 (TRAP FLAG)INT 1 (TRAP FLAG)

►Debugger Pressed F1 Debugger Pressed F1 ► Trap Flag INT 1 Invoked Trap Flag INT 1 Invoked ► F1 F1 ► Trap Flag INT 1 Invoked Trap Flag INT 1 Invoked ► Its set Trap flag and Disable other Interruption Its set Trap flag and Disable other Interruption

it is automatically generated after every it is automatically generated after every instruction .instruction .

► Used for single stepping Used for single stepping

it is working like that sir one Instruction is it is working like that sir one Instruction is executed now tell me what I can do executed now tell me what I can do

Page 33: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

INT 2 (NMI)INT 2 (NMI)

►Non Mask able Interrupt Real interrupt Comes Non Mask able Interrupt Real interrupt Comes Outside the processor Outside the processor

► Two Pins in the processor INT Pin & NMI PINTwo Pins in the processor INT Pin & NMI PIN► INT Pin Processor can be directed to lesson or INT Pin Processor can be directed to lesson or

not to listen not to listen ►NMI PIN tells about Fetal hardware Failure in NMI PIN tells about Fetal hardware Failure in

the System the System ► Int Pin Can be Masked or ignoredInt Pin Can be Masked or ignored►NMI pin Cannot be Masked NMI pin Cannot be Masked ► Like Castrophic (Natural Disaster ) Comes and Like Castrophic (Natural Disaster ) Comes and

Processor must Listen and do Some Processor must Listen and do Some OperationOperation

Page 34: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

INT 3 Debug InterruptINT 3 Debug Interrupt

►Single byte Opcode CCSingle byte Opcode CC►Replace any Instruction with Break Replace any Instruction with Break

PointPoint► It is Software InterruptIt is Software Interrupt►Detail is in Debugger TopicDetail is in Debugger Topic

Page 35: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

INT 4 (Arithmetic Overflow)INT 4 (Arithmetic Overflow)Change of Sign BitChange of Sign Bit

► It is Invoked when Unexpectedly sign Bit is Changed It is Invoked when Unexpectedly sign Bit is Changed as a result of mathematical or logical instruction as a result of mathematical or logical instruction

► Overflow Flag signals a real overflow only if the Overflow Flag signals a real overflow only if the number is treated as signed Numbernumber is treated as signed Number

► Not Automatically generated But as a Result of Not Automatically generated But as a Result of Special Instruction Special Instruction INTO INTO (Interrupt on Overflow) if (Interrupt on Overflow) if overflow flag is Set otherwise overflow flag is Set otherwise INTOINTO behave as NO behave as NO Operation (NOP)Operation (NOP)

► Review of OVERFLOW FLAG: Review of OVERFLOW FLAG: ► Overflow flag is set during signed Arithmetic e.g Overflow flag is set during signed Arithmetic e.g ► addition or subtraction When the when the sign of addition or subtraction When the when the sign of

destination changes Unexpectedly destination changes Unexpectedly

Page 36: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

DIVIDE OVER FLOWDIVIDE OVER FLOW

Page 37: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

Lecture 23Lecture 23

INTERRUPTSINTERRUPTS

Page 38: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

BIOS And DOS Interrupts BIOS And DOS Interrupts

► Bios provide Basic Building Block and DOS Bios provide Basic Building Block and DOS /OS Work on it & provide different Interfaces/OS Work on it & provide different Interfaces

► BIOS (basic Input output Services)BIOS (basic Input output Services)► When Computer is Switch on BIOS get When Computer is Switch on BIOS get

control to a specified address control to a specified address ► For Booting Some Hardware Tests (Key Board For Booting Some Hardware Tests (Key Board

, Hard drive etc) Are performed Boot time on , Hard drive etc) Are performed Boot time on screen giving BIOS Version , Detecting Basic screen giving BIOS Version , Detecting Basic Hardware .and then BOOT strap mean that Hardware .and then BOOT strap mean that Load OS from Hard disk & from there OS take Load OS from Hard disk & from there OS take Control & process to load its Components Control & process to load its Components and Display a Command Prompt in the End and Display a Command Prompt in the End

Page 39: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

Continue Continue

►There are two important programs OS & There are two important programs OS & BIOS BIOS

►OS services are high level and Work on OS services are high level and Work on Bios Bios

►Bios Services are Low levelBios Services are Low level►Direct Controlling the hardware is Further Direct Controlling the hardware is Further

Low Level Low Level ►WE USE VIDEO By direct controlling Video WE USE VIDEO By direct controlling Video

Memory By passing BIOS Memory By passing BIOS

Page 40: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

BIOS SERVICESBIOS SERVICES

►BIOS services are Optionally with us .if BIOS services are Optionally with us .if we do not use there is no limitation on we do not use there is no limitation on us we go & By Pass these Layer and us we go & By Pass these Layer and access Hardware directly access Hardware directly

►Sometime Bios Did Not Provide Some Sometime Bios Did Not Provide Some Sort of Services So we By Pass BIOS Sort of Services So we By Pass BIOS layer DOS Layer and Straightly go to layer DOS Layer and Straightly go to HardwareHardware

Page 41: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

USELESSUSELESS

► If BIOS did not Communicate With our program it is If BIOS did not Communicate With our program it is Useless so there Must some Mechanism way to Useless so there Must some Mechanism way to communicatecommunicate

► So we use INTERRUPT MECHANISM So we use INTERRUPT MECHANISM Interrupts Provide a standard interrupt Num forInterrupts Provide a standard interrupt Num forCaller & Flexibility to place A routine Anywhere in theCaller & Flexibility to place A routine Anywhere in theMemory Memory So INT 10 Video Services So INT 10 Video Services INT 16 Keyboard Services INT 16 Keyboard Services So Manufacturer place Code where ever he want andSo Manufacturer place Code where ever he want andService are exportedService are exported

Page 42: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

BIOS/ DOS SERVICESBIOS/ DOS SERVICES

► Keyboard Services are Exported through INT Keyboard Services are Exported through INT 1616

► Parallel Port Services Through INT 17Parallel Port Services Through INT 17►DOS has Single Entry point Through INT 21DOS has Single Entry point Through INT 21► The Sub services Concept Lies here Every The Sub services Concept Lies here Every

Service Number has Further Sub Services Service Number has Further Sub Services ► Like INT 10 (VIDEO SERVICES)Like INT 10 (VIDEO SERVICES)► 00 For Video00 For Video► 01 for Set cursor size 01 for Set cursor size ►…………

Page 43: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

BIOS SERVICES BIOS SERVICES

► Services Num Is Usually given in AH Register Services Num Is Usually given in AH Register While Sub service Num is In AL or BL While Sub service Num is In AL or BL

BIOS INTERRUPT SERVICES:BIOS INTERRUPT SERVICES:INT 0x10 Video ServiceINT 0x10 Video ServiceINT 0x13 Disk ServiceINT 0x13 Disk ServiceINT 0x14 Serial Port ServiceINT 0x14 Serial Port ServiceINT 0x16 Key board ServiceINT 0x16 Key board ServiceINT 0x17 Parallel Port ServiceINT 0x17 Parallel Port ServiceINT 0x1A Time & Date ServiceINT 0x1A Time & Date Service

Page 44: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

0x10 Video SUB SERVICES0x10 Video SUB SERVICES

►0x00 Video Mem0x00 Video Mem►0x01 Set Cursor Size0x01 Set Cursor Size►0x02 Set Cursor Position0x02 Set Cursor Position►0x06 Scroll Screen Up0x06 Scroll Screen Up►0x07 Scroll Screen Down 0x07 Scroll Screen Down ►0x13 Write Character String0x13 Write Character String

Page 45: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

Example Cursor Screen UpExample Cursor Screen Up0x06 sub service 0x06 sub service

Page 46: Assembly Language Lecture 21-23 Presented By Shery khan 10:00 to 11:00 Sherykhan186@gmail.com

SummarySummary

► INTERRUPTSINTERRUPTS►RESERVED INTERRUPTSRESERVED INTERRUPTS►BIOS & DOS INTERRUPTSBIOS & DOS INTERRUPTS

THE END :THE END :

FEED BACKSFEED BACKS

[email protected]@gmail.com

THANKSTHANKS