Shop OBEX P1 Docs P2 Docs Learn Events
signed multiply/divide in assembly — Parallax Forums

signed multiply/divide in assembly

Graham StablerGraham Stabler Posts: 2,510
edited 2011-03-04 04:35 in Propeller 1
Before I code it myself, is it already available?

Cheers,

Graham

Comments

  • max72max72 Posts: 1,155
    edited 2011-03-03 09:04
    There are samples on the wikispaces..

    http://propeller.wikispaces.com/MATH

    Massimo
  • BeanBean Posts: 8,129
    edited 2011-03-03 11:52
    Here is the code generated by PropBasic.
                      mov           __temp1,__param2             '  __param1 = __param2 * __param3
                      mov           __temp2,__param3            
                      abs           __temp1,__temp1 WC          
                      muxc          __temp3,#1                  
                      abs           __temp2,__temp2 WC, WZ      
        IF_C          xor           __temp3,#1                  
                      mov           __temp4,#0                  
                      mov           __temp5,#32                 
                      shr           __temp1,#1 WC               
    __L0001                                                     
        IF_C          add           __temp4,__temp2 WC          
                      rcr           __temp4,#1 WC               
                      rcr           __temp1,#1 WC               
                      djnz          __temp5,#__L0001            
                      test          __temp3,#1 WZ               
        IF_NZ         neg           __temp4,__temp4             
        IF_NZ         neg           __temp1,__temp1 WZ          
        IF_NZ         sub           __temp4,#1                  
                      mov           __param1,__temp1            
    
    
                      mov           __temp1,__param2             '  __param1 = __param2 / __param3
                      mov           __temp2,__param3            
                      mov           __temp4,#0                  
                      abs           __temp1,__temp1 WC          
                      muxc          __temp5,#1                  
                      abs           __temp2,__temp2 WC, WZ      
        IF_Z          mov           __temp1,#0                  
        IF_Z          jmp           #__L0002                    
        IF_C          xor           __temp5,#1                  
                      mov           __temp3,#0                  
                      min           __temp2,#1                  
    __L0003                                                     
                      add           __temp3,#1                  
                      shl           __temp2,#1 WC               
        IF_NC         jmp           #__L0003                    
                      rcr           __temp2,#1                  
    __L0004                                                     
                      cmpsub        __temp1,__temp2 WC          
                      rcl           __temp4,#1                  
                      shr           __temp2,#1                  
                      djnz          __temp3,#__L0004            
                      test          __temp5,#1 WZ               
        IF_NZ         neg           __temp4,__temp4             
        IF_NZ         neg           __temp1,__temp1             
    __L0002                                                     
                      mov           __param1,__temp4            
    
    
  • BRBR Posts: 92
    edited 2011-03-03 19:15
    See attached rabble of ASM snippets...lines 7-39. Also lines 398-449.

    Sorry about the thread links embedded in the comments, they're from the old forum. You'll have to use Phil's thread converter to see the original threads.

    I dunno why there isn't a nice sticky somewhere that compiles a bunch of useful ASM snippets in one place...
  • Cluso99Cluso99 Posts: 18,069
    edited 2011-03-04 01:45
    IIRC the spin interpreter is signed mult and divide. You can find the original code of the interpreter posted by Chip. There is a faster version in my spin interpreter (IIRC Chip provided the mult improvement - its noted in the code anyway).
    To find may faster spin interpreter, follow the Tools link in my signature.
  • Graham StablerGraham Stabler Posts: 2,510
    edited 2011-03-04 04:35
    Thanks guys, I've not had a chance to follow up the leads but it looks really promising, I'll get back to you when I can, typically I have lots of paper work to do instead of coding :(

    Graham
Sign In or Register to comment.