Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Microprogram generator
- * -----------------------
- * This program is used to generate the
- * microprogram data that will be stored
- * on the microprogram ROM of the CPU.
- * You can view the microprogrammed machine
- * as an abstract moore machine. Every state
- * has a specific value for the output and
- * a set of the ordered pairs: (input_value,
- * next_state_val);
- */
- #include <stdio.h>
- #define A 0
- #define B 1
- #define C 2
- typedef struct state {
- int next_state[2];
- int output;
- } state_t;
- int main() {
- // A machine that outputs 1 when
- // number of received 1s is divisible by 3.
- // The abstract machine consists of 3 states:
- // P.S | N.S | OUTPUT | NOTE
- // | X=0 X=1 | |
- // ----|-----------|----------|--------------
- // A | A B | 1 | n mode 3 = 0
- // B | B C | 0 | n mode 3 = 1
- // C | C A | 0 | n mode 3 = 2
- // define the Moore machine:
- state_t machine[3];
- // define the loop counters:
- int i, j;
- // prepare the ROM image:
- FILE *rom = fopen("image.bin", "w");
- // define state A:
- machine[A].next_state[0] = A;
- machine[A].next_state[1] = B;
- machine[A].output = 1;
- // define state B:
- machine[B].next_state[0] = B;
- machine[B].next_state[1] = C;
- machine[B].output = 0;
- // define state C:
- machine[C].next_state[0] = C;
- machine[C].next_state[1] = A;
- machine[C].output = 0;
- // The layout of the ROM will be like this:
- // ADD | N/A | O/P | NS
- // --- | ----- | --- | --
- // State A: 000 | 00000 | 1 | 00
- // 001 | 00000 | 1 | 01
- // State B: 010 | 00000 | 0 | 01
- // 011 | 00000 | 0 | 10
- // State C: 100 | 00000 | 0 | 10
- // 101 | 00000 | 0 | 00
- // NS is connected to the higher two bits of the
- // 3-bit address bus through a clocked latch.
- // The lower bit of the address is directly
- // connected to the input.
- // now generate the microprogram:
- for (i = 0; i < 3; i++) {
- for (j = 0; j < 2; j++) {
- char rombyte = machine[i].next_state[j] |
- (machine[i].output << 2);
- fputc(rombyte, rom);
- }
- }
- // pad 2 extra characters to make it 8-bit:
- fputc(0, rom);
- fputc(0, rom);
- // close the file:
- fclose(rom);
- // done:
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement