Index | Fejlesztés Development | CPU | Számítógép Computer | Assembler | Monitor | Függvények Library


Lang: Nyelv: HU EN

P1516 mikroprocesszor P1516 microprocessor

A mikroprocesszor egy RISC felépítésű (LOAD/STORE), Neumann architektúrájú 32 bites soft processzor, amelyet FPGA-val valósítunk meg. The microprocessor is a RISC-based (LOAD/STORE), Neumann architecture 32-bit soft processor implemented with FPGA.

A mikroprocesszor részei Parts of the microprocessor

A mikroprocesszor a szokásos építőelemekből áll. The microprocessor consists of the usual building blocks.

Ütemező, vezérlő Scheduler, controller

Az ütemező állítja elő a vezérlő jeleket a processzor többi eleme számára. Az ütemező állapot kódokat állít elő a működési fázisok jelzésére, az állapotok a CLK bemenetre adott órajel hatására követik egymást. Az állapotok bináris sorszáma a CLKstat kimeneten jelenik meg. A RESET bemenet az ütemezőt alaphelyzetbe állítja. The scheduler generates control signals for the other elements of the processor. The scheduler generates status codes to indicate the operating phases, the states follow each other in response to the clock signal given to the CLK input. The binary sequence number of the states is displayed on the CLKstat output. The RESET input resets the scheduler.

A vezérlőhöz tartozik még az ún. utasítás regiszter, amely a beolvasott utasítást tárolja a végrehajtás idejére. The controller also includes the so-called instruction register, which stores the read instruction for execution.

Memória illesztő Memory interafce

Mivel a processzor Neumann architektúrájú, ezért csak egy memória illesztővel rendelkezik. Ezen az illesztőn keresztül olvassa be az utasításokat, és ezen az illesztőn keresztül végzi el memória írási és olvasási műveleteket is. Since the processor has a Neumann architecture, it has only one memory interface. It reads instructions through this interface and also performs memory read and write operations through this interface.

Az illesztő az MA kimeneteken adja ki a művelethez használandó memória címet (32 bites). Írás esetén a memóriába tárolandó adat az MDO kimeneteken jelenik meg (32 bit). Ebben az esetben az MWE kimenet magas szintű lesz (írás jelzés). The adapter outputs the memory address (32 bits) to be used for the operation on the MA outputs. In case of writing, the data to be stored in the memory appears on the MDO outputs (32 bits). In this case, the MWE output will be high (write signal).

Olvasás műveletnél a megcímzett memória tartalmát az MDI bemenetre kell juttatni, ekkor az MWE kimenet alacsony lesz. Mind írás, mind olvasás esetén megjelenik az MCLK kimeneten egy impulzus, ennek felfutó éle használható a memória számára beíró jelként, illetve a pufferelt kimenetű memóriák esetén a kimeneti puffer beírására. For a read operation, the contents of the addressed memory must be sent to the MDI input, at which time the MWE output will be low. In both write and read a pulse appears on the MCLK output, the rising edge of which can be used as a write signal for the memory, or in the case of memories with buffered output to write the output buffer.

Memória szervezés Memory organization

A processzor által kezelt memória 32 bites szélességű, minden 32 bites rekesznek külön címe van. Memória műveletnél a processzor a megcímzett rekeszből 32 bites adatot olvas be, illetve 32 bites adatot ír ki. The memory managed by the processor is 32-bit wide, each 32-bit slot has a separate address. During a memory operation, the processor reads 32-bit data from the addressed slot, and writes 32-bit data.

Regiszterek Registers

A processzor állapota a belső regiszterekben tárolódik. A regiszter készlet 16 db 32 bites regiszterből áll. A regiszterek elnevezése: R0, R1...R15. The processor's state is stored in internal registers. The register set consists of 16 32-bit registers. The registers are named: R0, R1...R15.

Speciális regiszterek Special registers

PC

A processzor az R15 regisztert használja program számlálóként (Program Counter), ezért ennek tartalma minden utasítás végrehajtásakor eggyel növekszik. The processor uses register R15 as a program counter, so its contents are incremented by one each time an instruction is executed.

LR

A CALL utasítás a visszatéréshez szükséges címet az R14 (Link Regiszter) regiszterbe menti. The CALL instruction stores the return address in register R14 (Link Register).

