1 TDT4160 Datamaskiner Grunnkurs 2011 Gunnar Tufte
ISA (5) 2
Instruksjonsformat kort/langt 3
Adresseringsmodi 4
Instruksjonstypar I/O avbrudd 5
Avbrudd: Kva og korleis ISA-definert 6
Avbrudd (Interrupt, Irq) 7 IR CPU PC intr request intr ack data/address status reg data reg mechanism Kva som skjer definert på ISA nivå Som programerarar må me vite dette for å kunne lage program Avbruddshantering krever maskinvare Handtering: styreeining Avbrudsinformasjon register
Avbrudd (f.eks) Programmering av I/O: 8 Busy-wait CPU test status of I/O (løkke/loop) CPU utfører løkke til aktuell status endring oppstår I løkke les status til I/O eining loopstart Read keyboard status if keypressed goto selectaction loopend selectaction if key = x do. if key = y do. : goto loopstart
Avbrudd Programering av I/O: 9 Busy-wait CPU test status of I/O (løkke/loop) CPU utfører løkke til aktuell status endring oppstår I løkke les status til I/O eining Interrupt Eining gir signal til CPU ved behov CPU kan utføre andre oppgåver CPU har innebygde mekanismar for å detektere å handtere avbrudd
Avbrudd: Grensesnitt (internt externt) 10 IR CPU PC intr request intr ack data/address status reg data reg mechanism Device request CPU CPU receive Irq input signal CPU acknowledge request Utfør kode for avbrudd F.eks Data transferee (CPU <-> device)
8051 register bruk 11
Minnemodell 8051 (minnekart) 12
Avbrudd register 13 Interrupt vector Adresse CPU hoppar til ved avbrudd Avbudskode eller ei ny adresse som peikar på koden Interrupt register Register der kvar avbrudskjelde kan setje eit bit (sett ved avbrudd) Interrupt mask register Register der ein kan skru av og på kvart enkelt avbrudd Maskable interrupt NMI (NonMaskable Interrupt) Kan ikkje maskerast Interrupt priority register(s) Register der det er mogleg å prioritere avbrudd Ved samtidig avbrudd frå fleire kjelder er rekkefølgjen av avbrudda gitt I dette registeret NMI (NonMaskable Interrupt) alltid høgast (kan ikkje endrast)
Interupts vector 14 Internt register Adressa til interrupt kode Adressa til koden som skal utførast Adressa til interrupt handler 8051 interrupts: Interrupt Flag Interrupt Handler Address External 0 IE0 0003h Timer 0 TF0 000Bh External 1 IE1 0013h Timer 1 TF1 001Bh Serial RI/TI 0023h
Interupts vector 15 0x00010000
Interupts vector 16 0x00001000 0x00010000 0x00100000 0x01000000
Interupts vector 17 CPU har mange avbrudskjelder Mulige kjelder Irq Asynchronous serial port Synchronous serial port Bus logic Timer General purpose Irq-line(s) (external) NMI Prosessor kan definere vector for kvart avbrudd Prosessor kan definere ein vector for IRQ-kode (SW) Fleireavbrudd kan dele eit fysisk avbrudd
Interupts register 18 Tre kjelder vist RS232 Serial receive device (RS232 R) RS232 Serial transmit device (RS232 T) Timer Kvar kan gi avbrudd, avbrudd set flag I interrupt register: IrqAsR IrqAsT IrqTimC
Interupts register Signal til CPU kontrolllogikk: Interrupt detektert Interrupt register Kvart Irq kan setje eit bit Kan lese registeret for å finne ut kva avbrudd som er aktivt 19 Til CPU-kontroll logikk
Interupts mask register Enable/disable interrupts Kan disable midlertidig for å ikkje å få avbrudd i avbrudd Bit I register 1 Irq enable, 0 disable 20 Irq-mask register IrqAsR IrqAsT IrqXX IrqXX IrqXX IrqXX IrqXX IrqTimC Irq-register IrqAsR IrqAsT IrqXX IrqXX IrqXX IrqXX IrqXX IrqTimC Logic Logic Logic Shift Register Shift Register Timer register CLK CLK RS232 R RS232 T Timer CLK
Avbrudd prioritering 21
Avbrudd prioritering 22
Interupts priority register Brukast for å prioritere kva som er viktigaste kjelde 23 Irq-priority register IrqAsR IrqAsT IrqXX IrqXX IrqXX IrqXX IrqXX IrqTimC Irq-mask register IrqAsR IrqAsT IrqXX IrqXX IrqXX IrqXX IrqXX IrqTimC Irq-register IrqAsR IrqAsT IrqXX IrqXX IrqXX IrqXX IrqXX IrqTimC Logic Logic Logic Shift Register Shift Register Timer register CLK CLK RS232 R RS232 T Timer CLK
Interupts priority register 24 F.eks: IrqAsR level 2 IrqAsT level 3 IrqTimC level 4 NMI level 0 (alltid)
Interupts programming Initialization of programm Set interrupt priority as needed Mask out interrupts that is not in use 25
Irq: Program running Ved interrupt (CPU): PC stored Status register stored JMP Irq vector read Irq-register (user) LDA Irq-register Disable Irq? Write Irq mask register Mask register BEQ receive, IrqAsR BEQ transmit, IrqAsT BEQ Timer, IrqTimC Return from Irq-routine restore PC, status (CPU) restore status register Clear Irq bit Write to Interrupt register Enable interrupt Write to Interrupt mask register 26
Avbrudd (utføring) 27
Flytkontrol (flow control) 28
Flytkontrol (flow control) 29
Abstraksjonar bryt saman 30
Prosedyre 31
Prosedyre (stack) 32
Prosedyre oppsummering 33
Ko-rutiner 34
Trap 35
Ferdig, manglar litt bits & pices 36 Kva no? Manglar nokre små ting Avhengigheitar Flyttal Div snusk MEN NO: Snu på hovude (ned opp (eller opp ned) Reversert gjennom det Prøve å knytte saman med nokre eksempel
Har introdusert 6 nivå 37
For å få samanheng: 38
Nokre endringar 39 IJVM Assambly
Nokre endringar 40 IJVM Assambly
Ein slags Top-down av pensum 41 Kva ønskjer me? Har eit høgnivåspråk JAVA (forenkla til Integer Java) Ønskjer ei maskin å køyre program på EIT program: Assambly) Bryr oss ikkje med OS-ting (traps, korutiner osv) Må definere ISA Insruksjonsformat Minnemodell Instruksjonsset Maskin: Må ha ein Mikroarkitektur Lage ein prosessorarkitektur Støtte instruksjonar: kunne utføre (effektivt) alle inst. på ISA-nivå Handtering av minne Konstruere mikroarkitektur på digitalt logisk nivå Datapath (utførandeiningar) Control (styreeining) (Realisere prosessoren i silisium)
ISA Instruction Set Architecture 42 Kva ønskjer me? Har eit høgnivåspråk JAVA (forenkla til Integer Java) Går gjennom JAVA (forenkla her) Kva instruksjonar må/bør/kjektogha for å kunne køyre bytecode MÅ: Minne operasjonar (datatransport) Aritmetiske operasjonar Logiske operasjonar Betinga hopp Ubetinga hopp Også: Methode Utvida bitbredde (utvida instruksjonsbredde) NOP
ISA Instruction Set Architecture (5) 43 Kva ønskjer me? Har eit høgnivåspråk JAVA (forenkla til Integer Java) Må definere ISA Insruksjonsformat Minnemodell Instruksjonsset
Datatype: Heiltal, IntegerJavaVM 44
ISA Instruction Set Architecture 45 Kva ønskjer me? Har eit høgnivåspråk JAVA (forenkla til Integer Java) Må definere ISA Insruksjonsformat Kva er effiktivt Minnemodell Korleis skal data hentast lagrast og mellomlagrast? Instruksjonsset Instruksjonar mot minne og datapath
ISA Instruction Set Architecture 46 Kva ønskjer me? Har eit høgnivåspråk JAVA (forenkla til Integer Java) Insruksjonsformat: Undersøker IJVM behov, Kan klare oss med 1 adresse instruksjonar 0 adresse instruksjonar
47
48
Minne modell Utfrå behov i x-adresseinstruksjonar Utfrå IJVM program (feks methodar (korutiner)) STACK maskin Gir minnemodell 49
Minne modell og 0/1-adresseinstruksjonar Ingen direkte minneadresser er synlege men: Definerar korleis minne akseserast med register Desse registera manipulerar me aldri direkte PC LV SP CPP 50
Minne modell og 0/1-adresseinstruksjonar Ingen direkte minneadresser er synlege men: Definerar korleis minne akseserast med register Desse registera manipulerar me aldri direkte PC LV SP CPP Men indirekte Skjult for programerar, men nyttar Immidiate Register indirekte 51
Immediate adressering 52
Register-indirekte adressering 53
Har då: Datatype: Integer 0-adresse og 1-adresse instruksjonar Minnemodel: Stackmaskin Implisit adresering Immidiate Register imidiate 54 Kan lage oss eit instruksjonsset
ISA Instruction Set Architecture 55 Kva ønskjer me? Har eit høgnivåspråk JAVA (forenkla til Integer Java) Går gjennom JAVA (forenkla her) Kva instruksjonar må/bør/kjekt å ha for å kunne køyre bytecode MÅ: Minne operasjonar datatransport (huks at minne er minne, register, mem osv) Aritmetiske operasjonar Logiske operasjonar Betinga hopp Ubetinga hopp Bør: Methode Utvida bitbredde (utvida instruksjonsbredde) NOP
ISA Instruction Set Architecture Mnemonic Operands Description BIPUSH byte Push a byte onto stack DUPN /A Copy top word on stack and push ontostack ERR N/A Print an error message and halt the simulator GOTO label name Unconditional jump HALTN /A Halt the simulator IADDN /A Pop two words from stack; push their sumi ANDN /A Pop two words from stack; push Boolean AN DIFEQ label name Pop word from stack and branch if it is zero IFLT IF_ICMPEQ label name label name Pop word from stack and branch if it is less than zero Pop two words from stack and branch if they are equa INC byte Add a constant value to a local variable ILOAD variable name Push local variable onto stack INVOKEVIRTUAL method name Invoke a methodi ORN /A Pop two words from stack; push Boolean OR IRETURNN /A Return from method with integer value ISTORE variable name Pop word from stack and store in local variable ISUBN /A Pop two words from stack; push their difference LDC_Wconstant name Push constant from constant pool onto stack NOPN /A Do nothing OUTN /A Pop word off stack and print it to standard out POPN /A Delete word from top of stack SWAPN /A Swap the two top words on the stack WIDEN /A Prefix instruction; next instruction has a 16-bit index 56
Instruksjonstypar datatransport 57
Instruction Set: datatransport Mnemonic Operands Description BIPUSH byte Push a byte onto stack DUPN /A Copy top word on stack and push ontostack GOTO label name Unconditional jump IADDN /A Pop two words from stack; push their sumi ANDN /A Pop two words from stack; push Boolean AN DIFEQ label name Pop word from stack and branch if it is zero IFLT IF_ICMPEQ label name label name Pop word from stack and branch if it is less than zero Pop two words from stack and branch if they are equa INC byte Add a constant value to a local variable ILOAD variable name Push local variable onto stack INVOKEVIRTUAL method name Invoke a methodi ORN /A Pop two words from stack; push Boolean OR IRETURNN /A Return from method with integer value ISTORE variable name Pop word from stack and store in local variable ISUBN /A Pop two words from stack; push their difference LDC_Wconstant name Push constant from constant pool onto stack NOPN /A Do nothing POPN /A Delete word from top of stack SWAPN /A Swap the two top words on the stack WIDEN /A Prefix instruction; next instruction has a 16-bit index 58
Instruksjonstypar datamanipulering59
Instruction Set: Aritmetiske operasjonar 60 Mnemonic Operands Description BIPUSH byte Push a byte onto stack DUPN /A Copy top word on stack and push ontostack GOTO label name Unconditional jump IADDN /A Pop two words from stack; push their sumi ANDN /A Pop two words from stack; push Boolean AN DIFEQ label name Pop word from stack and branch if it is zero IFLT IF_ICMPEQ label name label name Pop word from stack and branch if it is less than zero Pop two words from stack and branch if they are equali INC byte Add a constant value to a local variable ILOAD variable name Push local variable onto stack INVOKEVIRTUAL method name Invoke a methodi ORN /A Pop two words from stack; push Boolean OR IRETURNN /A Return from method with integer value ISTORE variable name Pop word from stack and store in local variable ISUBN /A Pop two words from stack; push their difference LDC_Wconstant name Push constant from constant pool onto stack NOPN /A Do nothing POPN /A Delete word from top of stack SWAPN /A Swap the two top words on the stack WIDEN /A Prefix instruction; next instruction has a 16-bit index
Instruction Set: Logiske operasjonar Mnemonic Operands Description BIPUSH byte Push a byte onto stack DUPN /A Copy top word on stack and push ontostack GOTO label name Unconditional jump IADDN /A Pop two words from stack; push their sumi ANDN /A Pop two words from stack; push Boolean AN DIFEQ label name Pop word from stack and branch if it is zero IFLT IF_ICMPEQ label name label name Pop word from stack and branch if it is less than z Pop two words from stack and branch if they are e INC byte Add a constant value to a local variable ILOAD variable name Push local variable onto stack INVOKEVIRTUAL method name Invoke a methodi ORN /A Pop two words from stack; push Boolean OR IRETURNN /A Return from method with integer value ISTORE variable name Pop word from stack and store in local variable ISUBN /A Pop two words from stack; push their difference LDC_Wconstant name Push constant from constant pool onto stack NOPN /A Do nothing POPN /A Delete word from top of stack SWAPN /A Swap the two top words on the stack WIDEN /A Prefix instruction; next instruction has a 16-bit inde 61
Instruksjonstypar betingahopp 62
Instruction Set: Betingahopp Mnemonic Operands Description BIPUSH byte Push a byte onto stack DUPN /A Copy top word on stack and push ontostack GOTO label name Unconditional jump IADDN /A Pop two words from stack; push their sumi ANDN /A Pop two words from stack; push Boolean AN DIFEQ label name Pop word from stack and branch if it is zero IFLT IF_ICMPEQ label name label name Pop word from stack and branch if it is less than zero Pop two words from stack and branch if they are equali INC byte Add a constant value to a local variable ILOAD variable name Push local variable onto stack INVOKEVIRTUAL method name Invoke a methodi ORN /A Pop two words from stack; push Boolean OR IRETURNN /A Return from method with integer value ISTORE variable name Pop word from stack and store in local variable ISUBN /A Pop two words from stack; push their difference LDC_Wconstant name Push constant from constant pool onto stack NOPN /A Do nothing POPN /A Delete word from top of stack SWAPN /A Swap the two top words on the stack WIDEN /A Prefix instruction; next instruction has a 16-bit index 63
Instruction Set: Ubetingahopp Mnemonic Operands Description BIPUSH byte Push a byte onto stack DUPN /A Copy top word on stack and push ontostack GOTO label name Unconditional jump IADDN /A Pop two words from stack; push their sumi ANDN /A Pop two words from stack; push Boolean AN DIFEQ label name Pop word from stack and branch if it is zero IFLT IF_ICMPEQ label name label name Pop word from stack and branch if it is less than z Pop two words from stack and branch if they are e INC byte Add a constant value to a local variable ILOAD variable name Push local variable onto stack INVOKEVIRTUAL method name Invoke a methodi ORN /A Pop two words from stack; push Boolean OR IRETURNN /A Return from method with integer value ISTORE variable name Pop word from stack and store in local variable ISUBN /A Pop two words from stack; push their difference LDC_Wconstant name Push constant from constant pool onto stack NOPN /A Do nothing POPN /A Delete word from top of stack SWAPN /A Swap the two top words on the stack WIDEN /A Prefix instruction; next instruction has a 16-bit inde 64
Instruksjonstypar prosedyrekall 65
Instruction Set: Methode (pross. kall) Mnemonic Operands Description BIPUSH byte Push a byte onto stack DUPN /A Copy top word on stack and push ontostack GOTO label name Unconditional jump IADDN /A Pop two words from stack; push their sumi ANDN /A Pop two words from stack; push Boolean AN DIFEQ label name Pop word from stack and branch if it is zero IFLT IF_ICMPEQ label name label name Pop word from stack and branch if it is less than z Pop two words from stack and branch if they are e INC byte Add a constant value to a local variable ILOAD variable name Push local variable onto stack INVOKEVIRTUAL method name Invoke a methodi ORN /A Pop two words from stack; push Boolean OR IRETURNN /A Return from method with integer value ISTORE variable name Pop word from stack and store in local variable ISUBN /A Pop two words from stack; push their difference LDC_Wconstant name Push constant from constant pool onto stack NOPN /A Do nothing POPN /A Delete word from top of stack SWAPN /A Swap the two top words on the stack WIDEN /A Prefix instruction; next instruction has a 16-bit inde 66
Instruction Set: Andre Mnemonic Operands Description BIPUSH byte Push a byte onto stack DUPN /A Copy top word on stack and push ontostack GOTO label name Unconditional jump IADDN /A Pop two words from stack; push their sumi ANDN /A Pop two words from stack; push Boolean AN DIFEQ label name Pop word from stack and branch if it is zero IFLT IF_ICMPEQ label name label name Pop word from stack and branch if it is less than zero Pop two words from stack and branch if they are equal INC byte Add a constant value to a local variable ILOAD variable name Push local variable onto stack INVOKEVIRTUAL method name Invoke a methodi ORN /A Pop two words from stack; push Boolean OR IRETURNN /A Return from method with integer value ISTORE variable name Pop word from stack and store in local variable ISUBN /A Pop two words from stack; push their difference LDC_Wconstant name Push constant from constant pool onto stack NOPN /A Do nothing POPN /A Delete word from top of stack SWAPN /A Swap the two top words on the stack WIDEN /A Prefix instruction; next instruction has a 16-bit index 67
Har då: Datatype: Integer 68 0-adresse og 1-adresse instruksjonar Minnemodel: Stackmaskin Instruksjonsset
Neste gong 69 Fredag 11/11 ISA: frå ISA til microarkitektur og vidare til digital logikk
Instruksjonstypar DMA 70