Re: LF: programming stuff


[Prev][Next][Index][Thread]

Re: LF: programming stuff



At 01:57 PM 6/26/97 -0400, you wrote:
>Sorry to disturb....
>I am working on a trig lib which would really calculate sine and cosine
>values. ( the one which is available just stores values in an array... ) I am
>using " limited developpements" ( ?... ) ( am not sure about the spelling and
>the expression itself. ) U know: cos(x) = x + x^2 / 2 + ...
>So: the prog i wrote just can' t be compiled...
>here is what' s wrong: 
>exerpt from " list.txt "
>
>>000018	33FC 0001 000000BC	    134    move.w  #1,K     
>>000020	33FC 0001 000000BD	    135    move.w  #1,nume         ;  
>>Alignment error.			                                             ^ lib.asm
>line 10>000028	3200
>
>and "K" and "nume" are 	defined as
>
>>0000BC	00			    186 K:      dc.b 0
>>0000BD	00			    187 nume:   dc.b 0

I believe your trouble here is that you have the two variables defined as
bytes, but you are moving words into them, so to fix this, either define
them as words or use 'move.b' instead of 'move.w'.

>nume and K are thus defined exactly in the same way and are used exactly in
>the same way: what is wrong ? 
>For more detail, i have attached the source file ( lib.asm )  to this Email
>
>One more thing: i have had many " adressing mode not allowed here": this
>means that i cannot use a certain data with the specified instruction ? 

"adressing mode not allowed here" simply means that you cannot use the
specific instruction in the way that you are using it. If you look at the
68k guide, for each instruction, there is a list of acceptable
"Addressmethods", you must use one of these when using that instruction,
otherwise you will get a compiler error.  

>One thing more: in the 68k guide ( really great ! thanks jimmy mardel ! ) ,
>there are some "#" and "$" symbols used. "#" stands for "immediate" and "$"
>for "adress" ?

"$" stands for hexadecimal value, this just happens to be how memory is
addressed on the TI-92 (and most computers and calculators).  For example,
$04 and #4 are exactly the same and can be interchanged, the both stand for
4 in decimal.

Also, a few other notes: If you intend this to be a library, the format is
a bit different (the 68k guide has a good description of the differences.)
You cannot return from a branch (whether conditional or not), so if you
'bge sign' the rts statement at the end of that routine will quit the
program, which I don't think you want to do at that point.  bsr and jsr are
the only instructions that can be returned from, and there are no
conditional (if greater than, iff less than...) forms of these
instructions, so you must work around this.

	-Andrew

>Thanks for answering...
>Mathieu, <hm lacage@aol.com>      
>    @program prog_code,prog_name
>
>
>prog_code:
>
>   clr.l   D0
>   clr.l   D1
>   move.w  #1500,D0        ; envoie param a lib : calc de sin(1.500)
>   move.w  #1,K            ; ini le compteur                   
>   move.w  #1,nume         ;  
>   move.w  D0,D1           ; 1er terme du DL
>
>iterer1:
>   add.w   #1,(Num)        ; incrementation du compteur de termes non nuls
>   add.w   #2,(K)          ; incrementation du compteur puissance
>   bsr     calc            ; calc des termes inter stockes ds ecc
>   btst    #0,(Nun         ; teste si on doit ajouter ou retrancher 
>   bne     diff            ; le terme calcule ( test parite nø terme) 
>
>diff:
>   sub.w   (ecc),D1        ; calc le res ( difference ) 
>   rts
>
>   add.w   (ecc),D1        ; calc le res ( somme )
>   cmp     (ecc),#0        ; 
>   bge     sign            ; valeur abs
>   cmp     (ecc),#1        ; teste si precision suffisante
>   bge     fin             ;
>   bra     iterer1         ; sinon, retour au deb: calc d' 1 autre terme
>   rts
>
>calc:
>   clr.l   D2              ; vide le reg qui va etre utilise comme compteur
>   move.w  D0,ecc          ; ini de la valeur inter
>   move.w  K,D2
>iterer2:
>   sub.w   #1,D2           ; calcul du deb du terme ( la puissance )
>   mulu.l  D0,(ecc)        ; en fait: D0^K
>   divu.l  #1000,(ecc)     ;
>   cmp.w   D2,#0           ;
>   bne     iterer2         ;
>fin_iterer2:
>   move.w  K,D2            ; re initialisation de K ds D2
>iterer3:
>   mulu.l  #10,(ecc)       ; calcul de ecc/D2
>   divu.l  (ecc),D2        ; en fait, calcul de la div de la factorielle
>   sub.w   #1,D2           ; deccrementation du compteur K
>   cmp.w   D2,#0           ; test pour sortir de la boucle
>   bne     iterer3         ;
>fin_iterer3:
>   rts
>
>sign:
>   neg     (ecc)
>   rts
>
>fin:
>   rts
>
>ecc:    dc.l 0
>K:      dc.b 0
>nume:   dc.b 0
>
>prog_name:
>   dc.b  "sin lib",0
>
>reloc_open
>   add_library flib
>   add_library romlib
>   add_library hexlib
>reloc_close
>
>end:


References: