










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!











R8 PROCESSOR – ARCHITECTURE AND ORGANIZATION SPECIFICATION
AND DESIGN GUIDELINES
Fernando G. Moraes & Ney L. V. Calazans
1 HISTORY
The R8 processor research effort is an initiative of the Hardware Design Support Group (GAPH). GAPH
is a research group at the Computer Science Graduate Program (PPGCC), in the Faculty of Computer Science
(FACIN), part of the Pontifical Catholic University of Rio Grande do Sul (PUCRS), located in Porto Alegre,
capital of Rio Grande do Sul state, in Brazil.
In the start of 1997, a major revision of the then 13-year old Computer Science undergraduate curriculum
started to be applied. The new curriculum significantly enhanced the hardware contents taught with regard to the
previous one. Also, the hardware courses track in the curriculum was designed to expose students very early to
hardware design using mostly professional tools. The reasoning to do so is exposed in detail in [1]. The basic idea
is to propose a processor implementation as practical work to be developed along several semesters. First, the
students have to produce a processor description from a detailed specification, implementing it in a hardware
description language (currently, VHDL). Validation of their design is achieved by functional simulation. This
happens in the third semester of the curriculum. A following course requires the students to start from their
previous semester design and transform their implementation into a pipelined processor with the same architecture
(register bank, instruction set, etc.). In a subsequent course, input-output capabilities and memory hierarchy
considerations are added to the same design.
Every semester, a different processor specification is prepared. Specifications differ from one another in
some aspects, the main ones being the requirement of unified memory or Harvard organization and obviously
instruction set. However, all processors share common characteristics of being load-store, 16-bit RISC-like
architectures, with a bank of 16 16-bit registers, and the instruction word length being fixed at 16 bits. These
characteristics define the Rx clan. The first of these specifications was the R1 processor, proposed to the first class
of students taking the Computer Organization course of the new curriculum, in the first semester of 1998. The R
has been the eighth of these processors, and the R12 specification is currently under preparation.
Each new specification gives rise in fact to several processor implementations, and variations on the
specification define a family of processors. The R8 family occupies a special position in the Rx clan, since it has
been used in various research works outside the scope of undergraduate courses. Today, hardware
implementations of the R8 basic architecture are available, and various implementations are validated at several
abstraction levels. Up to four instances of the R8 processor have been implemented on FPGA-based prototyping
boards, providing a multiprocessing platform to the research work on system-on-chip (SoC) and network-on-chip
(NoC) subject areas.
This document is based on the original R8 specification handled to the students and is intended as the
basis for formalizing the R8 family, providing a “gold” specification for its very first member, named simply R8.
The definition of design methods and tools to support the R8 architecture must rely upon this specification,
including the assembler and simulator tools, the C compiler and the embedded operating system kernel for the R
processor. Also, it is expected that from this other specifications may branch to define other members of this
processor family.
The rest of this document is organized as follows. Sections 2 to 4 present the basic Instruction Set
Architecture (ISA) of the R8 processor. Next, Sections 5 to 10 detail a possible organization for the
implementation of the R8 processor ISA. Section 11 give some hints on how to use the R8 processor software
development environment available today, while Section 12 provide references to other documents.
2 GENERAL CHARACTERISTICS
the memory access instructions execute either the reading from (load) or the writing to (store) one memory
position.
manipulation general-purpose registers, to reduce the number of memory accesses (this always represents a
time penalty with regard to the processor internal operation). This characteristic differs from an accumulator
based architecture, which keeps all data in memory, performing logic and arithmetic instructions among
contents in memory and contents of one or a few special registers, named accumulators. Consider, for
example the following C language line: for(i=0; i<1000; i++). Here, in case ' i ' is stored in memory,
2,000 memory access operations are needed to execute this line, performing read and write operations at each
iteration. In case ' i ' is first read and stored in a register, just register operations are needed, without using
memory most of the time during the for command execution!
The instruction contains the operation code and the operands specification, in case they exist.
Thus, the R8 processor is a RISC-like machine, but still missing some characteristics so common in most
RISC processors, such as pipelines. The main specific organizational characteristics of this multi-cycle processor
are:
position containing 16 bits of information).
program executed is always a number between 2 and 4.
3 INSTRUCTION SET
The very simple instruction set defines the following instruction classes:
space reservation).
register addressing.
processor.
4 ARCHITECTURE REGISTERS
The processor contains the following control and data storage registers:
operands.
executed.
subroutines. The SP must be initialized by each program intending to use subroutines with the LDSP instruction, which loads a value in SP that represents the primary top of the stack for the program.
formed by these registers has a write port and two read ports. This means that it is possible to write in some
register while at the same time two data are read from other registers in the bank. The outputs of the register bank are the output busses SOURCE1 (S1) and SOURCE2 (S2).
arithmetic and memory instructions. These flags are used to store information to be tested by conditional jump instructions and conditional calls to subroutines. The flags state is determined by logic, arithmetic and memory read operations (loads).
Other registers may be necessary to implement the organization. Examples appear in Section 6 of this
document, where a suggestion of organization is advanced.
5 RELATIONSHIP BETWEEN PROCESSOR AND EXTERNAL MEMORY
Figure 1a illustrates the relationship between the R8 processor and its external memory. The processor
receives two signals from the external world: clock , intended to synchronize the internal events of the processor
hardware; and reset , which puts the processor in a starting state, able to begin instruction execution by fetching
instructions from the first address of the external memory, namely address 0000h.
The R8 control unit generates microinstructions (μinst) to execute instructions in a clock cycle by clock
cycle basis. Each microinstruction is responsible for commanding the actions executed by the datapath, such as
register access selection, ALU operation and/or external memory access to fetch data or instructions.
After an instruction fetch, the datapath informs to the control unit the code of the current instruction
under execution (the content of the IR register) and the values of the status flags ( flags ). The datapath is also
responsible for the communication with the external memory. The signals employed for the exchange of
information between the R8 processor and the external memory are: data (a 16-bit bidirectional bus transporting
data and instructions) and address (a 16-bit bidirectional bus containing a memory addresses to access).
The memory access control is performed by the control unit through signal ce and rw. The signal ce
indicates, when its value is 1, that an operation of information transfer is occurring between the processor and the
memory, while signal rw indicates if this operation is a reading ( rw=1 ) or writing ( rw=0 ) operation.
It is important to note that the datapath and the control unit work at distinct edges of the clock signal. In
one clock edge (e.g., the rising edge) the control unit generates a microinstruction, and in the next edge (in this
case at the falling edge) the datapath executes the microinstruction, by modifying its registers. With this schema
the control and data information will be sampled when they are effectively stable, for a sufficiently low clock
frequency.
ce
rw
clock reset
entity processor is port( ck,rst: in std_logic; data: inout reg16; address: out reg16; ce,rw: out std_logic ); end processor;
architecture processor of processor is signal flag: reg4; signal uins: microinstruction; signal ir: reg16; begin
dp: datapath port map( uins=>uins, ck=>ck, rst=>rst, instruction=>ir, address=>address, data=>data, flag=>flag);
ctrl: control_unit port map(uins=>uins, ck=>ck, rst=>rst, flag=>flag, ir=>ir); ce <= uins.ce; rw <= uins.rw; end processor;
4
address
6.4 Instruction Execution Cycle
6.4.1 Arithmetic, logic and immediate addressing instruction execution
arithmetic instructions.
lnz lcv
ALU
RAM
address
R_S
R_S
R_T
+1 outalu
general purpose register bank
alu
n z c v
n',z',c',v'
4
n d
st
rd
result of a given operation between the destination register itself and an 8-bit constant. The immediate addressing mode instructions are:
constant byte in the upper byte, maintaining the lower byte unchanged).
constant byte in the lower byte, maintaining the upper byte unchanged).
completing with 0s the 8 more significant bits of the constant to generate a 16-bit register.
LDL must be used in sequence. To read or write some data stored in a given 16-bit memory address 3 assembly language instructions are necessary: the first 2 to load the high and low parts of the address into
a register (LDH and LDL, respectively) and a third instruction to execute the reading from or writing to
memory (LD or ST). An example is given below:
6.4.2 Memory read instruction execution (LD)
memory address given by the result of the sum of the two source registers ( sources ): Rt fl MEMP(Rs1 +
Rs2). One of the sources can be used as a base register, while the other is used as a displacement from that
base address ( offset ).
ALU
alu
RAM
R_S
R_S
R_T
outalu RALU
+1 16 x 16 bits general purpose register bank
End of the 2 nd clock cycle
Address computed at the end of the 3rd^ cycle / reading at the 4th^ cycle
PC reg address
End of the 4th^ clock cycle mux to select origin of the external memory address
IR reg
End of the 1 st clock cycle End of the 3 rd clock cycle
6.4.3 Memory write instruction execution (ST)
contents of the destination register ( target ): MEMP(Rs1 + Rs2) fl Rt.
ALU
alu
RAM
R_S
R_S
R_T
outalu
general purpose register bank
st
nd
rd
th
t h
ce rw
6.4.4 Conditional and unconditional jump instructions
stored in the RALU register.
clock cycle.
register, at the same time storing the previous PC contents on the top of the stack. Remember that the PC
has been incremented in the fetch clock cycle (the first of the instruction), and this is the value stacked. After storing this value on the stack, the SP register is decremented, i.e.:
ALU
RAM
PC reg
0
1
2
address
0
1
2
SP reg
dtPC
DATA
ce rw
1
0
opA
opB
outalu RALU
0
1
2
Decrements SP at the end of the 4
th cycle
PMEM(SP) fl PC
Puts PC contents on data
STORES A NEW VALUE ON THE PC REGISTER (subroutine starting address)
6.4.6 Return from subroutine and pop instructions (top of stack data retrieval)
RALU register (with SP+1), storing the result of the memory reading either in the PC register (RTS) or in
the register bank destination register (POP). The SP register is updated (SP flSP+1).
7 DATAPATH ORGANIZATION
Aggregating the different previous figures, it is possible to obtain a complete R8 datapath that allows to
implement all instructions defined for this architecture. This is depicted in
Figure 11. Some additional elements were added for controlling subroutines cal and return, due to the
need of manipulating the SP register. The datapath sends to the control unit the output of the IR register as well as
the contents of the status flags.
The datapath needs to receive 18 control signals from the control unit, organized into 4 signal classes:
which register addresses the external memory), mreg (register bank data origin), ms2 (selects which portion of
the IR register selects the second ALU operand), ma (ALU first operand data origin), mb (ALU second
operand data origin).
Figure 12 illustrates the register bank organization, as a block diagram. It should be observed that the
multiplexer responsible for the selection of the second source register (S2) is inside the register bank block.
16 x 16 bits general purpose
ms2 wreg
RAM memory (external to the processor)
ce rw
wPC
PC reg
mpc
0
1
2
address
mad
0
1
2
wSP
SP reg
msp
0
1
wIR
IR reg
dtPC
dtSP
DATA
wAB
wAB
ce rw
R_S
R_S
R_T
ma
1
0
opA
opB
outalu
walu
mreg
dtReg
1 0
alu
n z c v
n',z',c',v'
4 lnz lcv
flags
mb
0
1
2
I=ST (in the 4 th clock cycle store in memory the target register contents)
1
0
8 CLOCK CYCLES NEEDED TO EXECUTE INSTRUCTIONS
Given the R8 processor datapath organization description presented in the previous Section, it is possible
to summarize the execution time for all instruction in terms of number of clock cycles to execute each instruction.
This is shown in Table 1 below.
Reset (All registers are cleared)
Default c ondition, that occurs in unconditional jumps with flag=0 or in the NOP operation
wREG
LA1 or LA
wIR wPC RAMread
wREG RAMread
RAMwrite
wPC
jump
wPC wSP RAMwrite
subroutine
wSP RAMwrite
wPC wSP RAMread
wREG wSP RAMread
wSP
wALU wnz,wcv*
9.1 Instruction decoding / ALU operation definition
The first action performed by the R8 Control Unit after instruction fetch is instruction decoding.
enumerated type containing all possible instruction mnemonics. Originally the R8 processor contains 40 instructions. However, it is possible to group some of these, e.g. the jump instructions, which may be grouped
in three distinct classes: relative jumps (Rjump), absolute jumps (jump) and displacement jumps (Djump).
Instruction mnemonic count can then be reduced to 28 instruction classes.
relative jumps are now referred by a single mnemonics “Rjump”, 5 absolute jumps become "jump" and the 5 jumps with short displacement become "Djump". This simplification tends to reduce the HDL code size to be
written.
9.2 Multiplexers control
Figure 11. The control signals are preceded below by the " uins. " suffix that designates the
microinstruction that passes from the control unit to the datapath.
state). The second source operand address (source2) receives the address of the destination register when
executing type 3 logic or arithmetic instructions or a memory write.
In short, three main parts compose the control unit:
Instruction decoding.
Multiplexers control generation.
Control finite state machine, to generate control signals for register load enabling, reading from and writing to
memory.
11 EXAMPLE PROGRAM TO TEST ALL INSTRUCTIONS
The object code below corresponds to an example text file that is read by the VHDL simulation test bench
during simulation of the R8 processor. It is associated with the corresponding assembler code in the comments
part (after the “;” symbol). The file contains n lines, each with 9 characters in the “xxxx yyyy” format, where
xxxx is a 16-bit address (4 hexadecimal digits) and yyyy is a 16-bit instruction (4 hexadecimal digits). This text
file is loaded in memory by the test bench during reset activation, typically at the start of the processor simulation.
0006 0412 ; sum: result in R4: 223C 0007 1512 ; subtrai: result in R5: FDD 0008 2612 ; and: result in R6: 1000 0009 3712 ; or: result in R7: 123C 000A 4812 ; xor: result in R8: 023C 000B 5101 ; immediate sum 01 to R1 - 1009 000C 510F ; immediate sum 0F to R1 - 1018 000D 51FF ; immediate sum FF to R1 - 1117 (1130ns) 000E 6201 ; immediate subtract 01 from R2 - 1233 000F 6204 ; immediate subtract 04 from R2 - 122F 0010 62FF ; immediate subtract FF from R2 - 1130 0011 7DFF 0012 8D01 ; LOAD RD, #01FF 0013 B0D7 ; load the stack pointer with the contents of register 14 (511 in decimal) (1610ns) 0014 7100 0015 8101 ; R1 <- 0100 0016 C01B ; ********* jump to subroutine pointed by R1 (address 0100) ********* 0017 B005 ; nop 0018 70FF 0019 80FF ; R0 < - FFFF / sets the negative flag 001A 50FF ; R0 < - R0 + FF / sets the overflow flag 001B 4000 ; RO < - R0 xor RO / seta the zero flag 001C 7730 ; 001D 8700 ; R7 < - 0030 001E C077 ; jumps to the address pointed by R7 (30H) if zero flag set
0030 7710 0031 8700 0032 C070 ; inconditional relative jump to address 33H+10H=43H
0043 D050 ; jump to address 44H+50H=94H
**0094 B006 ; ************* HALT HALT *******^ occurs at 4800 ns simulation time^ ********************
0100 B10A ; SUBROUTINE THAT TESTS PUSHING AND POPPING REGISTERS TO/FROM the STACK 0101 B20A 0102 B30A 0103 B40A ; push registers 1 to 4 0104 7109 0105 8100 0106 C01A ; when here, call another subroutine u sing PC-relative addressing mode (110H-107H=09H) 0107 B 0108 B 0109 B 010A B109 ; retrieve registers 1 to 4 from the stack 010B B008 ; ****** rts ***************** (4000ns simulation time)
**0110 4111 ; SUBROUTINE THAT employs xor instruction to clear registers 1 to 4 - 2490ns 0111 4222 0112 4333 0113 4444 ; simulation time: 2730ns 0114 F013 ; subrotine PC-relative, jump over 13 words, going to address 0128 0115 B008 ; ****** rts *******************
**0128 7190 ; S UBROUTINE THAT TESTS LOAD AND STORE INSTRUCTIONS 0129 8101 ; r1 < - 0190 (400 in decimal) 012A 73AA 012B 83BB ; R3 < - BBAA 012C AD01 ; stores the contents of register 14 at the addresss contained in register 1 (190H or 400) 012D 9F10 ; read s contents of address contained in register 1, storing it in register 15 (3250ns) 012E B 012F B 0130 B 0131 B221 ; tests sl0 and sl1 instructions - R2 after this must contain BAA 0132 B 0133 B 0134 B 0135 B443 ; tests sr0 a nd sr1 instructions - R4 after this must contain CBAA - simulation time: 4000ns 0136 B104 ; not - R1 after this must contain FFFF 0137 B008 ; ****** rts *******************
It is recommended that R8 users write assembly code programs for their application , generating
automatically the object code using the assembler/simulator combination. The assembler/simulation tool, as well
as some more detailed documentation on how to use it is available together with the processor specification and
implementation files. Figure 15 shows the Graphical User Interface (GUI) main window of the R
assembler/simulator. To the left of the Figure appears the Memory Table, containing in each line one assembly
instruction, the memory address chosen by the assembler where to locate this instruction and the associated object
code actually store at this position. In the center of the Figure is located the Symbol Table for the source code
program. For each label appearing in the program, regardless if this refers to data or program information, the
associated memory address and the value of the label are associated in this table. To the right of Figure 15 are
located the Register Table, which displays the contents of each general purpose register (from R0 to R15), and of
each of the main control registers, IR, PC and SP. In the lower part of the window are located the control buttons
Step , Run , Pause , Stop and Reset , as well as the simulation speed control buttons Slow , Normal and Fast. The
values of the qualifiers are displayed in the rightmost inferior part of the window, using check boxes, where a
checked box is associated with a value 1 for the corresponding flag.
The assembly tool accepts as input a text file written in the R8 assembly language. Given a file named
data contents in a hexadecimal format useful for downloading program and data to one of the prototyping
boards for which R8 is available as an embedded processor;
format, adequate for use as input to a test bench running within a VHDL simulator (we have already used Aldec Active-HDL and Mentor Modelsim simulators). This format is illustrated above in Section 11.
The R8 assembler is mostly invisible to the user, since it is automatically called by the simulator interface
when a file with .asm extension is read from disk. The above mentioned 3 output files are generated at the time of