flat assembler
Message board for the users of flat assembler.
Index
> DOS > Very curious about something I read. |
Author |
|
revolution 08 Oct 2006, 08:39
Quote: can you divide by ten with only shifts,addition,and subtraction? For the specific case of division by ten we can do better than the div instruction by multiplying by an approximate reciprocal and then shifting down to get the quotient. There are already some topics on this board showing how it is done. |
|||
08 Oct 2006, 08:39 |
|
Goplat 08 Oct 2006, 17:36
On the 6502 processor that was used in the C64, Apple II, and various other computers there was not only no divide, but no multiply either. A common way of dividing was doing something like this:
Code: LDA #0 LDX #8 divlp: ASL number ROL CMP #10 BCC low SBC #10 INC number low: DEX BNE divlp This would be about the x86 equivalent of it (though of course it would be pointless to actually do this) Code: mov al,0 mov cx,16 divlp: shl dx,1 rcl al,1 cmp al,10 jb low sub al,10 inc dx low: loop divlp |
|||
08 Oct 2006, 17:36 |
|
2 10 Oct 2006, 00:54
That's cool,but I'm a little lost. What does rcl do and why is dx left shifted?
|
|||
10 Oct 2006, 00:54 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.