Samples & Exercises

Test your knowledge by trying to solve the problems listed below. If you can make it to the end then you are an expert level assembler programmer for the PIC12F508.

Exercise 1: Input & Output

Write a program that turns an LED connected to GP0 on when a switch connected to GP4 is pressed, and off when the switch is released.
View Solution >>

Exercise 2: Simple Loops

Write a program that flashes an LED connected to GP0 while a switch connected to GP4 is pressed. When the switch is released the LED is turned off.
View Solution >>

Exercise 3: Counting Loops

Write a program that flashes an LED connected to GP0 a fixed number of times (for example 3) each time a switch connected to GP4 is pressed. Once the flashes have been performed the program should wait for the switch to be released and pressed again.
View Solution >>

Exercise 4: Conditional Statements

Write a program that implements the three main conditional tests (==, <, >) between a value in a test register (test_value) and a constant. To indicate the results of the tests, setup three LEDs that light up if each test condition is true.
View Solution >>

Exercise 5: Multiplication

Write a sub-routine that multiplies the values stored in two registers arg_a and arg_b, and stores the result into a 16-bit register pair called result_h and result_l.
View Solution >>

Exercise 6: Indirect Memory Addressing

Write a program that implements a simple stack library. The program should have two sub routines called StackPush and StackPop. StackPush takes the value in a register called arg and stores it onto the stack. If successful it returns 1 in the Working Register otherwise 0 to indicate that the stack is full. StackPop takes a value off the stack and copies it into arg. If successful it returns 1 in the Working Register otherwise 0 to indicate that the stack is empty.
View Solution >>

Exercise 7: Advanced 1

Write a program that implements an 8-bit linear feedback shift register for generating psuedo random numbers. The resulting program should have a display register that cycles through the generated number sequence.
View Solution >>

Exercise 8: Advanced 2

Write a sub-routine that returns (in the Working Register) the square of a number between 0 and 15. The value to square should also be passed to the sub-routine using the Working Register. Your solution should require only 18 lines of code or less.
View Solution >>