Cpr E 211 Laboratory

Lab 6

Introduction to Assembly Programming for the PowerBox

 

Lecture – Lab Connection

This lab introduces you to the PowerPC assembly language instruction set and the assembly programming environment in CodeWarrior. This lab comes at time when you are seeing assembly language for the first time in lecture.  That is intentional for two reasons. First, seeing assembly code “in action” in the lab will help you move up the learning curve more quickly.  Second, the course keeps moving along, so let’s move with it. If we waited to use PPC assembly language in the lab until you have heard about all of its features in lecture, that would be a couple weeks from now. So, the introduction is a blend of lecture and lab experiences that requires your cooperation to take some of the first steps.

SKIBLE (SKIll-BuiLding Exercise)

This week’s SKIBLE will be led by your lab instructor and take approximately the first 30 minutes of lab.

See the SKIBLE page for this week’s activity.

Purpose

In this lab, you will learn the basics of assembly language for the PowerPC processor.  At the end of this lab, you should be able to:

Prelab

Complete the prelab. This means:

·        Read the lab instructions.

·        Read any reference material cited/linked in the instructions.

·        Answer any questions that are indicated as part of the prelab.

1.      Browse through the list of reference material. You do not need to read everything now. You will be asked to read selected material more carefully. You should, however, take a quick look so that you are familiar with what is in these resources. Note the comments.

2.      From the list of reference material, read the Little Man Computer (LMC) slides. Run the LMC Shockwave demonstration. Notice that the program adds 2 numbers. In the LMC, there is just one “General-Purpose Register,” the so-called Accumulator (A) in the calculator. Up to one operand in an LMC instruction is a register. Thus, the programming model is slightly different than for the PowerPC, which has 32 GPRs. Also, the LMC has special instructions for input and output, whereas the PowerPC does not; it uses memory-mapped I/O so that the load and store instructions also handle input and output.

Compare the LMC program with an equivalent PowerPC program.

LMC Program

Two values are read in, added, and the sum is written out.

Equivalent PowerPC Program

Let R20 = first input value, R21 = second input value, R22 = address of input port, R23 = address of output port; R22, R23 must be initialized to the port addresses.

IN

LWZ R20, 0(R22)

STA 99

STW R20, 99(0) ;not needed

IN

LWZ R21, 0(R22)

ADD 99

ADD R20, R20, R21

OUT

STW R20, 0(R23)

The first value is read into register A, register A is stored into memory location 99, the second value is read into register A, the value in memory location 99 is added to the value in register A, register A is written to the output.

The first value is read into register R20, register R20 is stored into memory location 99, the second value is read into register R21, the value in register R21 is added to the value in register R20, register R20 is written to the output.

3.      Revisit briefly what you did in Lab 1, Section 4 – Assembly Language.

4.      Study the assembly language program Lab6_add.asm, which is the subject of the SKIBLE Getting Started activity. See the SKIBLE page for this week’s activity.

·        Carefully read through the notes on the Lab6_add.asm program.

 

Lab

Complete the following two activities during your lab.

  1. SKIBLE activity – led by the lab instructor
  2. Assembly Language Introduction

Reference Files for the Lab

Filename

Description

Main1.c

C code for lab section

Lab6_add.asm, Lab6Asm1.s

Assembly code for SKIBLE and lab section

PowerPC Assembly Resources

List of reference material for PowerPC assembly

quickrefPPC.html

PowerPC Assembly Language Quick Reference

Lab Evaluation Form

Evaluation checklist for Lab 6