Created
July 21, 2017 01:45
-
-
Save Insood/ca98d5c46a534c994ff99cd1b324cbfc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (mc *microcontroller) run() { | |
instruction := (*mc.memory)[mc.programCounter] | |
fmt.Printf("%X : %X\n", mc.programCounter, instruction) | |
switch instruction { | |
case 0x00: | |
mc.nop() | |
case 0xC3: | |
mc.jmp() | |
case 0x01, 0x11, 0x21, 0x31: | |
mc.lxi() | |
case 0x06, 0x16, 0x26, 0x36, 0x0E, 0x1E, 0x2E, 0x3E: | |
mc.mvi() | |
case 0xCD: | |
mc.call() | |
case 0x0A, 0x1A: | |
mc.ldax() | |
case 0x76: // This need to be above all the other 0x7x instructions | |
// since it's the only one that doesn't follow the MOV pattern | |
mc.halt() | |
case (instruction >> 6) == 0x01: | |
mc.mov() | |
default: | |
err := fmt.Sprintf("[%d] Unknown instruction: %X ", mc.programCounter, instruction) | |
fmt.Println(err) | |
panic(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment