Размещаю здесь для обсуждения системы команд 4-битных самодельных ЦПУ, популярных в сети.
Первая - от восьмиразрядного, но автор использовал только старший ниббл.
Titan - The 8 bit TTL Processor
http://marc.cleave.me.uk/cpu/index.htm
Code: Select all
Registers:
0000 Z(Hardwired zero)
0001 Accumulator
0010 B register
0011 C register
0100 D register
0101 E register
0110 F register
0111 G register
1000 H register
1001 I register
1010 J register
1011 K register
1100 L register
1101 M register
1110 N register
1111 O register
Code: Select all
Binary Hex Mnenomic Operation Excuted
0000 0000 0x00 NOP No operation
0001 0000 0x10 ADD Sum of the A and B registers
0010 0000 0x20 SUB The subtraction of the B register from the A register
0011 0000 0x30 AND Logical AND of the A and B registers
0100 0000 0x10 OR Logical OR of the A and B registers
0101 0000 0x50 NOT Logical NOT of the A register
0110 0000 0x60 XOR Logical XOR of the A and B registers
0111 XXXX 0x70 PSH Pushes the selected register onto the stack
1000 XXXX 0x80 POP Pops the top of the stack into the selected register
1001 0000 0x90 JMP Jumps to address
1010 0000 0xA0 JPI Indirect jump, point to a location in memory and jumps
to the value stored in the address
1011 0000 0xB0 JPZ Jumps if the zero flag is set
1100 0000 0xC0 JPC Jumps if the carry flag is set
1101 0000 0xD0 JPS Jumps if the sign flag is set
1110 0000 0xE0 STM Writes accumulator register to memory address
1111 0000 0xF0 LDM Loads memory address to accumulator
http://www.vttoth.com/vicproc.htm
Code: Select all
Characteristics of 4-bit experimental processor:
Data bus 4 bits
Address bus 8 bits
Memory 256 4-bit word
Accumulator 8 bits
Program counter 8 bits
Data address register (internal) 8 bits
Instruction register (internal) 4 bits
Flags Carry, Zero, Data (external I/O)
Instruction set 16 variable length instructions
Code: Select all
Opcode Mnem. Size Description
0 HLT 1 Halts the processor. Can be restarted manually by pressing a button.
1 LDA nn 3 Load 8-bit value from address nn into AC
2 STA nn 3 Store AC at address nn.
3 JMP nn 3 Continue execution at (i.e., set PC to) address nn.
4 SPC nn 3 Store current PC value at address nn.
5 AND nn 3 Compute logical AND of AC and nn, store result in AC. Set Z flag as
appropriate.
6 OR nn 3 Compute logical OR of AC and nn, store result in AC. Set Z flag as
appropriate.
7 ADD nn 3 Compute arithmetic sum of AC and nn, store result in AC. Set C and Z
flags as appropriate.
8 SUB nn 3 Subtract nn from AC, store result in AC. Set C and Z flags as
appropriate.
9 JNZ nn 3 Jump conditional; execute JMP nn if Z flag is not set.
A CMP nn 3 Subtract nn from AC, discard result. Set C and Z flags as appropriate.
B JND nn 3 Jump conditional; execute JMP nn if D flag is not set.
C JNC nn 3 Jump conditional; execute JMP nn if C flag is not set.
D ROL 1 Rotate AC left. Move C to least significant bit of AC. Move most
significant bit to C.
E ROR 1 Rotate AC right. Move C to most significant bit of AC. Move least
significant bit to C.
F CLF 1 Clear flags C, D, and Z.
http://www.galacticelectronics.com/Simple4BitCPU.HTML
Below is a summary of the available instructions:
Code: Select all
Code Mnem. Description
1 LIT Copy a literal value from program memory to the accumulator.
2 LOAD Copy a value from a register to the accumulator.
3 STORE Copy the value in the accumulator to a register.
4 INC Increment the accumulator by one.
5 DEC Decrement the accumulator by one.
6 REG Copy the value in the accumulator to the register address latch.
7 CMPL Compare the accumulator to a literal value. Sets flags.
8 CMPR Compare the accumulator to a register. Sets flags.
9 RST Resets the program counter.
10 JUMPL Copy the value in the accumulator to the segment register when the less
than flag is set.
11 JUMPE Copy the value in the accumulator to the segment register when the
equal flag is set.
12 JUMPG Copy the value in the accumulator to the segment register when the
greater than flag is set.
13 IN Copy the value from the input to the accumulator.
14 OUT Copy the value in the accumulator to the output latch.
15 NOP No operation.
Gakken GMC-4
http://www.jambell.com/GMC-4/
The GMC-4 understands about 30 instructions. Of these, 15 are accessed using a single hex value and the remainder are accessed by prefixing a hex value with hex E (i.e. E0 - EF)
Program code table:
Code: Select all
Code Mnem. Action Result Flag Detail
0 KA K->Ar 0, 1 The pressed key from the hex keypad is saved to the A register. If a
key is not pressed, the Flag is set to 1, otherwise it is 0.
1 AO Ar->Op 1 The 7-segment readout displays the value currently contained in the
A register.
2 CH Ar<=>Br
Yr<=>Zr 1 Exchange the contents of the A and B registers, and the Y and
Z registers.
3 CY Ar<=>Yr 1 Exchange the contents of the A and Y registers.
4 AM Ar->M 1 Write the contents of the A register to data memory (memory address
is 50 + Y register).
5 MA M->Ar 1 Write the contents of data memory (50 + Y register) to the A
register.
6 M+ M+Ar->Ar 0, 1 Add the contents of data memory (50 + Y register) to the A
register. If there is overflow, the Flag is set to 1, otherwise 0.
7 M- M-Ar->Ar 0, 1 Subtract the contents of data memory (50 + Y register) from
the A register. If the result is negative, the Flag is set to
1, otherwise 0.
8 TIA [ ] [ ] -> Ar 1 Transfer immediate to the A register.
9 AIA [ ] Ar + [ ] -> Ar 0, 1 Add immediate to the A register. If there is overflow, the
Flag is set to 1, otherwise 0.
A TIY [ ] [ ] -> Yr 1 Transfer immediate to the Y register.
B AIY [ ] Yr + [ ] -> Yr 0, 1 Add immediate to the Y register. If there is overflow, the
Flag is set to 1, otherwise 0.
C CIA [ ] Ar != [ ] ? 0, 1 Compare immediate to the A register. If equal, Flag reset to
0, otherwise set to 1.
D CIY [ ] Yr != [ ] ? 0, 1 Compare immediate to the Y register. If equal, Flag reset to
0, otherwise set to 1.
E --- --- --- Extended code. See table below.
F JUMP [ ] [ ] 1 Jump to the immediate address if the Flag is 1, otherwise
just increment the program counter. The Flag is then set to
1. Note that this is an absolute address. That is, JUMP [0]
[2] will change the address pointer to hex address 0x02. You
can jump both forward and backward in program space.
Code: Select all
E0 CAL RSTO 1 Clear the 7-segment readout.
E1 CAL SETR 1 Turn on the 2-pin LED using the Y register (Y register takes the
value of 0-6).
E2 CAL RSTR 1 Turn off the 2-pin LED using the Y register (Y register takes the
value of 0-6).
E3 --- --- Not used.
E4 CAL CMPL 1 Complement the A register (1 <=> 0).
E5 CAL CHNG 1 Swap the A/B/Y/Z registers with A'/B'/Y'/Z'
E6 CAL SIFT 0, 1 Shift the A register right 1 bit. If the starting value is even (bit
0 = 0), set the Flag to 1, otherwise 0.
E7 CAL ENDS 1 Play the End sound.
E8 CAL ERRS 1 Play the Error sound.
E9 CAL SHTS 1 Play a short "pi" sound.
EA CAL LONS 1 Play a longer "pi-" sound.
EB CAL SUND 1 Play a note based on the value of the A register (allowed values are
1 - E).
EC CAL TIMR 1 Pause for the time calculated by (value of A register +1) * 0.1
seconds.
ED CAL DSPR 1 Set the 2-pin LEDs with the value from data memory. The data to
display is as follows: the upper three bits come from memory address
5F (bits 0-2), and the lower four from memory address 5E (bits 0-3).
EE CAL DEM- 1 Subtract the value of the A register from the value in data memory.
The new value is stored in data memory as a decimal. Afterwards, the
Y register is decremented by 1.
EF CAL DEM+ 1 Add the value of the A register to the value in data memory. The new
value is stored in memory as a decimal. If the result is overflow,
data memory will be automatically adjusted. Afterwards, the Y
register is decremented.
http://web.mac.com/teisenmann/iWeb/elit ... ecode.html
Code: Select all
Code Mnem. Description
0000 - EQUAL (number) (number)
If the arguments are equal, then the boolean bit is set to 1; else, it is set to 0.
0001 - UNEQUAL (number) (number)
If the arguments are equal, then the boolean bit is set to 0; else, it is set to 1.
0010 - GREATER (number) (number)
If the first argument is greater than the second argument, then the boolean bit is set to 1; else, it is set to 0.
0011 - GOTO (address) (address)
Skips command execution to the given address.
0100 - WRITE (data) (destination)
Writes data to the given location in RAM.
0111 - INPUT (device input address) (destination)
Outputs the device input address and writes the device input at the given RAM address.
1000 - OUTPUT (data) (data) (device output address)
Writes the data at the given device output address.
1100 - ADD (number) (number) (destination)
Adds the numbers and stores the result in the given RAM address.
1101 - BITON (nybble) (bit address) (destination)
Sets the bit at the address in the nybble to 1, then stores the result in the given RAM address. Note: the digit addresses are ordered from most significant to least significant.
1110 - BITOFF (nybble) (bit address) (destination)
Sets the bit at the address in the nybble to 0, then stores the result in the given RAM address.
1111 - BITGET (nybble) (bit address) (destination)
Retrieves the bit at the address in the nybble, then stores the bit in the given RAM address.
их здесь - приветствуется.