EmbeddedRelated.com
Forums
Memfault Beyond the Launch

Urgent help with hc11!!!

Started by hombre_kenno69 October 5, 2005
Hi all, i'm doing a course on the HC11 and i've been assigned a
project that computes the distance between two points (given the
change in height and length) thus using pythagoras to compute the
hypoutenuse. I'm totally lost and stuck, since i'm not much of a
programmer...at all
So i'd appreciate any help at all!

here's the question:
The distance function, L2(x,y) computes the Euclidean distance
between two points, whose x
coordinates differ by x and whose y coordinates differ by y.
Mathematically, the distance function
is given by L2(x,y) = p(x)2 + (y)2.
Your job will be to write a subroutine that computes L2(x,y), but
only for unsigned integers.
Download and unzip the care package a3-care.zip to your floppy drive
A:.
Again, these contain the skeleton and a sample A3Q3.ASM subroutine
which you will complete.
The Specification:
The subroutine L2 takes two 8-bit parameters as input on the stack.
These represent the unsigned
integers x and y.
The stack frame is set up by the skeleton. One byte is reserved for
the return value, and then
both parameters are pushed.
L2 will compute the function L2(x,y) = jp(x)2 + (y)2k and store
the result on the stack.
[Note the addition of the floor function.]
In the cases for which L2(x,y) > 255, L2 shall return 255.
You will use a working version of the sqrt function from Assignment
2 to simplify your code.
The model solution for sqrt is included within the care package. Be
sure to properly observe the
function protocols!
Once done the computation, your code shall perform an rts operation.
Your code may not use any fixed memory to complete its task, but may
use the stack.
There are no scratch registers available, so make sure you save and
restore any registers you use.
You will not modify the skeleton code, except in the inputs. Thnx guys!



In a message dated 10/5/2005 7:01:38 A.M. Eastern Standard Time,
anders.friberg@ande... writes:

Be careful!

Your professor is also reading this list!
===========================
Couldnt possibly be. He's like old... must be 35 or something... they didnt
even have the internat when he was in school. This is our secret weapon! We
rely upon the generosity of nice folks around the world to help us with our
problems, and life is wonderful! Hey! What Happened! I cant log on! The cable
system and phone system is down! Cant get to the internet! Wont be able to do
homework! Wont be able to get a job! Wont be able to pay house payment! Will
soon be living under an overpass! Aieeeeee!


Be careful!

Your professor is also reading this list!

Regards,
AF

On Wed, 05 Oct 2005 06:58:11 -0000
"hombre_kenno69" <hombre_kenno69@homb...> wrote:
> Hi all, i'm doing a course on the HC11 and i've been
>assigned a
> project that computes the distance between two points
>(given the
> change in height and length) thus using pythagoras to
>compute the
> hypoutenuse. I'm totally lost and stuck, since i'm not
>much of a
> programmer...at all
> So i'd appreciate any help at all!
>
> here's the question:
> The distance function, L2(x,y) computes the Euclidean
>distance
> between two points, whose x
> coordinates differ by x and whose y coordinates differ
>by y.
> Mathematically, the distance function
> is given by L2(x,y) = p(x)2 + (y)2.
> Your job will be to write a subroutine that computes
>L2(x,y), but
> only for unsigned integers.
> Download and unzip the care package a3-care.zip to
>your floppy drive
> A:.
> Again, these contain the skeleton and a sample
>A3Q3.ASM subroutine
> which you will complete.
> The Specification:
> The subroutine L2 takes two 8-bit parameters as input
>on the stack.
> These represent the unsigned
> integers x and y.
> The stack frame is set up by the skeleton. One byte is
>reserved for
> the return value, and then
> both parameters are pushed.
> L2 will compute the function L2(x,y) = jp(x)2 +
>(y)2k and store
> the result on the stack.
> [Note the addition of the floor function.]
> In the cases for which L2(x,y) > 255, L2 shall
>return 255.
> You will use a working version of the sqrt function
>from Assignment
> 2 to simplify your code.
> The model solution for sqrt is included within the care
>package. Be
> sure to properly observe the
> function protocols!
> Once done the computation, your code shall perform an
>rts operation.
> Your code may not use any fixed memory to complete its
>task, but may
> use the stack.
> There are no scratch registers available, so make sure
>you save and
> restore any registers you use.
> You will not modify the skeleton code, except in the
>inputs. > Thnx guys! >
>
> ------------------------ Yahoo! Groups Sponsor > Yahoo! Groups Links >





The problem seems straightforward.

Which part is giving you trouble?

I guess it would help if we knew what parts you have done or can do
and had access to the skeleton code and your current version of it.

I doubt that anyone on this list is going to take the time to do
your college work for you. On the other hand, if you do some work on
it first, you can probably get some help with a particular issue if
you get stuck.

I would suggest that you start by outlining the several individual
parts of the problem, then try to solve these, create code to
perform the operations, then put it all together withing the
skeleton code that you have.

For example, detail each of the math operations necessary to do the
Pythagorean function. Noting that the parameters and result are 8
bit (one byte) unsigned integers, consider how large the
intermediate values will need to be.

You will need to allocate somewhere to store each of the
intermediate values. The ninth bullet on your list will give you a
hint about how to do this.

The HC11 can do many math operations (add, subtract, multiply)
directly, especially with 8 bit values. Other math operations can be
done by a sequence of operations, for example squaring an 8 bit
number can be done by mutiplying the byte by itself.

You will need to understand how HC11 application passes the
parameters to your subroutine and how you will pass the result back.
To try out this process initially, make a simpler function that
returns the sum of the two parameters.

I don't know what tools you have access to, but you can download an
HC11 simulator that will run on your PC and let you step through
your code and verify the operation of your code.

The good thing about a simulator is that it wont stop or crash if
you have a bug in your code.

Good Luck

--- In m68HC11@m68H..., "hombre_kenno69"
<hombre_kenno69@y...> wrote:
> Hi all, i'm doing a course on the HC11 and i've been assigned a
> project that computes the distance between two points (given the
> change in height and length) thus using pythagoras to compute the
> hypoutenuse. I'm totally lost and stuck, since i'm not much of a
> programmer...at all
> So i'd appreciate any help at all!



On Wed, 5 Oct 2005 10:17:01 EDT
BobGardner@BobG... wrote:
>
> In a message dated 10/5/2005 7:01:38 A.M. Eastern
>Standard Time,
> anders.friberg@ande... writes:
>
> Be careful!
>
> Your professor is also reading this list! >
> ===========================
> Couldnt possibly be. He's like old... must be 35 or
>something... they didnt
> even have the internat when he was in school. This is
>our secret weapon! We
> rely upon the generosity of nice folks around the world
>to help us with our
> problems, and life is wonderful! Hey! What Happened!
>I cant log on! The cable
> system and phone system is down! Cant get to the
>internet! Wont be able to do
> homework! Wont be able to get a job! Wont be able to pay
>house payment! Will
> soon be living under an overpass! Aieeeeee!


LOL

Maybe the cable and phone system was programmed by a
student from last years class? >
> ------------------------ Yahoo! Groups Sponsor > Yahoo! Groups Links >




Thnx guys
all the inputs are appreciated
I had a go today at the code, and i got the following steps done:

-compute the square of the height
-compute the square of the length
-add the squares together

However, after i've done this, i can't seem to pass the results to the
subroutine sqrt which is provided to us, this is the step i'm lacking...
there are also alot of loop holes in my code too....its by far perfect...

My Code for L2, the subroutine to compute the length...so far..still
very rough, but runs ok...

L2: pshx
pshy
psha
pshb

tsx
ldaa 9,x
ldab 9,x ;load 5
mul
std 9,x
psha
pshb
ldaa 8,x
ldab 8,x
mul
std 8,x
psha
pshb
ldab 10,x
ldaa 9,x
aba
staa 8,x
pula
jsr sqrt The subroutine provided by the TA's

; The subroutine sqrt finds the integer square root of a 16-bit
; value (param). The algorithm uses a temporary stack variable
; space for the loop index (called index), decremented on each loop.
;
; pseudocode: index <- 255;
; while (index*index > param)
; index--;
; return index;
;

org $e200

sqrt: psha ; save all registers and then
pshb ; restore them just before
pshx ; returning to the caller

tsx ; IX points to the top of the
; stack frame

ldaa #15 ; index <- 255

loop: psha
pulb
des
mul
cpd 6,x
bls endl ; while (index*index > param)

pula
deca ; index--
bra loop

endl: pula
staa 8,x ; return index

pulx
pulb ; restore registers
pula ; and return to caller
rts

If anyone could point me in the right direction for passing the
results of the added squares which is A9 (hex) to the sub routine
sqrt, that'd be greatly appreciated!!

thnx guys


You SERIOUSLY need to comment your code.
Line by line!
Tell us what you MEAN to be doing, NOT what the assembly indicates.

A paragraph describing what the module is supposed ot do helps too.

hombre_kenno69 wrote:

>Thnx guys
>all the inputs are appreciated
>I had a go today at the code, and i got the following steps done:
>
>-compute the square of the height
>-compute the square of the length
>-add the squares together
>
>However, after i've done this, i can't seem to pass the results to the
>subroutine sqrt which is provided to us, this is the step i'm lacking...
>there are also alot of loop holes in my code too....its by far perfect...
>
>My Code for L2, the subroutine to compute the length...so far..still
>very rough, but runs ok...
>
>L2: pshx
> pshy
> psha
> pshb
>
> tsx
> ldaa 9,x
> ldab 9,x ;load 5
> mul
> std 9,x
> psha
> pshb
> ldaa 8,x
> ldab 8,x
> mul
> std 8,x
> psha
> pshb
> ldab 10,x
> ldaa 9,x
> aba
> staa 8,x
> pula
> jsr sqrt >The subroutine provided by the TA's
>
>; The subroutine sqrt finds the integer square root of a 16-bit
>; value (param). The algorithm uses a temporary stack variable
>; space for the loop index (called index), decremented on each loop.
>;
>; pseudocode: index <- 255;
>; while (index*index > param)
>; index--;
>; return index;
>;
>
> org $e200
>
>sqrt: psha ; save all registers and then
> pshb ; restore them just before
> pshx ; returning to the caller
>
> tsx ; IX points to the top of the
> ; stack frame
>
> ldaa #15 ; index <- 255
>
>loop: psha
> pulb
> des
> mul
> cpd 6,x
> bls endl ; while (index*index > param)
>
> pula
> deca ; index--
> bra loop
>
>endl: pula
> staa 8,x ; return index
>
> pulx
> pulb ; restore registers
> pula ; and return to caller
> rts
>
>If anyone could point me in the right direction for passing the
>results of the added squares which is A9 (hex) to the sub routine
>sqrt, that'd be greatly appreciated!!
>
>thnx guys >Yahoo! Groups Links

--
*
| __O Thomas C. Sefranek WA1RHP@WA1R...
|_-\<,_ Amateur Radio Operator: WA1RHP
(*)/ (*) Bicycle mobile on 145.41, 448.625 MHz

http://hamradio.cmcorp.com/inventory/Inventory.html
http://www.harvardrepeater.org


You SERIOUSLY need to comment your code.
Doccument! It will save you a LOT of time.
Line by line!
Tell us what you MEAN to be doing, NOT what the assembly indicates.

A paragraph describing what the module is supposed to do helps too.

hombre_kenno69 wrote:

>Thnx guys
>all the inputs are appreciated
>I had a go today at the code, and i got the following steps done:
>
>-compute the square of the height
>-compute the square of the length
>-add the squares together
>
>However, after i've done this, i can't seem to pass the results to the
>subroutine sqrt which is provided to us, this is the step i'm lacking...
>there are also alot of loop holes in my code too....its by far perfect...
>
>My Code for L2, the subroutine to compute the length...so far..still
>very rough, but runs ok...
>
>L2: pshx
> pshy
> psha
> pshb
>
> tsx
> ldaa 9,x
> ldab 9,x ;load 5
> mul
> std 9,x
> psha
> pshb
> ldaa 8,x
> ldab 8,x
> mul
> std 8,x
> psha
> pshb
> ldab 10,x
> ldaa 9,x
> aba
> staa 8,x
> pula
> jsr sqrt >The subroutine provided by the TA's
>
>; The subroutine sqrt finds the integer square root of a 16-bit
>; value (param). The algorithm uses a temporary stack variable
>; space for the loop index (called index), decremented on each loop.
>;
>; pseudocode: index <- 255;
>; while (index*index > param)
>; index--;
>; return index;
>;
>
> org $e200
>
>sqrt: psha ; save all registers and then
> pshb ; restore them just before
> pshx ; returning to the caller
>
> tsx ; IX points to the top of the
> ; stack frame
>
> ldaa #15 ; index <- 255
>
>loop: psha
> pulb
> des
> mul
> cpd 6,x
> bls endl ; while (index*index > param)
>
> pula
> deca ; index--
> bra loop
>
>endl: pula
> staa 8,x ; return index
>
> pulx
> pulb ; restore registers
> pula ; and return to caller
> rts
>
>If anyone could point me in the right direction for passing the
>results of the added squares which is A9 (hex) to the sub routine
>sqrt, that'd be greatly appreciated!!
>
>thnx guys >Yahoo! Groups Links

--
*
| __O Thomas C. Sefranek WA1RHP@WA1R...
|_-\<,_ Amateur Radio Operator: WA1RHP
(*)/ (*) Bicycle mobile on 145.41, 448.625 MHz

http://hamradio.cmcorp.com/inventory/Inventory.html
http://www.harvardrepeater.org


On Wed, 2005-10-05 at 18:10 -0400, Tom Sefranek wrote:
> You SERIOUSLY need to comment your code.

And part of the commentary - a most *important* part, probably *more*
so than the "end-of-line" comments, is to use defined symbols as
mnemonics for constants and displacements.

You have for example, given us a code segment which refers to
variables pushed on the stack before the subroutine call. These
variables should be given *names*, not numbers (and you will likely be
marked on this point!). In addition, there are a few other apparent
blunders, some merely semantics, some important.

> >L2: pshx
> > pshy
> > psha
> > pshb

Someone correct me if I am wrong, but the HC11 is "big-endian" and
"pshd" would actually be "pshb ... psha" - just in case you were to use
it?

> > tsx
> > ldaa 9,x
> > ldab 9,x ;load 5
> > mul
> > std 9,x
> > psha
> > pshb
> > ldaa 8,x
> > ldab 8,x
> > mul
> > std 8,x

Courting trouble:

> > psha
> > pshb

> > ldab 10,x
> > ldaa 9,x
... Should have been ldd 9,x

> > aba
> > staa 8,x
> > pula

You now have three more things on the stack than when you started. Is
that what you wanted?

> > jsr sqrt

So you jump to the subroutine and come back with all sorts of things
on the stack. You are going to clean them up now?

> >The subroutine provided by the TA's
> >
> >; The subroutine sqrt finds the integer square root of a 16-bit
> >; value (param). The algorithm uses a temporary stack variable
> >; space for the loop index (called index), decremented on each loop.
> >;
> >; pseudocode: index <- 255;
> >; while (index*index > param)
> >; index--;
> >; return index;
> >;
> >
> > org $e200
> >
> >sqrt: psha ; save all registers and then
> > pshb ; restore them just before
> > pshx ; returning to the caller
> >
> > tsx ; IX points to the top of the
> > ; stack frame
> >
> > ldaa #15 ; index <- 255
> >
> >loop: psha
> > pulb
> > des

Pray no-one *ever* uses interrupts with this code!

> > mul
> > cpd 6,x

Arguably, if the prof does this himself, he won't mark you down.

> > bls endl ; while (index*index > param)
> >
> > pula
> > deca ; index--
> > bra loop
> >
> >endl: pula
> > staa 8,x ; return index
> >
> > pulx
> > pulb ; restore registers
> > pula ; and return to caller
> > rts
> >
> >If anyone could point me in the right direction for passing the
> >results of the added squares which is A9 (hex) to the sub routine
> >sqrt, that'd be greatly appreciated!!

I thought from your imitation of the same techniques, you understood
this? I think you need to sit and work out what is going on on the
stack all through this code.

--
Cheers,
Paul B.


Tom Sefranek wrote:
> You SERIOUSLY need to comment your code.
> Line by line!

Line by line may be just a tad much. But I usually comment
2/3 of the lines in my assy or maybe 90%. Often, in assy,
accomplishing any one given thing takes 2-3 instructions.
I comment the first, and use indicators that the action is
still taking place. For example:

tsx ; Increment total byte count
ldd Count,x ; .
addd #1 ; .
std Count,x ; .

I think that over-commenting can be bad, but it's not
nearly as bad as under-commenting. I'd much rather
encounter

tsx ; Prepare for stack addressing
ldd Count,x ; Get total byte count
addd #1 ; Increment total byte count
std Count,x ; Store total byte count back

than bare code. I'd prefer what I wrote at first, though.

The very worst would be

tsx
ldd 6,x
addd #1
std 6,x

AAAAARRRRGGGGHHHH!

> Tell us what you MEAN to be doing, NOT what the assembly indicates.

'Way back when I was doing assy on the 8088, a buddy of mine
used to comment thusly:

cli ; disable interrupts
...
sti ; enable interrupts

Used to drive me NUTS! I asked him, in a calm tone, the first
time I encountered it, why he made those comments. His reply
was that he could never remember which one enabled and which
one disabled. I replied something like "I can always look up
the instructions. But please tell me WHY ARE YOU DISABLING
INTERRUPTS? WHAT NEEDS TO BE ATOMIC!?"

This remained a bone of contention between us. I'd figure out
what the code was doing, and rip his comments, and add something
like

cli ; The keyboard interrupt handler uses InHead and
; InTail. We are critical until the circular

; buffer update is completed.
...

sti ; Allow keyboard interrupts...

At another job, I routinely encountered comments like:

CLR R0 ; Clear R0
LDA RR2,BUF ; Load address to RR2
CALL KERBFA ; Call kernel routine

(Z8000 assy for Telecomm code)

> A paragraph describing what the module is supposed ot do helps too.

I have built boilerplate into my favorite editor to create

file level prologue
subroutine level prologue

They are for C, rather than assy, but a quick edit changes
them to assy commentary.

> hombre_kenno69 wrote: >>Thnx guys
>>all the inputs are appreciated
>>I had a go today at the code, and i got the following steps done:
>>
>>-compute the square of the height
>>-compute the square of the length
>>-add the squares together
>>
>>However, after i've done this, i can't seem to pass the results to the
>>subroutine sqrt which is provided to us, this is the step i'm lacking...
>>there are also alot of loop holes in my code too....its by far perfect...

Well, the calling procedure is the PROF'S responsibility
to provide. Whoever writes code is responsible for making
it absolutely clear how it is intended to be used. [snip]

>>The subroutine provided by the TA's
>>
>>; The subroutine sqrt finds the integer square root of a 16-bit
>>; value (param). The algorithm uses a temporary stack variable
>>; space for the loop index (called index), decremented on each loop.
>>;
>>; pseudocode: index <- 255;
>>; while (index*index > param)
>>; index--;
>>; return index;
>>;
>>
>> org $e200

I realize this is the TA's code.
This is inadequate commentary.

Mike
--
p="p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}
This message made from 100% recycled bits.
You have found the bank of Larn.
I can explain it for you, but I can't understand it for you.
I speak only for myself, and I am unanimous in that!




Memfault Beyond the Launch