SP

A processzor nem használ verem műveleteket, a verem megszervezése a programozó feladata. Az ehhez szükséges verem mutató (Stack Pointer) céljára bármelyik regiszter felhasználható. A programok megírásakor az R13 regisztert használtuk SP-ként. The processor does not use stack operations, the stack is organized by the programmer. Any register can be used for the required stack pointer. When writing the programs, the R13 register was used as SP.

Aritmetikai-logikai egység Arithmetic-logic unit

Az adat manipulációs műveleteket az ALU végzi, amely 32 bites egész (előjeles és előjel nélküli) adatokkal tud műveleteket végezni. Az ALU-nak 3 adat bemenete van: Rd, Ra, Rb. Az Rd bemenetre az eredményt eltároló regiszter eredeti (művelet előtti) értékét kell kötni. Az Ra és Rb bemenetekre a művelet operandusaként használt regiszterek értéke kerül. Az egy operandusú műveletek csak az Ra bemenetet használják, míg a két operandusú műveletek az Ra és az Rb értékeket használják fel. Az operandus nélküli műveleteknél az eredmény a változatlan Rd bemeneti érték lesz. Data manipulation operations are performed by the ALU, which can operate on 32-bit integer (signed and unsigned) data. The ALU has 3 data inputs: Rd, Ra, Rb. The original value (before the operation) of the register storing the result must be connected to the Rd input. The values ​​of the registers used as the operands of the operation are connected to the Ra and Rb inputs. One operand operations use only the Ra input, while two operand operations use the Ra and Rb values. In the case of operations without an operand, the result will be the unchanged Rd input value.

FLAG regiszter FLAG register

Az aritmetikai egység a műveletek eredményének jellemzőit a FLAG regiszterben tárolja el. Ez a regiszter nem része az általános regiszter készletnek, a tartalmához az utasítások speciális módon férhetnek csak hozzá. The arithmetic unit stores the characteristics of the operation result in the FLAG register. This register is not part of the general register set, its contents can only be accessed by instructions in a special way.

Carry flag (C)

Aritmetikai műveletek után azt jelzi, hogy előjel nélkülinek tekintve az operandusokat, volt-e túlcsordulás (1: volt, 0: nem volt). After arithmetic operations, indicates whether there was an overflow, considering the operands as unsigned (1: there was, 0: there was not).

Overflow flag (O)

Aritmetikai műveletek után azt jelzi, hogy előjelesnek tekintve az operandusokat, volt-e túlcsordulás (1: volt, 0: nem volt). After arithmetic operations, indicates whether there was an overflow, considering the operands as signed (1: there was, 0: there was not).

Sign flag (S)

Aritmetikai műveletek után után az eredmény előjelét jelzi (1: negatív, 0: pozitív) After arithmetic operations, indicates the sign of the result (1: negative, 0: positive)

Zero flag (Z)

Aritmetikai és logikai műveletek után azt jelzi, hogy az eredmény nulla-e (1: igen, 0: nem) After arithmetic and logical operations, indicates whether the result is zero (1: yes, 0: no)

A mikroprocesszor működése Operation of the microprocessor

Az utasítások végrehajtása a következő fázisokból áll. The execution of instructions consists of the following phases.

Fetch

Ebben a fázisban a processzor elvégzi a soron következő utasítás beolvasását. Az MA kimeneten megjelenik az R15 regiszter tartalma, az MWE kimenet alacsony szintű lesz, míg az MCLK kimeneten megjelenik egy felfutó él. In this phase, the processor reads the next instruction in the sequence. The MA output displays the contents of the R15 register, the MWE output goes low, and the MCLK output displays a rising edge.

Dekódolás Decoding

A következő fázisban fetch során megcímzett memória tartalom megjelenik az MDI bemeneten, ezt a processzor eltárolja az utasítás regiszterben. Ezzel egyidejűleg az R15 tartalma eggyel nő. In the next phase, the memory contents addressed during fetch appear on the MDI input, which the processor stores in the instruction register. At the same time, the contents of R15 are incremented by one.

Számítás Calculation

