?? bitops.asm
字號:
;Subject: Quick routines for 16-bit large-integer arithmetic Basic library.
;Author : Sjoerd.J.Schaper - vspickelen@zonnet.nl
;Date : 07-07-2004
;Code : Assembly
.MODEL Medium, Basic
.386
MB equ 08000h ;storage base
M1 equ 07FFFh ;masks MB - 1
M2 equ 03FFF8000h ;(MB - 1)* MB
LB equ 0Fh ;bitlength
.CODE
PUBLIC EstQ ;n(j, ..)* MB^2 + n(j-1, ..)* MB + n(j-2, ..)
EstQ PROC ;45-bit dividend \ 30-bit divisor,
mov bx,sp ;15-bit quotient is returned in ax
push ds
push si
xor edx,edx
mov si,[bx+4] ;point si to the long divisor
mov ecx,[si] ;load value
lds si,[bx+6] ;point ds:si to h.o. array element
mov dx,[si] ;load it
mov eax,[si-4] ;load both l.o. array elements
mov bx,ax ;save low word, msb is 0
shr eax,1 ;shift-right dword
and eax,M2 ;mask off bits 0..14
or ax,bx ;paste back low word
xor ebx,ebx
shr dx,1 ;shift-right 2 bits in edx:ebx
rcr ebx,1
shr dx,1
rcr ebx,1
or eax,ebx ;paste in 2 high bits with l.o. elements in 0..29
div ecx ;edx:eax / ecx integer division
mov edx,MB
cmp edx,eax ;check if base > quotient
ja eind
mov ax,M1 ;if not, return base - 1
eind:
pop si
pop ds
retf 6
EstQ ENDP
;This routine does not check for segment crossings,
;so do not compile the LargeInt-library with the /Ah switch,
;or replace EstQ with its Basic counterpart, if needed.
PUBLIC SftL
SftL PROC
push bp
mov bp,sp
mov bx,[bp+6] ;move bits-to-shift into cx
mov cx,[bx]
mov bx,[bp+8] ;get value-to-shift address
shl dword ptr[bx],cl ;shift-left
pop bp
retf 4
SftL ENDP
PUBLIC SftR
SftR PROC
push bp
mov bp,sp
mov bx,[bp+6]
mov cx,[bx]
mov bx,[bp+8]
shr dword ptr[bx],cl ;shift-right
pop bp
retf 4
SftR ENDP
;As SftL and SftR reference 16-bit offset addresses only,
;they accept no $Dynamic array elements as argument.
END
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -