EE357-Nazarian-Fall09-Lab2-addr_modes

EE357-Nazarian-Fall09-Lab2-addr_modes -...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: EE
357
Lab
2
–
Using
Addressing
Modes
 1 Introduction
 You
will
work
in
teams
of
one
or
two
to
write
two
short
kernels
of
assembly
code
to
 reverse
a
string
of
text
and
to
perform
simple
text
encryption
method.

 2 What
you
will
learn
 This
lab
is
intended
to
teach
you
how
to
use
the
various
addressing
modes
available
 with
the
Coldfire
processor.

Particular
focus
will
be
paid
to
the
address
register
 indirect
with
predecrement
and
postincrement
[
‐(An)
and
(An)+
]
as
well
s
the
 address
register
indirect
with
index
mode
[
(d8,An,Rn.L*S)
].

In
addition,
this
lab
will
 familiarize
you
with
assembler
directives
and
coding
loops.


 3 Background
Information
and
Notes
 Part
1
 The
first
task
in
this
lab
is
to
write
assembly
code
to
query
the
user
for
a
text
string,
 receive
that
text
string
input,
and
then
reverse
the
string
and
output
it
to
the
 console.

An
example
is
shown
below:
 
 Enter text to reverse Here is my text txet ym si ereH 
 To
perform
this
task
you
should
consider
how
to
use
the
postincrement
and
 predecrement
address
register
indirect
modes
[i.e.
(An)+,
‐(An)
].

By
setting
up
a
 pointer
to
the
end
of
the
source
string
and
a
pointer
to
a
blank
space
in
memory
for
 the
destination
(reversed)
string,
the
source
pointer
can
use
predecrement
mode
 while
the
destination
pointer
uses
postincrement
mode.
 
 Part
2
 The
second
task
in
this
lab
is
to
perform
a
simple
text
encryption
of
a
user
specified
 string.

Each
character
in
the
string
(other
than
spaces)
should
be
converted
to
a
 different
character
based
on
the
specification
below
followed
by
an
example:
 
 Input
 a
 b
 c
 d
 e
 f
 g
 h
 i
 j
 k
 l
 m
 n
 o
 p
 q
 r
 s
 t
 u
 v
 w
 x
 y
 z
 Output
 o
 m
 b
 c
 r
 q
 z
 s
 e
 d
 g
 t
 g
 u
 a
 h
 i
 j
 v
 y
 k
 p
 w
 x
 n
 l
 
 Enter text to encrypt hi world se wajtc Fall
2009 1
 EE
357
Lab
2
‐
Using
Addressing
Modes
 
 
 Using
Index
Mode
to
Access
a
Look‐Up
Table
(LUT):

Consider
a
simple
text
 encryption
scheme
that
maps
each
input
letter/character
to
a
different
output
 letter/character.
 
 Input
Letter
 
 Output
Letter
 LUT
Position/Index
 a
 
 p
 0
 b
 Maps
to…
 r
 1
 c
 
 g
 2
 d
 
 x
 3
 
 Now
assume
we
store
the
output
letters
in
an
array
(or
call
it
a
table).

If
we
convert
 the
input
letters
to
their
position
in
the
alphabet
(i.e.
a
=>
0,
b
=>
1,
c=>
2,
…,
z
=>
 25)
we
could
use
that
position
as
an
index
into
the
output
letter
array/table
and
 simply
output
whatever
letter
is
located
at
that
index.

Thus,
if
an
address
register
 (say
A0)
pointed
to
the
start
address
of
the
output
letter
table
and
we
perform
 arithmetic
on
the
input
letter
to
convert
it
to
an
index
(and
store
it
in
D0),
we
could
 then
use
the
A.R.I.
w/
Index
addressing
mode
[i.e.
(A0,D0.L)]
to
“look‐up”
the
 output
letter
that
corresponded
with
the
input
letter.

This
simple
LUT
capability
is
 used
quite
often
and
is
recommended
for
performing
the
encryption
scheme
in
 your
lab.


 
 I/O:

Refer
to
the
Codewarrior
7.1
Setup
document
for
the
subroutines
that
are
 defined
to
perform
I/O,
specifically,
the
“ee357_get_str”
and
“ee357_put_str”
 subroutines.

They
each
require
some
arguments
to
be
setup
in
certain
registers
 before
being
called
and
in
the
case
of
the
“ee357_get_str”
routine,
a
value
is
 returned
in
D1.
 4 Procedure
 1. Download
the
project
zip
file:

“ee357_lab2_addrmodes.zip”
from
Blackboard
 (Assignments..Labs..Lab
2)
and
unzip
it
to
a
folder
on
your
PC.


 2. Open
the
project,
by
double‐clicking
the
.mcp
file
in
the
project
folder.

This
 project
provides
a
skeleton
assembly
file,
‘main.s’.

It
is
setup
for
the
Instruction
 Set
Simulator
(ISS)
and
thus
does
not
require
your
HW
board.
 3. Open
‘main.s’
and
examine
the
code.

There
are
several
data
directives
to
 initialize
memory
with
specific
text
strings,
tables,
buffers,
and
other
data
 values.

The
code
is
broken
into
two
parts.

The
first
part
is
for
the
text
string
 reversal
code
while
the
second
is
for
the
text
encryption
code.
 4. For
the
text
reversal
code
your
solution
must:
 a. Output
a
prompt
to
the
user
to
enter
a
text
string
 2 Fall
2009
 
 
 EE
357
Lab
2
‐
Using
Addressing
Modes
 b. Receive
a
text
string
input.

[Note:

When
you
enter
a
string
in
the
console
 window,
you
may
need
to
click
on
the
window
first…the
program
is
a
bit
 buggy
and
may
not
have
focus
even
though
it
seems
like
the
window
is.]
 This
string
can
have
up
to
a
maximum
of
20
characters
including
the
 ‘LF’/Enter
character
(i.e.
only
19
alphanumeric
characters).

You
may
 assume
the
user
will
enter
an
appropriately
formatted
string
(i.e.
you
do
 not
have
to
do
any
error
checking).
 c. Now
reverse
all
characters
EXCEPT
for
the
LF
at
the
end
of
the
input
string.

 You
should
simply
add
the
LF
to
the
end
of
your
reversed
string
followed
by
 a
NULL
character.

You
MUST
use
the
postincrement
mode
and
 predecrement
mode
in
the
body
of
a
loop.

 d. You
must
then
print
the
reversed
string
to
the
console.
 Sample
C
Code
to
perform
text
string
reversal:
 char buf1[21]; char buf2[21]; int len, i=0; // Assume string received into buf1 and // length of string (including LF but not NULL) is in len; len = len-1; while(len > 0){ buf2[i++] = buf1[--len]; } buf2[i++] = ‘\n’; // Add NEWLINE character buf2[i] = 0; // Add NULL character to terminate string 5. For
the
text
encryption
code
your
solution
must:
 a. Output
a
prompt
to
the
user
to
enter
a
text
string
 b. Receive
a
text
string
input.

This
string
can
have
up
to
a
maximum
of
20
 characters
including
the
‘LF’/Enter
character
(i.e.
only
19
LOWER
CASE
 alpha
characters
and
spaces;
no
numeric
digits
or
other
character).

You
 may
assume
the
user
will
enter
an
appropriately
formatted
string
(i.e.
you
 do
not
have
to
do
any
error
checking
for
upper
case
letters
or
digits,
etc.).
 c. Now
use
the
‘cipher’
array
as
a
LUT
to
encrypt
each
character
up
through
 but
not
including
the
LF.

HOWEVER,
space
characters
should
simply
be
 copied
to
the
destination
and
not
encrypted
(i.e.
do
not
perform
a
look‐up
 in
the
cipher
table
if
it
is
a
space
character).

You
MUST
use
the
indexmode
 to
access
the
LUT
(manipulating
the
input
character
to
be
your
index)
in
the
 body
of
a
loop.

 d. You
must
then
print
the
encrypted
string
to
the
console.
 
 
 
 Fall
2009 3
 EE
357
Lab
2
‐
Using
Addressing
Modes
 Example
C
code
to
perform
encryption:
 char cipher[26] = {ombcrqzsedgtguahijvykpwxnl}; char buf1[21]; char buf2[21]; int len, index, i=0; // Assume string received into buf1 and // length of string (including LF but not NULL) is in len; buf1[len-1] = 0; // overwrite LF with NULL; while(buf1[i] != 0){ if(buf1[i] = ‘ ‘) // if space, then just copy buf2[i] = buf1[i]; else { // Perform operations on ASCII value of buf1[i] // to convert it to index between 0-25 buf2[i] = cipher[index]; } i++; } 
 6. Now
go
back
to
your
part
1
code
and
add
code
at
the
end
to
determine
if
the
 string
entered
by
the
user
is
a
palindrome.

A
palindrome
is
a
string
that
is
the
 same
when
read
forwards
or
backwards
(e.g.
“rotator”,
“dennis
sinned”,
etc.).

 Note:

You
do
not
have
to
filter
out
spaces
(i.e.
“hi
h”
is
not
a
palindrome
due
to
 the
space).

After
you
print
the
reversed
string,
determine
if
the
string
is
a
 palindrome
and
output
a
message
indicating
that
it
is
or
is
not.


 7. Compile/make
the
project.
Remember
to
set
a
breakpoint
at
the
first
instruction
 then
start
the
debugger.

Run
your
program
using
the
debugging
features
of
 viewing
registers
and
memory
along
with
single‐stepping
and
breakpoints
to
fix
 any
errors
that
occur.

Learn
to
be
a
good
debugger
and
don’t
just
guess
or
 change
instructions
randomly
hoping
it
will
work.

Figure
out
what
you
expect
 each
instruction
to
do
and
verify
it
by
viewing
the
register/memory
values.
 8. Comment
your
code
with
enough
information
to
convey
your
approach
and
 intentions.

Try
to
organize
your
code
in
a
coherent
fashion
to
avoid
“spaghetti
 code”
(i.e.
branches
all
over
the
place
jumping
back
and
forth).

Also,
format
the
 code
to
make
it
readable
using
helpful
label
names,
good
formatting
and
 alignment
of
instructions,
etc.
 9. Submit
your
source
file,
via
Blackboard
(Assignments..Labs..Lab
2)
attaching
only
 the
‘main.s’
file
in
the
‘sources’
folder
of
your
project.

Make
sure
you
click
 “submit”
on
Blackboard
and
not
just
“save”.

Also,
turn
in
a
hardcopy
of
your
 main.s
file
to
your
TA.
 5 Review
 None
 4 Fall
2009
 
 
 EE
357
Lab
2
‐
Using
Addressing
Modes
 6 Lab
Report
 Name: ___________________________________ Due: Fri. October 2nd Score: ________ (Detach and turn this sheet along with any other requested work or printouts) 
 1. Turn
in
a
hardcopy
of
main.s
with
the
name
of
your
partner
to
your
TA
in
 discussion.
 Fall
2009 5
 EE
357
Lab
2
‐
Using
Addressing
Modes
 
 
 7 EE
357
Lab
2
Grading
Rubric
 Name: ___________________________________ Req.
/
 Guidelin e
 
 Mul t
 
 Scor e
 
 4
 (Excellent)
 Works
 correctly
all
 the
time
 
 
 Score: ______ / 81 2
(Poor)
 1
 (Deficient)
 (0)
Failure
 3
(Good)
 Works
 usually
but
 fails
in
1‐2
 cases
 Req.
4a
 Req.
4b
 Req.
4c
 Req.
4d
 Req.
5a
 Req.
5b
 Req.
5c
 Req.
5d
 Req.
6
 Req.
8
 1
 1
 4
 1
 1
 1
 4
 1
 4
 2
 
 
 
 
 
 
 
 
 
 
 Fails
in
 several
cases
 Does
not
 but
not
 work
 always
 
 
 Not
 implemente d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 Well‐ organized
 and
readable
 with
good
 labels
and
 formatting
 5
pts.
 
 Well‐ organized
 with
 acceptable
 labels
and
 formatting
 
 
 Hard
to
read
 or
poorly
 organized
 but
 formatted
 well
 
 
 Hard
to
read
 or
poorly
 organized
 and
with
 poor
 formatting
 
 
 Extermely
 poor
 organization
 and
 formatting
 
 Hard
 
 
 6 Fall
2009
 
 
 Copy
 EE
357
Lab
2
‐
Using
Addressing
Modes
 Late
 TOTAL
 
 
 
 
 
 ‐10
per
day
 
 
 
 
 
 
 
 
 
 Fall
2009 7
 ...
View Full Document

This note was uploaded on 09/14/2010 for the course EE 357 at USC.

Ask a homework question - tutors are online