New version DRDOS 7.01.7 & 7.01.8 (Announce)
> > You can convert the code below for Int64 to Int32 and replace the 32-bit
> > registers with 16-bit registers to skip the 32-time loop.
>
> Thanks for the code. I can not convert it one by one, because the DRSYS
> div32 procedure also returns the remainder, but I get the idea...
>
> However, for now I decided to leave the shifting algorithm as it is, mainly
> because it is a code path not often taken, and i want to fix more things
> than I break
>
> The div32 procedure is mainly called with 512 as the divisor (to calculate
> sectors and offsets into the FAT). So 99% of the time, the optimized 16-bit
> shortcut is used, I guess.
>
> The current version is here:
> https://github.com/SvarDOS/edrdos/blob/8fa1acd6576...9fd7f283a9119e3494036ce7/drdos/bdevio.a86#L2029
>
> It should yield correct results (kernel behaves as expected). But perhaps
> someone with more assembly experience might double-check (from div32_full
> on it is the original code).
div32: ; 32-bit division
;--------
; On Entry:
; 32-bit dividend & divisor on stack
; space for 32-bit quotient & remainder reserved on stack
; SP-16
; On Exit:
; 32-bit quotient & remainder on stack
; SP-16
; Modified registers:
; AX,CX,DX,BP
mov bp,sp ; base address of temporary variables
add bp,2
Twice `inc bp` is cheaper in code space.
xor dx,dx
cmp 10[bp],dx ; if divisor high != 0 => 32bit div
jne div32_full
mov cx,8[bp] ; CX <- divisor low
mov 2[bp],dx ; clear remainder high, guaranteed to
; ...be zero here
mov ax,14[bp] ; AX <- dividend high
test ax,ax ; if both dividend and divisor are
; ...16bit, perform one 16bit division
jz div16 ; ...else perform two 16bit divisions
dix2x16:
div cx ; divide dividend high by divisor low
div16: mov 6[bp],ax ; 6[bp] <- quotient high
mov ax,12[bp] ; AX <- dividend low
div cx ; divide dividend low by divisor low
; ...DX -> remainder of previous
; ... division or zero
mov [bp],dx ; store remainder low
mov 4[bp],ax ; store quotient low
ret
div32_full:
Looks good to me. Dispatching to either the two-step division or a single one is new to me. I do think you could save code space at the cost of some performance by just dropping the test and jz. Zero divided by CX is always zero.
---
l
Complete thread:
- New version DRDOS 7.01.7 & 7.01.8 - CandyMan, 21.07.2023, 15:40 (Announce)
- New version DRDOS 7.01.7 & 7.01.8 - glennmcc, 21.07.2023, 20:13
- New version DRDOS 7.01.7 & 7.01.8 - nico7550, 21.07.2023, 20:27
- New version DRDOS 7.01.7 & 7.01.8 - fritz.mueller, 21.07.2023, 20:29
- New version DRDOS 7.01.7 & 7.01.8 - glennmcc, 21.07.2023, 20:34
- New version DRDOS 7.01.7 & 7.01.8 - CandyMan, 21.07.2023, 22:18
- New version DRDOS 7.01.7 & 7.01.8 - nico7550, 21.07.2023, 22:45
- New version DRDOS 7.01.7 & 7.01.8 - nico7550, 22.07.2023, 09:40
- New version DRDOS 7.01.7 & 7.01.8 - CandyMan, 22.07.2023, 23:06
- New version DRDOS 7.01.7 & 7.01.8 - nico7550, 22.07.2023, 09:40
- New version DRDOS 7.01.7 & 7.01.8 - nico7550, 21.07.2023, 22:45
- New version DRDOS 7.01.7 & 7.01.8 - fritz.mueller, 21.07.2023, 20:29
- New version DRDOS 7.01.7 & 7.01.8 - Guti, 24.07.2023, 11:08
- New version DRDOS 7.01.7 & 7.01.8 - CandyMan, 25.07.2023, 15:04
- New version DRDOS 7.01.7 & 7.01.8 - nico7550, 26.07.2023, 15:19
- New version DRDOS 7.01.7 & 7.01.8 - Guti, 30.07.2023, 11:12
- New version DRDOS 7.01.7 & 7.01.8 - nico7550, 26.07.2023, 15:19
- New version DRDOS 7.01.7 & 7.01.8 - DieTotenByte, 30.07.2023, 01:09
- New version DRDOS 7.01.7 & 7.01.8 - CandyMan, 30.07.2023, 10:55
- New version DRDOS 7.01.7 & 7.01.8 - CandyMan, 03.08.2023, 21:46
- New version DRDOS 7.01.7 & 7.01.8 - CandyMan, 10.08.2023, 11:09
- New version DRDOS 7.01.7 & 7.01.8 - ecm, 10.08.2023, 15:52
- New version DRDOS 7.01.7 & 7.01.8 - CandyMan, 10.08.2023, 19:21
- New version DRDOS 7.01.7 & 7.01.8 - CandyMan, 11.08.2023, 10:47
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - ecm, 12.08.2023, 21:13
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - CandyMan, 13.08.2023, 11:16
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - ecm, 13.08.2023, 13:59
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - ecm, 13.08.2023, 14:39
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - CandyMan, 13.08.2023, 19:23
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - ecm, 13.08.2023, 21:41
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - CandyMan, 13.08.2023, 22:41
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - ecm, 13.08.2023, 23:18
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - CandyMan, 13.08.2023, 23:51
- EDR-DOS development - ecm, 14.08.2023, 07:18
- EDR-DOS development - CandyMan, 14.08.2023, 09:43
- EDR-DOS development - ecm, 15.08.2023, 20:49
- EDR-DOS development - ecm, 15.08.2023, 20:51
- EDR-DOS development - ecm, 19.08.2023, 19:56
- EDR-DOS development - ecm, 15.08.2023, 20:49
- EDR-DOS development - CandyMan, 14.08.2023, 14:35
- EDR-DOS development - bretjohn, 14.08.2023, 21:12
- EDR-DOS development - CandyMan, 15.08.2023, 11:49
- EDR-DOS development - bretjohn, 14.08.2023, 21:12
- EDR-DOS development - CandyMan, 14.08.2023, 09:43
- EDR-DOS development - ecm, 15.08.2023, 20:46
- EDR-DOS development - CandyMan, 15.08.2023, 22:29
- EDR-DOS development - ecm, 16.08.2023, 10:06
- EDR-DOS development - CandyMan, 16.08.2023, 12:54
- EDR-DOS development - ecm, 16.08.2023, 18:19
- EDR-DOS development - CandyMan, 16.08.2023, 18:55
- EDR-DOS development - ecm, 16.08.2023, 18:19
- EDR-DOS development - CandyMan, 16.08.2023, 12:54
- EDR-DOS development - ecm, 16.08.2023, 10:06
- EDR-DOS development - CandyMan, 15.08.2023, 22:29
- EDR-DOS development - ecm, 20.08.2023, 01:35
- EDR-DOS development - CandyMan, 21.08.2023, 00:27
- EDR-DOS development - ecm, 21.08.2023, 22:54
- EDR-DOS development - ecm, 29.08.2023, 17:49
- EDR-DOS development - ecm, 29.08.2023, 18:26
- EDR-DOS development - ecm, 29.08.2023, 18:32
- EDR-DOS development - ecm, 29.08.2023, 18:49
- EDR-DOS development - ecm, 29.08.2023, 18:32
- EDR-DOS development - Rugxulo, 29.08.2023, 23:28
- EDR-DOS development - ecm, 30.08.2023, 09:47
- EDR-DOS development - ecm, 29.08.2023, 18:26
- EDR-DOS development - roytam, 29.12.2023, 15:33
- EDR-DOS development - CandyMan, 21.08.2023, 00:27
- EDR-DOS development - ecm, 14.08.2023, 07:18
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - CandyMan, 13.08.2023, 23:51
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - ecm, 13.08.2023, 23:18
- EDR-DOS repository - Ro2003, 10.10.2023, 16:24
- EDR-DOS repository - ecm, 12.10.2023, 19:04
- EDR-DOS repository - Ro2003, 13.10.2023, 08:23
- EDR-DOS repository - nico7550, 13.10.2023, 15:53
- EDR-DOS repository - Single-file kernel load - ecm, 13.10.2023, 18:16
- EDR-DOS repository - Single-file kernel load - ecm, 13.10.2023, 18:23
- EDR-DOS repository - Ro2003, 13.10.2023, 08:23
- EDR-DOS repository - ecm, 12.10.2023, 19:04
- EDR-DOS version number - Ro2003, 10.10.2023, 16:32
- EDR-DOS version number - ecm, 12.10.2023, 19:08
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - CandyMan, 13.08.2023, 22:41
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - ecm, 13.08.2023, 21:41
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - ecm, 13.08.2023, 13:59
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - CandyMan, 13.08.2023, 11:16
- EDR-DOS bugs on int 21h functions 7142h and 71A6h - ecm, 12.08.2023, 21:13
- New version DRDOS 7.01.7 & 7.01.8 - ecm, 10.08.2023, 15:52
- New version DRDOS 7.01.7 & 7.01.8 - glennmcc, 13.08.2023, 22:19
- What ever happened to Udo ? - glennmcc, 29.08.2023, 23:04
- New version DRDOS 7.01.7 & 7.01.8 - Ro2003, 10.10.2023, 16:10
- New version DRDOS 7.01.7 & 7.01.8 - glennmcc, 10.10.2023, 21:35
- New version DRDOS 7.01.7 & 7.01.8 - boeckmann, 12.12.2023, 17:04
- New version DRDOS 7.01.7 & 7.01.8 - ecm, 12.12.2023, 18:47
- New version DRDOS 7.01.7 & 7.01.8 - boeckmann, 12.12.2023, 21:15
- New version DRDOS 7.01.7 & 7.01.8 - boeckmann, 12.12.2023, 21:27
- New version DRDOS 7.01.7 & 7.01.8 - CandyMan, 13.12.2023, 16:58
- New version DRDOS 7.01.7 & 7.01.8 - boeckmann, 14.12.2023, 18:00
- New version DRDOS 7.01.7 & 7.01.8 - ecm, 14.12.2023, 20:58
- New version DRDOS 7.01.7 & 7.01.8 - boeckmann, 16.12.2023, 21:52
- New version DRDOS 7.01.7 & 7.01.8 - ecm, 30.12.2023, 14:27
- New version DRDOS 7.01.7 & 7.01.8 - boeckmann, 01.01.2024, 13:57
- New version DRDOS 7.01.7 & 7.01.8 - ecm, 30.12.2023, 14:27
- New version DRDOS 7.01.7 & 7.01.8 - boeckmann, 16.12.2023, 21:52
- New version DRDOS 7.01.7 & 7.01.8 - ecm, 14.12.2023, 20:58
- New version DRDOS 7.01.7 & 7.01.8 - boeckmann, 14.12.2023, 18:00
- New version DRDOS 7.01.7 & 7.01.8 - CandyMan, 13.12.2023, 16:58
- New version DRDOS 7.01.7 & 7.01.8 - boeckmann, 12.12.2023, 21:27
- New version DRDOS 7.01.7 & 7.01.8 - boeckmann, 12.12.2023, 21:15
- New version DRDOS 7.01.7 & 7.01.8 - ecm, 12.12.2023, 18:47