Download Programming in Assembly

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
15-348 Embedded Systems
Spring 2016
Assignment 2
This is a written and programming homework. You should either type or write your
answers and submit during recitation on Thursday February 4. You should also demo
your code at that time and submit all .asm files zipped as a single file on autolab.
Part A:
Goal: To familiarize yourself with the microcontroller assembly instructions and the
process of assembly.
Discussion: This lab focuses on the operation of the CPU core and
assembling/disassembling instructions.



Compilation - C and other high-level programming languages must be compiled.
Compilation is the process of translating keywords and statements into assembly
instructions which perform the functions described by the language. Typically, a
single statement will translate into multiple assembly instructions.
Assembly - Unlike high-level languages, in assembly code, each assembly
instruction corresponds to a single CPU instruction. Assembly is the process of
translating the assembly instructions into the binary machine code.
Disassembly - This is the reverse process of assembly. Binary machine code is
translated into the corresponding assembly instructions.
Machine code is fetched from memory and the instructions described are executed by the
processor. This includes performing operations (shift, add, subtract, clear) on registers
and memory locations and copying values from one location to another.
Task 2: (10 pts) Translate the following assembly code into machine code. Do this by
hand using the reference materials. It is OK to use CodeWarrior to check your work and
make corrections after you have done it by hand.
Assembly instruction
Machine Code
ORG RAMStart
Counter DS.W
X
1
X
ORG ROMStart
X
Theloop:
LDX
#1
couterLoop:
STX
Counter
BSR
first
LDX
Counter
INX
first:
CPX
#24
BSR
first
BRA
Theloop
LDY
#$00
LDD
#$01
LEAY
D,Y
EXG
D,Y
RTS
Task 3: (10 pts) Disassemble the following machine code. Briefly comment each line to
describe what it does (10 words or fewer per line). For branch instructions, insert labels
at the appropriate locations and use the label values in your disassembled assembly code.
Do this by hand using the reference materials. It is OK to use CodeWarrior to check your
work and make corrections after you have done it by hand.
CE 00 00 08 7E 02 40 8E 00 0A 26 F7 20 FE
Task 4: (10 pts) Determine the values of registers and flags during the following
program. For each instruction, fill in the values that will be present AFTER the
instruction is executed. If an instruction is not executed, fill in N/A for that row. Do this
by hand using the reference materials. It is OK to use CodeWarrior to check your work
and make corrections after you have done it by hand.
Assembly Instructions
Flags
Register D Register A Register B Z N C
Initial Values
Value DS.W 1
LDD #1
STD Value
LDAA #255
LDAB #255
ADDD Value
BCC cFlagClear
cFlagSet:
CLRA
cFlagClear:
BEQ zFlagSet
zFlagClear:
CLRB
zFlagSet:
LDAB #20
LDAA #10
SBA
BPL nFlagClear
nFlagSet:
LDD #0;
nFlagClear:
LDD #65535
0
0
0
0 0 0
Task 5:
(30 pts) Programming:
1.
2.
3.
4.
5.
6.
Configure PORTB4 – B7 to be outputs
Configure PORTA3-A7 to be inputs
Connect Pins PORTB4 – B7 to LEDs 5-8 on the project board
Connect Pin PORTA3 to Push Button 4 on the project board
Connect Pins PORTA4-7 to Dip Switch SW1(1-4)
Write an assembly program to do the following:





N = Read the input from the dip (SW1) switches
Add all numbers from 1 to N
If PB4 is NOT pressed, show the lower 4 bits of the sum using the LEDs (58). I
If PB4 is pressed, show the upper 4 bits of the sum using the LEDs (5-8).
Please demo your working code to the instructor or the TA
Task 6:
(30 pts) Programming:
1.
2.
3.
4.
5.
6.
Configure PORTB0 to be an output
Configure Pin PORTA3 to be input
Connect Pin PORTA3 to Push Button 4 on the project board
Connect Pins PORTA4-7 to Dip Switch SW1(1-4)
Connect PORTB0 to the signal pin of the Motor.
Write an assembly program to do the following:

When Push Button 4 is pressed and released, you should:
o N = Read the input from the dip (SW1) switches
o Turn the motor on based on the following criteria
 N = 0 or 7, Motor does not move
 N = 1, Motor rotates clockwise at lowest speed
 N = 2, Motor rotate clockwise at medium speed
 N = 3, Motor rotate clockwise at highest speed
 N = 4, Motor rotates counter-clockwise at lowest speed
 N = 5, Motor rotate counter-clockwise at medium speed
 N = 6, Motor rotate counter-clockwise at highest speed
 Lowest, medium, and highest are subjective, but there should
be a clearly observable difference between these three speeds.

Please demo your working code to the instructor or the TA