|
|
1.1 ! root 1: # ! 2: # udiv - unsigned division for vax-11 ! 3: # ! 4: # arguments: dividend, divisor. ! 5: # result: quotient. ! 6: # uses r0-r2 ! 7: # ! 8: # If 1 < divisor <= 2147483647, zero-extend the dividend ! 9: # to 64 bits and let ediv do the work. If the divisor is 1, ! 10: # ediv will overflow if bit 31 of the dividend is on, so ! 11: # just return the dividend unchanged. If the divisor is 0, ! 12: # do the ediv also, so it will generate the proper exception. ! 13: # All other values of the divisor have bit 31 on: in this case ! 14: # the quotient must be 0 if divisor > dividend, and 1 otherwise, ! 15: # provided that the comparison is made as unsigned. ! 16: # ! 17: .text ! 18: .align 1 ! 19: .globl udiv ! 20: udiv: .word 0x0000 ! 21: movl 4(ap),r0 # Dividend ! 22: movl 8(ap),r2 # Divisor ! 23: jeql 1f # If divisor=0, force exception ! 24: cmpl r2,$1 # If divisor <= 1 (signed), ! 25: jleq 2f # no division is necessary ! 26: 1: clrl r1 # Zero-extend the dividend ! 27: ediv r2,r0,r0,r2 # Divide. q->r0, r->r2 (discarded) ! 28: ret ! 29: 2: jeql 4f # If divisor=1, return dividend ! 30: cmpl r0,r2 # Unsigned comparison between ! 31: jgequ 3f # dividend and divisor ! 32: clrl r0 # Dividend < divisor, return 0 ! 33: ret ! 34: 3: movl $1,r0 # Dividend >= divisor, return 1 ! 35: 4: ret ! 36: ! 37:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.