flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
revolution 22 Feb 2013, 06:04
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 |
|||
![]() |
|
cwpjr 22 Feb 2013, 22:02
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 |
|||
![]() |
|
cwpjr 22 Feb 2013, 22:07
I'm not familiar with what the ip is.
|
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.