Assembly Language Lecture By Shery khan 24-25-26 [email protected] .
-
Upload
gloria-norris -
Category
Documents
-
view
217 -
download
2
Transcript of Assembly Language Lecture By Shery khan 24-25-26 [email protected] .
Assembly Language Assembly Language
Lecture ByLecture ByShery khanShery khan24-25-2624-25-26
[email protected]@gmail.comwww.sherykhan.jimdo.comwww.sherykhan.jimdo.com
AgendaAgenda
What are Real time Interrupts & Hardware What are Real time Interrupts & Hardware Interfacing?Interfacing?
What are I/O Ports?What are I/O Ports? What are IN/OUT Instruction?What are IN/OUT Instruction? What are PIC Port?What are PIC Port? What is Interrupt Chaining?What is Interrupt Chaining? What are TSR?What are TSR? Lastly we study Programmable Interval timer?Lastly we study Programmable Interval timer?
Hardware InterruptsHardware Interrupts
Single pin outside the processor Single pin outside the processor Called INT PIN that are used for External Called INT PIN that are used for External
hardware to generate Interrupthardware to generate Interrupt There are many devices that need processor There are many devices that need processor
Attention like keyboard ,Hard disk ,Floppy Attention like keyboard ,Hard disk ,Floppy Disk etcDisk etc
If processor actively monitor all devices If processor actively monitor all devices instead of being automatically interrupted instead of being automatically interrupted then Processor cant do any meaningful workthen Processor cant do any meaningful work
ContinueContinue
Since there are many devices generating Since there are many devices generating interrupts there is going one pin inside the interrupts there is going one pin inside the processor & one pin cannot be technically processor & one pin cannot be technically derived by more than one source a controller is derived by more than one source a controller is used b/w called programmable Interrupt used b/w called programmable Interrupt controller (pic)controller (pic)
It has Eight input & single Output It has Eight input & single Output The Eight Input signal to Pic are called The Eight Input signal to Pic are called
Interrupt RequestInterrupt Request
Hardware InterruptHardware Interrupt
Hence “ A hardware Interrupt is a signal Hence “ A hardware Interrupt is a signal Received by the CPU that Tells it to Interrupt Received by the CPU that Tells it to Interrupt Its Current Sequence of Instruction &branch to Its Current Sequence of Instruction &branch to a new Location .cpu supports 256 Interrupts a new Location .cpu supports 256 Interrupts numbered 0-FF Hexa decimal “numbered 0-FF Hexa decimal “
IRQ Level: Interrupt can be triggered by a IRQ Level: Interrupt can be triggered by a number of different devices on PC .Each number of different devices on PC .Each Device has Priority based on Interrupt level Device has Priority based on Interrupt level or IRQ level . Level 0 has Highest Priorityor IRQ level . Level 0 has Highest Priority
What is IRQ????What is IRQ????
There are 8 Sources in Programmable Interrupt There are 8 Sources in Programmable Interrupt ControllerController
You See in BIOS Parallel Port IRQ 3 etcYou See in BIOS Parallel Port IRQ 3 etc These are 8 input Lines in IBM PC which ar These are 8 input Lines in IBM PC which ar
connected to Different Devices connected to Different Devices The 8 Input signal to Programmable Interrupt The 8 Input signal to Programmable Interrupt
are called IRQ Below Table is Explained are called IRQ Below Table is Explained Highest priority IRQ 0 which is TimerHighest priority IRQ 0 which is Timer IRQ 1 for Keyboard etcIRQ 1 for Keyboard etc
IRQ vs. INT MappingIRQ vs. INT Mapping
Each IRQ is Mapped to specific Interrupt in the Each IRQ is Mapped to specific Interrupt in the system This is Called IRQ & INT Mapping system This is Called IRQ & INT Mapping
IRQ 0 to 7 consecutively mapped on Int 8 to FIRQ 0 to 7 consecutively mapped on Int 8 to F This Mapping is Done by PIC not the Processor This Mapping is Done by PIC not the Processor The Actual Mechanism Fetches one Instruction from The Actual Mechanism Fetches one Instruction from
PIC whenever an INT PIN is Signaled instead of PIC whenever an INT PIN is Signaled instead of Memory Memory
We can program the pic to generate a different set of We can program the pic to generate a different set of INTERRUPT on the same Interrupt Request INTERRUPT on the same Interrupt Request
IRQ 0 is translated to INT 8IRQ 0 is translated to INT 8
Table of IRQ and InterruptsTable of IRQ and Interrupts
TableTableIRQIRQ Interrupt Interrupt
NumNumDescriptionDescription
00 88 System Timer System Timer 18.2 time/sec18.2 time/sec
11 99 KeyboardKeyboard
22 0Ah=100Ah=10 Programmable Programmable Interrupt Interrupt ControllerController
33 0Bh=110Bh=11 Serial Port 2Serial Port 2
44 0Ch=120Ch=12 Serial Port 1Serial Port 1
55 0Dh0Dh LPT2 (parallel LPT2 (parallel port 1)port 1)
66 0Eh0Eh Floppy disk Floppy disk ControllerController
77 0Fh0Fh LPT1(P P1)LPT1(P P1)
88 70h70h Real Time Real Time clockclock
99 71h71h Redirected to Redirected to INT 0AhINT 0Ah
1010 72h72h Sound cardSound card
1111 73h73h SCSI CardSCSI Card
1212 74h74h PS/2 MOUSEPS/2 MOUSE
1313 75h75h Math Math CoprocessorCoprocessor
1414 76h76h Hard disk Hard disk ControllerController
1515 77h 77h AvailableAvailable
PriorityPriority
IRQ 0 the Highest Priority Interrupt is IRQ 0 the Highest Priority Interrupt is generated by the Timer chip frequency and generated by the Timer chip frequency and Handler at INT 8 is Invoked which Update the Handler at INT 8 is Invoked which Update the the System Time.the System Time.
A key Press generated IRQ 1 and the INT 9 A key Press generated IRQ 1 and the INT 9 handler is invoked which store this Keyhandler is invoked which store this Key
What is IRQ Conflict???What is IRQ Conflict???
When Network Card and Sound Card is Fit in When Network Card and Sound Card is Fit in the Motherboard of the System and Connected the Motherboard of the System and Connected to Processor through IRQ 5 both have Same to Processor through IRQ 5 both have Same IRQ at that Situation when 2 outputs sources IRQ at that Situation when 2 outputs sources drive one Input source then we say that IRQ drive one Input source then we say that IRQ conflict conflict
Working /Mechanism of IRQ & EOIWorking /Mechanism of IRQ & EOI
when a key is Pressed IRQ 1 is generated and INT 9 when a key is Pressed IRQ 1 is generated and INT 9 Handler which stores the key .Handler which stores the key .
When an Interrupt comes Outside the Processor or When an Interrupt comes Outside the Processor or From a Device it Reaches to PIC as then Processor From a Device it Reaches to PIC as then Processor and Processor Invoke the software related routine and Processor Invoke the software related routine now this Routine is working after some time it Tells now this Routine is working after some time it Tells to PIC that I finish my work so we Acknowledge the to PIC that I finish my work so we Acknowledge the PIC BY END OF INTERRUPT so that the Switches PIC BY END OF INTERRUPT so that the Switches which are Open that they Closed and Other Waiting which are Open that they Closed and Other Waiting Interrupts Are Come that Processor Serve Them Interrupts Are Come that Processor Serve Them
I/O PORTSI/O PORTS
Around the Processor the Different Devices Around the Processor the Different Devices like Printer , Video , Keyboard Port ,etc like Printer , Video , Keyboard Port ,etc
How the Processor Communicate with these How the Processor Communicate with these Devices if Processor Don’t Communicate with Devices if Processor Don’t Communicate with These Devices don’t send or Receive data then These Devices don’t send or Receive data then there no function is performed . there no function is performed .
So the Processor must Communicate with So the Processor must Communicate with these Devices these Peripheral Devices are these Devices these Peripheral Devices are called I/O PORTS called I/O PORTS
continuecontinue
Processor Communicate with Peripheral Processor Communicate with Peripheral devices is Similar as it can Communicate with devices is Similar as it can Communicate with MEMORY MEMORY
Similar to Memory Operation it can Similar to Memory Operation it can Either Read or Write .Either Read or Write . Some thing is Happen when Processor Read or Some thing is Happen when Processor Read or
Write on I/O PORTS Write on I/O PORTS
Separation of Peripheral address Separation of Peripheral address &Memory Address Space &Memory Address Space
IBM PC or IAPX 8088 Processor Separate IBM PC or IAPX 8088 Processor Separate Peripheral Address space from the Memory Peripheral Address space from the Memory Address Space Address Space
Another Concept is there Another Concept is there
MEMORY MAPPED I/O: Designated Memory MEMORY MAPPED I/O: Designated Memory cell Work as a Port for specific devices . (wo cell Work as a Port for specific devices . (wo input devices jo memory address ka ander hi input devices jo memory address ka ander hi periphiral adress ko bhe rakhta hain)periphiral adress ko bhe rakhta hain)
continuecontinue
Processor see only Data Bus & Address Bus Processor see only Data Bus & Address Bus Iapx8088 divides in two parts Iapx8088 divides in two parts First is MEMORY Operation (Move is Valid)First is MEMORY Operation (Move is Valid) Secondly one Signal tells that at this Particular Secondly one Signal tells that at this Particular
time what was the Interest of Processor time what was the Interest of Processor whether it is Interested in Outside World I/O whether it is Interested in Outside World I/O Ports or whether it is Interested in Memory Ports or whether it is Interested in Memory world world
Continue Continue
For this Purpose it uses a number which is on For this Purpose it uses a number which is on Address Bus that Tells the Interest of Address Bus that Tells the Interest of Processor Processor
Iapx 8088 uses a PIN we called as I/O by Iapx 8088 uses a PIN we called as I/O by n n bar bar
When this PIN is Level 0 processor Access Memory When this PIN is Level 0 processor Access Memory When this Pin is Level 1 it can Access I/o portWhen this Pin is Level 1 it can Access I/o port Basically the num is on Address bus which indicate Basically the num is on Address bus which indicate
that it is of I/O world or Memory world that it is of I/O world or Memory world
continuecontinue
Read & write operation are performed by using same Read & write operation are performed by using same data Bus and Address bus data Bus and Address bus
PIN I/O by n bar Differentiate that from which world PIN I/O by n bar Differentiate that from which world data is expected data is expected
So by this way it can read or write the Peripheral So by this way it can read or write the Peripheral Register Register
The I/O space is of 16 bits which mean 64 K The I/O space is of 16 bits which mean 64 K Different I/O ports connect to it Different I/O ports connect to it Which we say that 65536 I/O PORTS are connected Which we say that 65536 I/O PORTS are connected
to Processor to Processor
Continue Continue
Keyboard is mapped to I/O ports in this I/o Keyboard is mapped to I/O ports in this I/o space space
PIC is mapped , sound card etc ………PIC is mapped , sound card etc ……… There are port address through which There are port address through which
communication is done communication is done
IN /OUT INSTRUCTIONIN /OUT INSTRUCTION
There are two special instruction for read and There are two special instruction for read and write I/o ports write I/o ports
For read we use IN (port to processor)For read we use IN (port to processor) For Write we use OUT (processor to port)For Write we use OUT (processor to port) When we use IN/out instead of MOV the When we use IN/out instead of MOV the
Processor Automatically indicate I/O by n bar Processor Automatically indicate I/O by n bar Indicate that it is read or Write from I/O portIndicate that it is read or Write from I/O port There are also two variant in BYTE & WORDThere are also two variant in BYTE & WORD
Address of the PortsAddress of the Ports
Port 21 is for PIC (Prog Interrupt controller)Port 21 is for PIC (Prog Interrupt controller) Port 61 is for Keyboard Port 61 is for Keyboard Port 378 H is for Parallel Port so on……..Port 378 H is for Parallel Port so on…….. IN: in this Instruction we use a destination Register in IN: in this Instruction we use a destination Register in
which data comes while read from port to processor which data comes while read from port to processor in Byte case we use ALin Byte case we use AL
In Word case we AXIn Word case we AX Port address is not in segment and Offset form Port address is not in segment and Offset form It is Just a NUM and it is Destination so it is DX It is Just a NUM and it is Destination so it is DX
registerregister
ContinueContinue If the port num is less than 255 or it can fit in 8 bit so If the port num is less than 255 or it can fit in 8 bit so
we cannot use DX or not store in DX register it is we cannot use DX or not store in DX register it is written directly in instructionwritten directly in instruction
Port num tells us that at some particular time Port num tells us that at some particular time Processor talk to which specific device/ portProcessor talk to which specific device/ port
IN : we can first read and then fetched so register is IN : we can first read and then fetched so register is first written first written
OUT: at there the data is written on port so the the OUT: at there the data is written on port so the the destination is port so port number is first written in destination is port so port number is first written in the instruction the instruction
All the Rules of MOV instruction are followed All the Rules of MOV instruction are followed ………………
Sample Sample
Lecture 25Lecture 25
Keyboard Controller:Keyboard Controller: Keyboard is the collection of labeled button Keyboard is the collection of labeled button
and every button is designated a number (not and every button is designated a number (not the AscII Code)the AscII Code)
The number is send to the processor when the The number is send to the processor when the Key is Pressed from this number called Scan Key is Pressed from this number called Scan Code the processor understand which Key was Code the processor understand which Key was Pressed Pressed
Scan Code Scan Code For Each Key Scan Code comes Twice once the Key press and For Each Key Scan Code comes Twice once the Key press and
once for key release once for key release Both Scan code are differ in one bit Both Scan code are differ in one bit The lower seven bit contain the key number The lower seven bit contain the key number While the Most Significant bit is clear in the Press code and While the Most Significant bit is clear in the Press code and
Set in the Release Code Set in the Release Code If we write Capital A so we First Press Shift Key the Scan If we write Capital A so we First Press Shift Key the Scan
Code is Sent then We Pressed A Scan Code is Sent then the Code is Sent then We Pressed A Scan Code is Sent then the Release code of A & release code of Shift Key and Interrupt Release code of A & release code of Shift Key and Interrupt Handler Understand That Sequence Should Result in ASCII Handler Understand That Sequence Should Result in ASCII Code of ACode of A
Interrupt handler REMEMBER the Sequence .Interrupt handler REMEMBER the Sequence .
Keyboard PortKeyboard Port
The Keyboard Port is 60 the Keyboard The Keyboard Port is 60 the Keyboard Generate IRQ 1 when Ever Key is Pressed so Generate IRQ 1 when Ever Key is Pressed so if we Hooked INT 9 inside the it read Port if we Hooked INT 9 inside the it read Port 60so we can tell Which Key is Pressed 60so we can tell Which Key is Pressed
Scan code table is Given Below Scan code table is Given Below
Scan code Scan code KEYSKEYS Scan CodeScan Code
11 7878
22 7979
33 7A7A
44 7B7B
55 7C7C
66 7D7D
77 7E7E
88 7F7F
99 8080
1010 8181
SCAN CODESCAN CODE
KEYKEY SCAN CODESCAN CODE
AA 1E1E
BB 3030
CC 2E2E
DD 2020
EE 1212
FF 2121
GG 2222
HH 2323
II 1717
SCAN CODESCAN CODE
KEYKEY SCAN CODESCAN CODE
JJ 2424
KK 2525
LL 2626
MM 3232
NN 3131
OO 1818
PP 1919
QQ 1010
RR 1313
SCAN CODESCAN CODE
KEYSKEYS SCAN CODESCAN CODE
SS IFIF
TT 1414
UU 1616
VV 2F2F
WW 1111
XX 2D2D
YY 1515
ZZ 2C2C
SCAN CODESCAN CODE
KEYSKEYS alonealone With CTRL KEYWith CTRL KEY
HOMEHOME 4747 7777
ENDEND 4F4F 7575
Page upPage up 4949 8484
PageDownPageDown 5151 7676
Left arrowLeft arrow 4B4B 7272
Right ArrowRight Arrow 4D4D 7373
uparrowuparrow 4848 7474
Dn arrowDn arrow 5050
insertinsert 5252
USING SCAN CODE PROGRAMUSING SCAN CODE PROGRAM
in al,0x60 ;Keyboard Portin al,0x60 ;Keyboard Port cmp al,0x47……………HOME KEY cmp al,0x47……………HOME KEY jne nextcmpjne nextcmp
nextcmp:nextcmp: cmp al,0x4B ;Left arrow …………..LEFT cmp al,0x4B ;Left arrow …………..LEFT jne nomatch jne nomatch
THAT’S PROGRAM THAT’S PROGRAM [org 0x0100][org 0x0100] jmp startjmp start keyboardISR:keyboardISR: push axpush ax push espush es mov ax,0xb800mov ax,0xb800 mov es,axmov es,ax in al,0x60 ;Keyboard Port……………………………..in al,0x60 ;Keyboard Port…………………………….. cmp al,0x47……………………………………………..cmp al,0x47…………………………………………….. jne nextcmpjne nextcmp mov byte [es:0],'H'mov byte [es:0],'H' jmp nomatchjmp nomatch nextcmp:nextcmp: cmp al,0x4B ;Left arrow………………………………………..cmp al,0x4B ;Left arrow……………………………………….. jne nomatchjne nomatch mov byte [es:0],'L'mov byte [es:0],'L'
continuecontinue nomatch:nomatch: mov al,0x20mov al,0x20 out 0x20,alout 0x20,al pop espop es pop axpop ax iretiret start:start: xor ax,axxor ax,ax mov es,axmov es,ax clicli mov word [es:9*4],keyboardISRmov word [es:9*4],keyboardISR mov [es:9*4+2],csmov [es:9*4+2],cs stisti li:li: mov ah,0mov ah,0 int 0x16int 0x16
Lecture 26Lecture 26Basic OS UnderstandingBasic OS Understanding
In MS DOS Memory point of View we see In MS DOS Memory point of View we see first IVT then Os Different Things Appearfirst IVT then Os Different Things Appear
Then BIOS Data Area , Dos Data Area ,IO.sys Then BIOS Data Area , Dos Data Area ,IO.sys
Then MS Dos.sys and Device driver are loaded Then MS Dos.sys and Device driver are loaded
Then the MS Dos Command Interpreter is Then the MS Dos Command Interpreter is Loaded Loaded
Lastly the area which is Free for us called Lastly the area which is Free for us called Transient Program Area Transient Program Area
What is Meant For Transient????What is Meant For Transient????
We say this Area Transient because in this Area our We say this Area Transient because in this Area our Programs are loaded ,Executed and after there Programs are loaded ,Executed and after there Specific Work the Free this Area so that this Area is Specific Work the Free this Area so that this Area is Utilized by other program so that it is Called Utilized by other program so that it is Called Transient Area .Transient Area .
Mechanism :Dos maintain a Pointer which is called Mechanism :Dos maintain a Pointer which is called Free Mem from where the TPA is Started it Dos Free Mem from where the TPA is Started it Dos Pointer is Started and Remember the Position and it is Pointer is Started and Remember the Position and it is Own word to the RAM 640 K it is there Own word to the RAM 640 K it is there
Free Min Pointer Working Free Min Pointer Working
When Ever a program is Loaded to this When Ever a program is Loaded to this Memory the Free Min Pointer gives a Control Memory the Free Min Pointer gives a Control to Program when the Program Executed to Program when the Program Executed Finishes the Last to lines 4c Terminator Lines Finishes the Last to lines 4c Terminator Lines Return the Control to Free min Pointer And Return the Control to Free min Pointer And FREED the Space of TPA FREED the Space of TPA
Legal control return to DOS Legal control return to DOS
TerminationTermination
One way is to Freed all Memory and Return Control One way is to Freed all Memory and Return Control to Dos and Free Min Pointer is Start Pointing start of to Dos and Free Min Pointer is Start Pointing start of the TPA the TPA
Second way is that Free Min Pointer Stop Second way is that Free Min Pointer Stop Deallocation at some point were I say and some Part Deallocation at some point were I say and some Part of Program is Retain in this memory and make it Part of Program is Retain in this memory and make it Part of OS .or Some part of Program Resident at there of OS .or Some part of Program Resident at there leave the some part of program in this Memory . leave the some part of program in this Memory . Termination is Done Control Return but some Part of Termination is Done Control Return but some Part of Program Remain there and Pointer start Pointing after Program Remain there and Pointer start Pointing after that ………….that ………….
TSR TSR
Terminate & stay Resident :above the Terminate & stay Resident :above the Phenomena is Explain is Called TSR Phenomena is Explain is Called TSR
Control Return to DosControl Return to Dos Some Part Is Remain There in we say ResidentSome Part Is Remain There in we say Resident We say it is Extension of Command Prompt We say it is Extension of Command Prompt
and Not Over written from There Free Min and Not Over written from There Free Min Pointer is Starting New Programs are Executed Pointer is Starting New Programs are Executed after my Resident Programafter my Resident Program
How Much memory we Can How Much memory we Can Resident???Resident???
We Can Resident Memory in Multiples of We Can Resident Memory in Multiples of 16Byte we say that 32 byte,48,64 16Byte we say that 32 byte,48,64
These are in paragraph which is chunk of 16 These are in paragraph which is chunk of 16 Bytes and its Multiples Bytes and its Multiples
Labeling is Done when we Resident Labeling is Done when we Resident RoundUp is Done And Calculation is RoundUp is Done And Calculation is Label Offset +15/16=round up Label Offset +15/16=round up We know that 4 shift right is equal to division We know that 4 shift right is equal to division
of 16 so we use SHR while Doing Round UP of 16 so we use SHR while Doing Round UP
Programmable Interval TimerProgrammable Interval Timer PIT is Important Peripheral Device chip numbered is 8254 PIT is Important Peripheral Device chip numbered is 8254 Chip has Fixed Frequency 1.1938 MHZ Chip has Fixed Frequency 1.1938 MHZ Inside the chip 16 Bit Divisor which Divide the Input Inside the chip 16 Bit Divisor which Divide the Input
Frequency and output is Connected to IRQ 0 line of PIC Frequency and output is Connected to IRQ 0 line of PIC 0 means a divisor of 65536 0 means a divisor of 65536 1193180/65536=18.2 timer per sec this is called Timer TICK 1193180/65536=18.2 timer per sec this is called Timer TICK In one Sec 55 ms times a IRQ 0 is Coming so these Timer In one Sec 55 ms times a IRQ 0 is Coming so these Timer
Tick Are Counted and IBM PC maintain His TIME Tick Are Counted and IBM PC maintain His TIME
THAT’S ALLTHAT’S ALL
THANKS FOR LISTENING ME THANKS FOR LISTENING ME FEED BACKS FEED BACKS [email protected]@gmail.com www.sherykhan.jimdo.comwww.sherykhan.jimdo.com www.skvu.blogspot.comwww.skvu.blogspot.com RESPECT YOUR PARENTS ………….RESPECT YOUR PARENTS …………. ALLAH HAFIZ ALLAH HAFIZ