ENSC 150 - PowerPoint PPT Presentation

1 / 14
About This Presentation
Title:

ENSC 150

Description:

The symbol r is called the radix (base). There are an infinite number of digits. ... This procedure is independent of the position of the radix point in both operands. ... – PowerPoint PPT presentation

Number of Views:43
Avg rating:3.0/5.0
Slides: 15
Provided by: luc135
Category:
Tags: ensc | radix

less

Transcript and Presenter's Notes

Title: ENSC 150


1
ENSC 150
26
  • Multiplication
  • Stack Operations

2
Multiplications
We only have 3 multiplication instructions to
choose. EMUL, EMULS and MUL
MUL performs 8-bit unsigned multiplication D
A B EMUL performs (extended)16-bit unsigned
multiplication YD Y D EMULS performs 16-bit
Signed multiplication. YD Y D
Using the simulator load A1, BFF and execute
MUL. load Y0001, D00FF execute EMUL
3
The Algorithm
Recall In any base we encode UNSIGNED numbers
using,
The symbol r is called the radix (base). There
are an infinite number of digits.
In many cases the digits to the left and the
digits to the right are all ZERO and thus we can
write the number with only a finite number of
digits without any error.
We indicate the position of the r0 digit by
placing a dot called the radix point.
The algorithm for multiplication contains TWO
steps. The first step involves manipulating the
digits of the two operand to construct a new
string of digits. This procedure is independent
of the position of the radix point in both
operands. The second step involves positioning
the radix point in the result by inspecting the
position of the radix point in both operands.
This procedure is independent of the digits of
the operands.
4
Placing the Point
Suppose that you have a machine that can
correctly multiply a single decimal digit by
another single decimal digit.
In all cases, the machine produces the same pair
of digits but it is up to us to remember where
the point is.
5
Binary Multiplication
Suppose that you wish to multiply 5.125 by 11.25
60.46875
6
Using The Stack
The Stack Pointer (SP) is another register inside
the processor. Like the PC, the SP has a special
purpose and should not be used as a general
purpose register.
See Table 5-25. On page 92 The bottom half shows
instructions that allow the programmer to
transfer values between registers and the top of
stack (TOS). This is called pushing and pulling.
(popping)
7
Memory Organization
Here is an example showing the most common way in
which programs use the memory space.
Instructions and Data are usually in separate
regions of memory. The stack is place far away
because its size is always changing and we do not
want it to accidentally overlap the other regions.
8
A Time Delay Subroutine
Let us write a subroutine that causes a time
delay. This is a useful subroutine that may be
called from any arbitrary level using a JSR
instruction. The subroutine will inspect the
16-bit value in a global variable called DELAY to
determine how many times to loop before returning
back to the calling level.
9
Main Level
for testing. O
rg 0800 lds 0a00 ldd 25 std Delay jsr
Wait Break bra
A delay subroutine.
Wait ldx Delay loop dbne x,loop rts
Reserve
memory for any globals
Org 0900 Delay dc.w 0
You should calculate how long it will take to hit
the breakpoint. Verify your calculation using the
simulator.
10
Saving Registers
The subroutine used Register X for its loop
counter. The original number in Register x (
before entering the subroutine ) is destroyed by
the subroutine.
  • We can prevent this problem in two ways.
  • We can modify the subroutine so that is saves
    Register X on the TOS upon entry and restores
    Register X upon exit.
  • We can modify the calling level process so that
    it saves Register X on the TOS just before
    executing the JSR and then restores Register X
    after the JSR.

11
Exchanging Parameters
The delay subroutine required a value that was
supplied by the calling level. We defined a
convention that this value should be passed in a
global variable called Delay. Both the calling
instructions and the subroutine we written with
this convention.
The memory location used to store the exchanged
parameter is in some sense being wasted. If we
have a large program with hundreds of subroutine
each requiring their own specific memory slots
for passing parameter we would have to reserve a
lot of memory.
Instead we use the stack to pass the parameter
values. We adopt the convention that the calling
level must place the parameter values on the TOS
then execute the JSR and after returning the
calling level must restore to its previous state.
12
Main Level
for testing. O
rg 0800 lds 0a00 ldd 25 pshd jsr Wait
puld Break bra
A delay subroutine.
Wait ldx 2,sp loop dbne x,loop r
ts
You should calculate that this code will hit the
breakpoint after 12 microseconds. Verify this
value using the simulator.
13
The Stack Upon Subroutine Entry
Notice that any instruction may access the Delay
value as an operand using an index addressing
mode with the SP as the index register.
The offset will be 2, HOWEVER if if any push or
pull instructions have occurred then the offset
will be WRONG.
A subroutine will make a copy of the value of the
stack pointer when it is entered. This copy is
place in an index register and is used to access
the parameters. This allows the stack to be used
by the subroutine without having to worry about
the offsets changing. We refer to this index
register as the Frame Pointer.
14
We will continue with this example next
lecture. Please modify the delay subroutine so
that the loop counter is stored in memory as a
local variable on the stack.
Write a Comment
User Comments (0)
About PowerShow.com