flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Non-x86 architectures > [ARM] Math primitive SW needed for m0 from m3 UDIV and MLS

Author
Thread Post new topic Reply to topic
cwpjr



Joined: 03 Jul 2012
Posts: 45
[ARM] Math primitive SW needed for m0 from m3 UDIV and MLS
I completed a M3 project with much help from this forum. Thanks again.

Now I am tasked with porting to the M0 (NXP 1114).

So upfront I suck at math. That is what got me in microprocessors!

My port is stalled at commented out UDIV and MLS opcodes that don't exist in MO...

Any help including equivalent code to tutorials on how to do the math would be appreciated by me.

Thanks in Advance.

P.S. I hope Revolution is in good health and spirits and I am still scared to solve your puzzle! Surprised

_________________
Developing ARM Electronic Hobby Bench Stuff!
Post 19 Feb 2013, 23:50
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 12129
Location: Another plane of existence
For UDIV you could modify this ARM code for THUMB. Be careful about the size of the repeat loop, with thumb code you might need to check the output to see that you get what is expected with regard to instruction lengths:

Code:
divide_unsigned:
    numerator equ r0
    denominator equ r1
        cmp     denominator,0
        beq     .divide_by_0
        subs    ip,numerator,denominator
        blo     .smaller_than_1
        cmp     ip,denominator
        blo     .is_1
        mov     r3,numerator
        clz     ip,numerator
        clz     r2,denominator
        sub     ip,r2,ip
        rsbs    ip,ip,31
        addne   ip,ip,ip,lsl 1                  ;ip * 3
        mov     r0,0
        addne   pc,pc,ip,lsl 2
        nop
        .rotate = 32
        while .rotate>0
                .rotate = .rotate - 1
                cmp     r3,denominator,lsl .rotate
                adc     r0,r0,r0
                subcs   r3,r3,denominator,lsl .rotate
        end while
        mov     r1,r3                           ;remainder
        mov     pc,lr
    .smaller_than_1:
        mov     r1,numerator                    ;remainder
        mov     r0,0                            ;result
        mov     pc,lr
    .is_1:
        sub     r1,numerator,denominator        ;remainder
        mov     r0,1                            ;result
        mov     pc,lr
    .divide_by_0:
        mov     r1,numerator                    ;remainder
        mov     r0,-1                           ;result = infinity
        mov     pc,lr

For MLS it should be no difficulty to use two instructions; MUL then SUB. I can't see how that is causing a problem unless I misunderstand your description.
Post 22 Feb 2013, 06:04
View user's profile Send private message Visit poster's website Reply with quote
cwpjr



Joined: 03 Jul 2012
Posts: 45
This gets put in an interpreter wrapper so I should be able to test effectively. I also am blessed to have a black box model to check against.

Thanks so much!

Clyde
Post 22 Feb 2013, 22:02
View user's profile Send private message Reply with quote
cwpjr



Joined: 03 Jul 2012
Posts: 45
I'm not familiar with what the ip is.
Post 22 Feb 2013, 22:07
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2013, Tomasz Grysztar.