Az utasítás regiszter által meghatározott regiszterek tartalma megjelenik az ALU bemenetein, ezek az adatok áthaladnak az ALU-ban lévő aritmetikai hálózatokon. Ezek mindegyike kombinációs (nem sorrendi) hálózat, de több szintű felépítésük miatt a kimeneti eredmények megjelenéséhez több idő kell. Ennek kivárására szolgál a “számítás” fázis. The contents of the registers specified by the instruction register are displayed on the ALU inputs, and these data are passed through the arithmetic networks in the ALU. All of these are combinational (not sequential) networks, but due to their multi-level structure, it takes more time to display the output results. The “calculation” phase is used to wait for this.

Az utasítás regiszter tartalma azt is meghatározza, hogy az ALU kimenetén melyik hálózat eredménye jelenjen meg. The contents of the instruction register also determines which network result is displayed at the ALU output.

Memória művelet Memory operation

Ha az utasítás memória műveletet ír elő, akkor az ebben a fázisban zajlik le. Az MA kimeneten az utasításban meghatározott regiszter tartalma jelenik meg címként, írás esetén az MDO kimenetekre az utasításban megadott (kiírandó) regiszter tartalma kapcsolódik. Az MWE kimenet az elvégzendő műveletnek megfelelő értékű lesz. Az MCLK kimeneten megjelenik egy felfutó él. Olvasáskor a memóriának a címzett rekesz tartalmát az MDI bemenetre kell kapcsolnia, és ott kell tartania a következő fázis ideje alatt is. Ezért az MA kimeneteken a cím fennmarad a következő fetch fázis elejéig. If the instruction requires a memory operation, it takes place in this phase. The contents of the register specified in the instruction are displayed on the MA output as an address, and in the case of writing, the contents of the register specified in the instruction (to be written) are connected to the MDO outputs. The MWE output will have a value corresponding to the operation to be performed. A rising edge appears on the MCLK output. When reading, the memory must switch the contents of the addressed slot to the MDI input and hold it there during the next phase. Therefore, the address on the MA outputs will remain until the beginning of the next fetch phase.

Ha nincs szükség memória műveletre, akkor ebben a fázisban semmi sem történik. Ez megnöveli az aritmetikai eredmények kiszámításához rendelkezésre álló időt. If no memory operation is required, nothing happens in this phase. This increases the time available for calculating arithmetic results.

Eredmény tárolás Write-back

Az utasítás eredménye vagy az ALU kimenetén megjelent adat, vagy memória olvasásnál az MDI bemenetek állapota. Az eredmény tárolási (visszaírási, Write-Back) fázisban ez az érték beíródik az utasítás által meghatározott regiszterbe. Néhány utasításnak nincs eredménye, ezeknél az írás nem zajlik le (pl. memóriába írás, “nincs művelet” utasítás). Aritmetikai utasításoknál az ALU által előállított jelzőbitek is beíródnak a flag regiszterbe. The result of the instruction is either the data displayed on the ALU output or the state of the MDI inputs when reading from memory. In the result storage (Write-Back) phase, this value is written to the register specified by the instruction. Some instructions have no result, in these cases the write is not performed (e.g. write to memory, “no operation” instruction). In the case of arithmetic instructions, the flag bits generated by the ALU are also written to the flag register.

Utasítások Instructions

A processzor utasítás készlete 8 utasításból áll. Minden utasítás kódja 32 bites, egy memória rekeszben tárolódik. The processor instruction set consists of 8 instructions. Each instruction code is 32 bits long and is stored in one memory location.

Feltételes végrehajtás Conditional execution

Minden utasítás ellátható egy feltétellel, ekkor a memória írási és a visszaírási műveletek csak akkor hajtódnak végre, ha a feltétel teljesül. A feltétel megadja, hogy mely jelzőbit milyen értéke esetén lesz igaz. A feltétel elhelyezkedése az utasítás kódjában a következő: Each instruction can be equipped with a condition, in which case the memory write and write back operations are only executed if the condition is met. The condition specifies which flag bit will be equal to which value. The condition is located in the instruction code as follows:

FFVC.---- ----.---- ----.---- ----.----

Az F jelű bitek jelölik ki a flag bitet: The bits marked F indicate the flag bit:

A feltétel akkor teljesül, ha a kiválasztott jelzőbit értéke egyezik az utasításban lévő V bit értékével. A feltételt a vezérlő csak akkor veszi figyelembe, ha a kódban a C jelű bit 1, egyébként az utasítás feltétel nélkül hajtódik végre. The condition is met if the value of the selected flag bit matches the value of the V bit in the instruction. The condition is only considered by the controller if the bit marked C in the code is 1, otherwise the instruction is executed unconditionally.

Utasítások Instructions

NOP

“Nincs művelet” utasítás, hatására a memória, és a visszaírási fázisban nincs művelet. “No operation” instruction, causing no action in the memory and the writeback phase.

Az utasítás diagnosztikai célra használható, segítségével meg lehet figyelni az ALU be- és kimeneti értékeit. The instruction can be used for diagnostic purposes, allowing you to monitor the input and output values ​​of the ALU.

LD Rd,Ra

LOAD memory to register. Memória tartalom regiszterbe való beolvasására használható utasítás. Instruction used to read memory contents into a register.

ST Rd,Ra

STORE register to memory. Egy regiszter memóriába írására használható utasítás. A command used to write a register to memory.

MOV Rd,Ra

MOVE register to register. Regiszter másolás utasítás, az Ra regiszter értékét átmásolja az Rd regiszterbe. Register copy instruction, copies the value of register Ra to register Rd.

LDL0 Rd,adat

LOAD low half, set high half 0. Konstans adat regiszterbe írásához használható, az adat az utasításban található. Az adat 16 bites, a megadott regiszter alsó helyi értékű felére kerül, a regiszter felső helyi értékű fele 0 lesz. It can be used to write constant data to a register, the data is contained in the instruction. The data is 16 bits, the specified register is placed in the lower half of the register, the upper half of the register is set to 0.

LDL Rd,adat

LOAD low half of register. Konstans adat regiszterbe írásához használható, az adat az utasításban található. Az adat 16 bites, a megadott regiszter alsó helyiértékű felére kerül, a regiszter felső helyiértékű fele nem változik. It can be used to write constant data to a register, the data is contained in the instruction. The data is 16 bits, and is placed in the lower half of the specified register, while the upper half of the register remains unchanged.

LDH Rd,adat

LOAD high half of register. Konstans adat regiszterbe írásához használható, az adat az utasításban található. Az adat 16 bites, a megadott regiszter felső helyi értékű felére kerül, a regiszter alsó helyi értékű fele nem változik. It can be used to write constant data to a register, the data is contained in the instruction. The data is 16 bits, and is placed in the upper-order half of the specified register, while the lower-order half of the register remains unchanged.

CALL cím

Szubrutin hívás. Mivel a processzor memóriában lévő vermet nem kezel, a visszatérési címet (az R15 megnövelt értékét, amely a CALL-t követő utasítás címét tartalmazza) a memória fázisban átmásolja, beírja az R14 regiszterbe. Egymásba ágyazott szubrutin hívások esetén az R14 mentéséről a programozónak kell gondoskodnia. Subroutine call. Since the processor does not manage the stack in memory, the return address (the incremented value of R15, which contains the address of the instruction following the CALL) is copied and written into the R14 register in the memory phase. In the case of nested subroutine calls, the programmer must ensure that R14 is saved.

Az utasítás kódjában csak 27 bites cím helyezhető el, ezért csak a memória tartomány első 32-ed részében lévő szubrutint lehet meghívni. Only a 27-bit address can be placed in the instruction code, so only a subroutine in the first 32nd of the memory range can be called.

A szubrutinból való visszatéréshez az R14 (LR) értét kell bemásolni az R15-be (PC) egy MOV utasítással. To return from the subroutine, the value of R14 (LR) must be copied to R15 (PC) with a MOV instruction.

Aritmetikai, logikai utasítások Arithmetic, logical instructions

Ezek az utasítások az ALU kimenetén megjelenő adatot használják a visszaírási fázisban. Az utasítások kódja: These instructions use the data that appears at the ALU output in the writeback phase. The instructions code:

FFVC.0111 DDDD.AAAA BBBB.OOOO OXXX.XXXX

Az FFVC bitek a végrehajtási feltételt adják meg, a DDDD az eredményt tároló regiszter száma, az AAAA és BBBB bitek pedig az operandusokat tartalmazó regiszterek sorszámai. Az OOOOO bitek választják ki, hogy az ALU hálózatai közül melyik eredményét használjuk. Ez alapján maximum 32 művelet lehetséges, de ennél jelenleg kevesebb van megvalósítva. The FFVC bits specify the execution condition, DDDD is the number of the register storing the result, and the AAAA and BBBB bits are the serial numbers of the registers containing the operands. The OOOOO bits select which of the ALU networks results to use. Based on this, a maximum of 32 operations are possible, but fewer than this are currently implemented.

ADD Rd,Ra,Rb

Összeadás átvitel nélkül. Add without carry.

ADC Rd,Ra,Rb

Összeadás átvitellel. Add with carry.

SUB Rd,Ra,Rb

Kivonás átvitel nélkül. Subtraction without carry.

SBB Rd,Ra,Rb

Kivonás átvitellel. Subtraction with carry.

INC Rd,Ra

Növelés eggyel. Az Ra regiszter eggyel növelt értéke az Rd regiszterbe kerül. Az Ra és az Rd ugyanaz is lehet. Increment by one. The value of the Ra register increased by one is placed in the Rd register. Ra and Rd can be the same.

DEC Rd,Ra

Csökkentés eggyel. Az Ra regiszter eggyel csökkentett értéke az Rd regiszterbe kerül. Az Ra és az Rd ugyanaz is lehet. Decrement by one. The value of the Ra register, decremented by one, is placed in the Rd register. Ra and Rd can be the same.

AND Rd,Ra,Rb

Bitenkénti és művelet. Az eredmény egyes helyi értékei a két operandus ugyanazon helyi értékein lévő két bit közötti logikai ÉS művelet eredményeként keletkeznek. Bit(ek) vizsgálatára, illetve bit(ek) 0-ba állítására használható. Bitwise AND operation. Each local value of the result is the result of a logical AND operation between two bits at the same bit positions ​​of the two operands. It can be used to examine bit(s) or to set bit(s) to 0.

OR Rd,Ra,Rb

Bitenkénti vagy művelet. Az eredmény egyes helyi értékei a két operandus ugyanazon helyi értékein lévő két bit közötti logikai VAGY művelet eredményeként keletkeznek. Bit(ek) 1-be állítására használható. A bitwise OR operation. Each local value of the result is the result of a logical OR operation between two bits at the same bit position ​​of the two operands. It can be used to set bit(s) to 1.

XOR Rd,Ra,Rb

Bitenkénti kizáró vagy művelet. Az eredmény egyes helyi értékei a két operandus ugyanazon helyi értékein lévő két bit közötti logikai KIZÁRÓ VAGY művelet eredményeként keletkeznek. Bit(ek) összehasonlítására, illetve negálására használható. Bitwise exclusive OR operation. The result is the result of a logical EXCLUSIVE OR operation between two bits at the same bit position of the two operands. It can be used to compare or negate bit(s).

SHL Rd,Ra

Bitenkénti (logikai) eltolás, egy bittel balra. Az Ra regiszter minden bitje egy helyi értékkel feljebb lép, a 0-ik bit 0 lesz. A legfelső helyi értékű bit a C jelzőbitbe másolódik. Az eredmény az Rd regiszterbe kerül. Bitwise (logical) shift, one bit to the left. Each bit of the Ra register is moved up by one place value, the 0th bit becomes 0. The most significant bit is copied into the C flag bit. The result is placed in the Rd register.

shl.png

SHR Rd,Ra

Bitenkénti (logikai) eltolás, egy bittel jobbra. Az Ra regiszter minden bitje egy helyi értékkel lejjebb lép, a 31-ik bit 0 lesz. A legalsó helyi értékű bit a C jelzőbitbe másolódik. Az eredmény az Rd regiszterbe kerül. Bitwise (logical) shift, one bit to the right. Each bit of the Ra register is shifted down by one bit position, the 31st bit becomes 0. The least significant bit is copied into the C flag bit. The result is placed in the Rd register.

shr.png

SHA Rd,Ra

Bitenkénti (aritmetikai) eltolás, egy bittel jobbra. Az Ra regiszter minden bitje egy helyi értékkel lejjebb lép, a 31-ik bit nem változik. A legalsó helyi értékű bit a C jelzőbitbe másolódik. Az eredmény az Rd regiszterbe kerül. Bitwise (arithmetic) shift, one bit to the right. Each bit of the Ra register is shifted down by one bit position, the 31st bit is not changed. The least significant bit is copied into the C flag bit. The result is placed in the Rd register.

sha.png

ROL Rd,Ra

Forgatás egy bittel balra, a C jelzőbiten keresztül. Az Ra regiszter tartalmának minden bitje egy helyi értékkel balra lép. A legfelső helyi értékű bit a C jelzőbitbe kerül, aminek az eredeti értéke lép be a legalsó helyi értékre. Az eredmény az Rd regiszterbe kerül. Rotate one bit to the left, via flag bit C. Each bit in the contents of register Ra is shifted to the left by one bit position. The highest significant bit is placed in flag bit C, whose original value is placed in the lowest bit position. The result is placed in register Rd.

rol.png

ROR Rd,Ra

Forgatás egy bittel jobbra, a C jelzőbiten keresztül. Az Ra regiszter talmának minden bitje egy helyi értékkel jobbra lép. A legalsó helyi értékű bit a C jelzőbitbe kerül, aminek az eredeti értéke lép be a legfelső helyi értékre. Az eredmény az Rd regiszterbe kerül. Rotate one bit to the right, via flag bit C. Each bit in the register Ra is shifted to the right by one bit position. The least significant bit is placed in flag bit C, whose original value is placed in the highest bit position. The result is placed in register Rd.

ror.png

MUL Rd,Ra,Rb

32 bites adatok szorzása. A 64 bites eredmény alsó 32 bitjét számolja ki. Multiply 32-bit data. Calculates the lower 32 bits of the 64-bit result.

CMP Rd,Ra,Rb

Összehasonlítás. A művelet a SUB utasítással egyezik, de az eredmény nem íródik be az Rd regiszterbe, csak a jelzőbitek tárolódnak el. Comparison. The operation is the same as the SUB instruction, but the result is not written to the Rd register, only the flag bits are modified.

SETC

A C jelzőbit 1-be állítása. Set flag bit C to 1.

CLRC

A C jelzőbit 0-ba állítása. Setting flag bit C to 0.

Diagnosztika Diagnostics

A processzor működése nyomon követhető a teszt kimeneteken megjelenő jelek megfigyelésével. The operation of the processor can be monitored by observing the signals appearing on the test outputs.

CLKstat

A CLKstat kimenetek az egymás utáni fázisok sorszámát adják bináris kódban. The CLKstat outputs provide the sequential phase numbers in binary code.

TREG

A TREG kimeneteken a 16 regiszter egyikének értéke nyerhető ki, a regiszter sorszámát a TRS bemenetekre kell kapcsolni, 4 bites bináris kódban. The value of one of the 16 registers can be obtained at the TREG outputs, the register number must be connected to the TRS inputs, in 4-bit binary code.

TR

A TR kivezetéseken a processzor valamely belső adatát lehet megjeleníteni, a megfelelő adatot a TRS bementekre adott 4 bites bináris kóddal lehet kiválasztani. Some internal data of the processor can be displayed on the TR pins, the corresponding data can be selected with a 4-bit binary code given to the TRS inputs.

TRS bemenetTRS input TR kimenetTR output
0 R15 (PC) értéke value of R15 (PC)
1 R14 (LR) értéke value of R14 (LR)
2 R13 regiszter értéke (általában SP) value of R13 (usually SP)
4 IC (utasítás regiszter) értéke value IC (instruction register)
5 ALU kimenete output of the ALU
6 Utasítás eredménye Result of the instruction
7 Visszaírásnál használt adat Write-back data
8 ENA (utasítás feltétel értéke), Rd, Ra, Rb regiszterek sorszámai ENA (instruction condition value), Rd, Ra, Rb register numbers
9 Az Rd regiszter értéke Value of the Rd register
10 (A) Az Ra regiszter értéke Value of the Ra register
11 (B) Az Rb regiszter értéke Value of the Rb register
12 (C) Az ütemező kimenő vezérlő jelei Output control signals of the scheduler
13 (D) MA (memória illesztő cím kimenete) MA (memory interafce address output)
14 (E) MDO (memória illesztő adat kimenete) MDO (memory interface data output)
15 (F) MDI (memória illesztő adat bemenete) MDI (memory interface data input)