Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .DEF rd1l = R2 ; LSB 16-bit-number to be divided делимое младший
- .DEF rd1h = R1 ; MSB 16-bit-number to be divided делимое старший
- .DEF rd1u = R3 ; interim register
- .DEF rd2 = R4 ; 8-bit-number to divide with делитель
- .DEF rel = R6 ; LSB result результат младший
- .DEF reh = R5 ; MSB result результат старший
- div16:
- clr rd1u ; clear interim register
- clr reh ; clear result (the result registers
- clr rel ; are also used to count to 16 for the
- inc rel ; division steps, is set to 1 at start)
- div8a:
- clc ; clear carry-bit
- rol rd1l ; rotate the next-upper bit of the number
- rol rd1h ; to the interim register (multiply by 2)
- rol rd1u
- brcs div8b ; a one has rolled left, so subtract
- cp rd1u,rd2 ; Division result 1 or 0?
- brcs div8c ; jump over subtraction, if smaller
- div8b:
- sub rd1u,rd2; subtract number to divide with
- sec ; set carry-bit, result is a 1
- rjmp div8d ; jump to shift of the result bit
- div8c:
- clc ; clear carry-bit, resulting bit is a 0
- div8d:
- rol rel ; rotate carry-bit into result registers
- rol reh
- brcc div8a ; as long as zero rotate out of the result
- ; registers: go on with the division loop
- ; End of the division reached
- RET
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement