Electronic – Understanding word and instruction on simple microcontroller

microcontrollerpic

From what I'm reading in this CircuitBread tutorial, the microcontroller PIC10F200 has flash memory of 256 words. PIC10F200 has a constant word unit of 12bits and so the maximum program size I can flash into the memory is 256 words * 12 bits = 3072 bits or 384 bytes. But still, I can't see how the word "word size" or "bytes size" indicate how much I can write into the flash, or how many cycles it takes to run.

  1. Program size: If PIC10F200 has fix 12-bit words size (also the tutorial mentioned each instruction is one word in size). Should I count each assembly operation (or an opcode) as an instruction (i.e. GOTO as one instruction, MOVLW as another instruction)? If I have an assembly program consisted of two MOVLW and one GOTO (assuming labels are not instructions and occupies no flash), then I would have 3 word/instruction * 12 bits = 36bits or 4.5 bytes. But that's not the case and I was wrong. How can I count for myself the quantity of words or instructions I wrote in my assembly other than being just told to by the IDE?

  2. Time to process an instruction: My understanding is that different manufacturers of MCU may have their instructions each takes a varying multiples of word. So if an instruction for a particular MCU's instruction occupies 128bits on flash on a machine of 32bits word size, does that mean it'll take the MCU 4 cycles to complete this specific instruction?

I googled and looked into stackoverflow but am confused with different architectures and abstraction which doesn't help. I want to check my understanding and be able to roughly calculate and time my program and understand why.

Best Answer

  1. Each instruction or opcode is a single 12-bit word. So each line of assembly that has an instruction is one word and it includes the parameters. Instructions don't use multiple words. GOTO is one word, MOVLW is one word. You have 256 words code memory.

  2. It says right on the first datasheet page that all instructions take one cycle except for branch instructions which take two cycles. It's just that one instruction cycle takes 4 clock cycles, so at 4 MHz clock your single cycle instructins take 1 microsecond each, or in other words, executes at 1 MIPS. This PIC has one word per instruction and it can take 1 or 2 cycles. Any other architecture can execute stuff differently.