Page 1 of 1

C and ASM programmer needed!

Posted: Fri Nov 26, 2004 2:34 pm
by RichardL
Hi,

I have an ongoing project that requires a PB compatible assembly routine written.

I have a C listing which is just 28 line long, plus the listing file from the C compiler which includes an assembler listing; but is in an obscure format and is defeating me!

The reason I cannot program it directly in PB is that it involves unsigned long values and PB treats longs as signed.

I am NOT literate with C or 808x assembler and may need some assistance IF in-house efforts fail.

If anyone with appropriate skills is able to assist I would be pleased to hear from them... and we could negaotiate.

Re: C and ASM programmer needed!

Posted: Fri Nov 26, 2004 3:45 pm
by traumatic
RichardL wrote:The reason I cannot program it directly in PB is that it involves unsigned long values and PB treats longs as signed
I don't think that's a valid reason as the resulting values are the same.

Re: C and ASM programmer needed!

Posted: Fri Dec 03, 2004 8:35 pm
by horst
> The reason I cannot program it directly in PB is that it involves unsigned long values and PB treats longs as signed.

That's no problem if the values never exceed 2^31.
If only intermediate results might exceed that limit, you could do just those instructions in assembler (intermediate values can be 64 bit in assembler).

In any case, if the assembler listing is not too long, send me an email, and I'll have a look.

Posted: Fri Dec 03, 2004 9:50 pm
by RichardL
Gentlemen...

I fixed it with a bit of help from a friend!

The biggest problem we experienced involved sign extension on right shifts and a few other problems in the same class. So, by carefully re-writing the code in PB with a few devious subroutines like the one below we now have the PB program providing the same results as the PC version written in C and the H8 Microprocessor version that has to match it.

Job done, Phew!

Code: Select all

Procedure Uadd32(al.l,Bl.l)            ;- Add two SIGNED variables as UNSIGNED quantities
  ; Routine to add two SIGNED 32 bit quantities and return 
  ; a 32 bit result that is UNSIGNED.
  
  Protected TopBit.l, Sum2.l
  
  TopBit.l = (al.l ! Bl.l) & $80000000
  
  Sum2.l    = ((al.l & $7FFFFFFF) + (Bl.l & $7FFFFFFF)) ! TopBit.l
  
  ProcedureReturn Sum2.l
EndProcedure
PS: Thank you for your offer Horst, and sorry not to have got back to you earlier.
R.L

Posted: Sat Dec 04, 2004 8:46 am
by horst
If you want to add two positive values (32 bit), and the result is assumed within 32 bit, then there is no special treatment necessary. Just do A + B, and check StrU(result,#long).

Code: Select all

#bn=1000000000
a = 2*#bn + #bn
Debug StrU(a,#Long)
a + #bn
Debug StrU(a,#Long)
Debug Str(a) + " same, as signed value"
It just depends how you interprete the result.

However, if one of the given values is negative, your procedure may not return what you wanted. For example Uadd32(2,-3) will return 4294967295.

(Multiplication is another issue...)