# Understanding word and instruction on simple microcontroller

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.

• Don't try and convert the word size for each instruction into bytes. The instruction memory is read a full word at a time. It's not organized as bytes. The decision to organize memory along byte size was made by IBM around 1964, or so, and it's just a "decision." Many computers before and after (PDP-10 used 36 bit words, for example) have used varying widths. Just don't fret it. Meanwhile, every instruction takes a word. Period. Some take more cycles than 1. But they all occupy one word. Data memory is different, though. Just FYI. See Figure 3.1 for the architecture. It's almost all there.
– jonk
Jul 5, 2020 at 1:12
• but this value doesn’t tell us anything - we want to know how many instructions we can write, and from this perspective, knowing how many words you have is much more informative. Jul 5, 2020 at 1:55

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.

• I think that really help clear the terminologies that has been confusing me here. So GOTO or MOVLW is a command (opcode) and if with or without a parameter (operand) occupies one "word" magnitude of bits in the flash. This line of code is called an assembly line or simply an "instruction" in literal sense which does one thing in one chunk of word. I falsely imagine instruction is another unit of bits like a word (as in bytes vs. bits) and instruction cycle is another obscure abstraction of time longer than the clock. Now looking back to my question it now make little sense. Thank!
– KMC
Jul 5, 2020 at 4:33

Word width is fixed. It is 256 words of 12 bits each. You cannot convert this to bytes as it is not on byte-sized boundaries.

Instruction cycles on most all MPU's and CPU's is 1/4 the clock rate. If clock is 4 MHZ then it can spew out instructions at a 1 MHZ rate. Note that more complex MPU's have multiple clock sources and also sleep-modes where another slower clock is used. In some sleep modes the MPU core may be shut down.

Note that some ops require extended clock cycles to complete, so as Dave Tweed mentions in his answer read the datasheet in detail.

Read the datasheet. Section 10 gives the details of the instruction set, including how many words of storage (in this case, exactly one) and how many clock cycles (one or two) each one requires.

There's really no reason to talk about bytes of program storage, because the program storage isn't byte-addressable anyway. Just know that you can write 256 instructions before you run out of storage.