# Re: Help needed

From: Martijn van Buul (martijnb_at_stack.nl)
Date: 2001-09-03 12:38:17

```Ruud Baltissen wrote:
> I first have to find out what LBA exactly is.

LBA doesn't describe a disk as tracks, heads and sectors, but as your
linear encoding. SCSI does this, for instance. Modern IDE disks do this
too, since the THS-mapping doesn't have any physical meaning anymore -
it's a backward-compatibility thing.

> If LBA deals with 256 sectors and 256 heads, then LBA is equivalent to
> lineair coding which simplifies things a lot.

Well, most of the time it's something like 256 sectors and 64 heads. But
that doesn't make much of a difference. It's *one* way of achieving the same
goal.

> > block(t,h,s)= (t * HDHEADS + h ) * HDSECT + s
>
> That is correct. But now I need someone willing to translate this equation
> in ML. The only way _I_ know how to do multiplications is by doing a loop of
> addititions. And I know that this certainly not the fastest way. So therefor
> my plea for help.

You can use the fact that (a+b)*c = a*c + b*c.

For instance: a*13 is a*8 + a*4 + a*1.

Multiplications by a factor of 2 is simple - it's nothing more than shifting
the operand. Since every number can be written as a sum of 'factors of 2'
(That's exactly what binary encoding is all about), you can execute any

The above example can even be written as
(((a)*2 + a)*2 + 0)*2 + a

Consider the (integer) multiplication a*b (with b being 8-bit) in
pseudo-assembly:

result = 0
count = 8
loop:  asl result		; Multiply the result with 2.
asl b			; Move the MSB into carry
bcc next			; If carry set, then add, otherwise ignore.
clc
result = result + a
next:  dec count		; decrease counter
bne loop			; if counter is zero, then done.

caveats:

* The result will be more than 8 bits, so you'll need to shift over multiple
bytes. 'asl result' will have to be something like
asl result0
rol result1
rol result2
rol result3

* Same applies for the addition.

> Same for the division-stuff.

Division can be done with a 'staartdeling'. Don't know the english word for
that, sorry.

I think I have a halfway efficient algorithm in one of my college textbooks.
I'd have to look it up - can't come up with something right now.

--
Martijn van Buul -  Pino@dohd.org - http://www.stack.nl/~martijnb/
Geek code: G--  - Visit OuterSpace: mud.stack.nl 3333
Kees J. Bot: The sum of CPU power and user brain power is a constant.

Message was sent through the cbm-hackers mailing list
```

Archive generated by hypermail 2.1.1.