1
Name:
Anonymous
2011-09-22 9:29
/prog/ , I'm working on a RISC instruction set that is more RISC than any RISC out there. I've devised an instruction format, plus fifteen core instructions that should suffice for any programming out there. The instruction format, instruction forms, and instructions can be found here:
http://jsbin.com/ekuwap
Any comments or suggestions?
30
Name:
Anonymous
2011-09-23 9:06
Fact
It takes 12 instructions to load 0x12345678 into the first register.
Process
0. load the value 0x8 into the second register
1. load the value 0x1 into the high half of the lowest byte of the first register
2. load the value 0x2 into the low half of the lowest byte of the first register
3. shift the first register left by the second register (8)
4. load the value 0x3 into the high half of the lowest byte of the first register
5. load the value 0x4 into the low half of the lowest byte of the first register
6. shift the first register left by the second register (8)
7. load the value 0x5 into the high half of the lowest byte of the first register
8. load the value 0x6 into the low half of the lowest byte of the first register
9. shift the first register left by the second register (8)
10. load the value 0x7 into the high half of the lowest byte of the first register
11. load the value 0x8 into the low half of the lowest byte of the first register
Debugging output
[0001000000110000] 0 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[0001000000000011] 10 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[0001000000000100] 12 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[0010110000000001] 1200 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[0001000000000111] 1230 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[0001000000001000] 1234 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[0010110000000001] 123400 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[0001000000001011] 123450 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[0001000000001100] 123456 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[0010110000000001] 12345600 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[0001000000001111] 12345670 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
[0001000000010000] 12345678 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Source code
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#define MEM 67108864
#define BITS 64
#define uw uint64_t
#define sw int64_t
int main() {
uint8_t *mem = calloc(MEM, 1);
uint16_t *memi = (uint16_t *) mem, ins, insd, insa, insb;
uint32_t stat = 0;
uw *reg = calloc(32, BITS / 8), cia = 0, nia;
memi[0] = (4 << 10) | (1 << 5) | (0x8 << 1) | 0;
memi[1] = (4 << 10) | (0 << 5) | (0x1 << 1) | 1;
memi[2] = (4 << 10) | (0 << 5) | (0x2 << 1) | 0;
memi[3] = (11 << 10) | (0 << 5) | 1;
memi[4] = (4 << 10) | (0 << 5) | (0x3 << 1) | 1;
memi[5] = (4 << 10) | (0 << 5) | (0x4 << 1) | 0;
memi[6] = (11 << 10) | (0 << 5) | 1;
memi[7] = (4 << 10) | (0 << 5) | (0x5 << 1) | 1;
memi[8] = (4 << 10) | (0 << 5) | (0x6 << 1) | 0;
memi[9] = (11 << 10) | (0 << 5) | 1;
memi[10] = (4 << 10) | (0 << 5) | (0x7 << 1) | 1;
memi[11] = (4 << 10) | (0 << 5) | (0x8 << 1) | 0;
while (1) {
nia = cia + 1;
ins = memi[cia];
insd = ins & 0x3ff;
insa = insd >> 5;
insb = insd & 0x1f;
switch (ins >> 10) {
case 0: break;
case 1: mem[reg[insa]] = mem[reg[insb]]; break;
case 2: reg[insa] = ((reg[insa] >> 8) << 8) | mem[reg[insb]]; break;
case 3: mem[reg[insa]] = reg[insb]; break;
case 4:
if (insb & 1)
reg[insa] = ((reg[insa] >> 8) << 8) |
(reg[insa] & 0xf) | ((insb >> 1) << 4);
else
reg[insa] = ((reg[insa] >> 4) << 4) |
(insb >> 1);
break;
case 5: reg[insa] = ~reg[insa]; break;
case 6: reg[insa] &= reg[insb]; break;
case 7: reg[insa] |= reg[insb]; break;
case 8: reg[insa] ^= reg[insb]; break;
case 9: reg[insa] += reg[insb]; break;
case 10: reg[insa] -= reg[insb]; break;
case 11: reg[insa] <<= reg[insb]; break;
case 12: reg[insa] >>= reg[insb]; break;
case 13: reg[insa] = (uw) (((sw) (reg[insa])) >> reg[insb]); break;
case 14:
stat = (stat >> 3) << 3;
if (reg[insa] == reg[insb])
stat |= 1;
else if (reg[insa] < reg[insb])
stat |= 2;
else
stat |= 4;
case 15:
if (((insb >> 1) & 7) & (stat & 7))
nia = reg[insa] + ((insb & 1) ? cia : 0);
}
if (ins) {
putchar('[');
putchar(((ins >> 15) & 1) ? '1' : '0');
putchar(((ins >> 14) & 1) ? '1' : '0');
putchar(((ins >> 13) & 1) ? '1' : '0');
putchar(((ins >> 12) & 1) ? '1' : '0');
putchar(((ins >> 11) & 1) ? '1' : '0');
putchar(((ins >> 10) & 1) ? '1' : '0');
putchar(((ins >> 9) & 1) ? '1' : '0');
putchar(((ins >> 8) & 1) ? '1' : '0');
putchar(((ins >> 7) & 1) ? '1' : '0');
putchar(((ins >> 6) & 1) ? '1' : '0');
putchar(((ins >> 5) & 1) ? '1' : '0');
putchar(((ins >> 4) & 1) ? '1' : '0');
putchar(((ins >> 3) & 1) ? '1' : '0');
putchar(((ins >> 2) & 1) ? '1' : '0');
putchar(((ins >> 1) & 1) ? '1' : '0');
putchar((ins & 1) ? '1' : '0');
putchar(']');
{
int i;
for (i = 0; i < 32; i++)
printf(" %lx", reg[i]);
}
putchar('\n');
}
cia = nia;
if (cia > MEM / 2 - 1)
break;
}
free(mem);
free(reg);
return 0;
}