PH415 Computer Interfacing 2013
OSU logo
Low-Level Control: Assembly and C

Table of Contents

Introduction

In our exploration of the microcontroller, we will be using the Digilent Chipkit MAX32 as our test platform. This microcontroller utilizes the PIC32 for execution. The architecture of the PIC32 microcontroller is designed to execute machine code assembled opCode written in the format of the 3-operand MIPS32{4k} Assembly Language (ASM).

This task will develop a conceptual understanding of the microController's hardware, and an introduction to the execution of machine codes on an electronic device, such as our microcontroller. We will begin where all embedded programmers begin, namely blinking lights! An opCode will be written in ASM to blink a light on our MAX32 board. This will then be compared with the next level of abstraction, called {embedded} C. C is the most widely used programming language in the world, and nearly any processor can utilize C. We will be doing low-level register manipulation in C. Then, a high level of abstraction will be observed, namely Arduino-style libraries written in C++. C++ is nearly a super-set of C, but is not complete. An investigation into the trade-offs of different layers of abstraction will be explored in this task. In one sentence, the flow of this task will be:

Explore Blinking light program in: machine code -> opCode (in ASM) -> low-level C -> C++/Arduino

Investigating Assembly Language

  • Download the sample ASM code
  • Listen attentively to overview of the given ASM code
  • Upload code using MPIDE and verify code is executing as expected using an oscilloscope
  • Capture signal on scope, including frequency and peak to peak potential

C - A Layer of Abstraction

The C programming language is a higher level language that still allows access to low level hardware. High level programming languages have higher levels of abstraction. This means that many of the fine details on how a processor works are hidden from the programmer. This allows the user to ignore some of the complexities of how a processor works and focus on writing code for what they want the processor to do. The code is then passed to a compiler to get it ready to be loaded on to the micrcontroller.

A compiler is a program converts one programming language to another. In this case the compiler will parse through the c code and convert it to machine code. This is necessary because the microcontroller only understands machine code. The c language is merely a tool to aid someone in developing software for a specific device.

Take a look at this C/C++ Tutorial. Look over the sections Basics of C++, Control Structures, and Arrays under Compound Data Types. Anything regarding namespaces or input/output can be ignored as they are not used when programming the microcontroller.

Task

  • Write A C implementation of the blink code investigated above using {TRIS*, LAT*SET, LAT*CLR, LAT*INV, PORT*}
  • Observe and record (screen capture on oscilloscope) the fastest possible frequency and the peak-to-peak potential at this frequency.
  • Notice anything different about this signal compared to the ASM output? Compare the two and look over this disassembly of the C code in order to find the discontinuity.
  • Make a human-scale blinking led program.

Goal

  • Understand qualitatively what assembly code represents in terms of machine code, instructions, and operands. Write a general description of what an assembly instruction represents in terms of an ALU instruction and registers, using a line from the provided ASM code as an example.
  • Provide a copy of your own C code with commenting on each line, describing what the program is doing.
  • Write a short paragraph (electronic or otherwise) talking about why ASM or C would be preferred for a particular program. What are the benefits of ASM, C?