Skip to main content

Microcontrollers

Section 3.3 Program

Using the defined machine instructions, each instruction can be used in software to create a program for the microcontroller to execute. A very simple program including a list of individual instructions is defined below. Then, the program will be written in machine code, assembly language, and register transfer language.
  1. Input data from the switches into register A
  2. Input data from the dial into register B
  3. Output the contents of register A to the LCD screen
  4. Output the contents of register B to the LEDs
  5. Add the contents of both registers, and store the result in register A
  6. Output the contents of register A to the 16-segment display
The binary numbers in the machine code are what’s actually saved to the microcontroller memory. Based on the sample program defined above, the corresponding machine instructions are represented below in binary:
0000 0100
0000 1101
0001 0010
0001 0100
0011 0100
0001 0011
Using hexadecimal makes the list of instructions somewhat less unwieldy. The same machine instructions are represented below in HEX:
0x04
0x0D
0x12
0x14
0x34
0x13
Based on the sample program defined above, the corresponding assembly code is:
IN A, switches
IN B, dial
OUT LCD, A
OUT LEDs, B
ADD A, B
OUT 16seg, A
The same program expressed with register-transfer language is:
A ← I/O(switches)
B ← I/O(dial)
I/O(LCD) ← A
I/O(LEDs) ← B
A ← A + B
I/O(16seg) ← A