Category : Files from Magazines
Archive   : DDJ0589.ZIP
Filename : STRUCT.ASC

 
Output of file : STRUCT.ASC contained in archive : DDJ0589.ZIP
_Language-Independent Dynamic Pseudostructures_
by Bruce Tonkin

[LISTING ONE]


DEFDBL A-Z
DIM i AS LONG
k = 1# / LOG(2#) 'convert to base 2
OPEN "o", 1, "c:temp"
FOR i = 1 TO 100000
t = t + LOG(i) * k
IF i MOD 10000 = 0 OR i < 11 OR i = 100 OR
(i < 10000 AND i MOD 1000 = 0) THEN
PRINT #1, i, t / i, (LOG(i * .737) * k) - 1
NEXT i


[LISTING TWO]

.MODEL MEDIUM
.CODE
PUBLIC convint
;convint written by Bruce W. Tonkin on 8-14-88 for use with QB 4.0 & MASM 5.0
;convint will convert a binary 2-byte integer passed as a string into
;a string with the bytes re-ordered so an ASCII-order sort will sort in
;numeric order. It is called with:
;call convint (x$)
;where x$ is the string to convint (in the current data segment).
;The routine does not check for a zero length of the passed string.
convint PROC
push bp ;save old BP
mov bp,sp ;Set framepointer to old stack
mov bx,[bp+6] ;bx points to string length, which we don't need
mov bx,[bx]+2 ;move the string address to bx
mov dh,byte ptr [bx] ;get first byte
inc bx ;point to next byte
mov dl,byte ptr [bx] ;get second byte
xor dl,080h ;invert the sign bit
mov byte ptr [bx],dh ;store first byte where second was
dec bx ;now for modified second byte
mov byte ptr [bx],dl ;store where first byte went
pop bp ;restore old base pointer
ret 2 ;clear 2 bytes of parameters on return
convint ENDP
END


[LISTING THREE]

.MODEL MEDIUM
.CODE
PUBLIC convlong
;convlong written by Bruce W. Tonkin on 8-14-88 for use with QB 4.0 & MASM 5.0
;convlong will convert a long integer passed as a packed 4-byte string into
;a string with the bytes re-ordered so an ASCII-order sort will sort in
;numeric order. It is called with:
;call convlong (x$)
;where x$ is the string to convlong (in the current data segment).
;The routine does not check for a zero length of the passed string.
convlong PROC
push bp ;save old BP
mov bp,sp ;Set framepointer to old stack
mov bx,[bp+6] ;address of string length isn't needed
mov bx,[bx]+2 ;move the string address to bx
mov dh,byte ptr [bx] ;get first byte
inc bx ;point to next byte
mov dl,byte ptr [bx] ;get second byte
inc bx ;point to third byte
mov ah,byte ptr [bx] ;get third byte
inc bx ;point to last byte
mov al,byte ptr [bx] ;get fourth and last byte
mov byte ptr [bx],dh ;store first byte in fourth spot
dec bx ;point to third spot
mov byte ptr [bx],dl ;store former second byte
dec bx ;point to second spot
mov byte ptr [bx],ah ;store former third byte
dec bx ;point to former first byte spot
xor al,080h ;invert the sign bit
mov byte ptr [bx],al ;and store the fourth byte where first was
pop bp ;restore old base pointer
ret 2 ;clear 2 bytes of parameters on return
convlong ENDP
END


[LISTING FOUR]


.MODEL MEDIUM
.CODE
PUBLIC convof
;convof written by Bruce W. Tonkin on 8-14-88 for use with QB 4.0 & MASM 5.0
;convof will convert a Microsoft Binary format floating-point number passed as
;a string into a string with the bytes re-ordered so an ASCII-order sort will
;sort in numeric order. It is called with:
;call convof (x$)
;where x$ is the string to convof (in the current data segment).
;The routine does not check for a zero length of the passed string.
convof PROC
push bp ;save old BP
mov bp,sp ;Set framepointer to old stack
mov bx,[bp+6] ;move the string length to cx
mov cx,[bx]
push si ;save si--used by routine
mov ax,cx ;copy cx into ax
dec ax ;subtract one from ax
shr cx,1 ;divide cx by two
mov bx,[bx]+2 ;move the string address to bx
push bx ;save that address
add bx,ax ;look at the end of the string
cmp byte ptr [bx],0 ;check the first byte
pop bx ;restore string pointer
jnz va ;last byte was not zero
mov byte ptr [bx],081h ;it was zero, so make first byte 129
dec cx ;and make all other bytes zero
inc bx ;point to next byte
vt: mov byte ptr [bx],0 ;clear it
inc bx ;point to next byte
loop vt ;decrement cx and loop until done
jmp vi ;then go to the end and restore registers
va: mov si,bx ;set up si to point to bytes to swap
add si,ax ;points to last byte of string
iv: mov dl,[bx] ;first byte of string to dl
mov dh,[si] ;second byte to dh
mov [bx],dh ;and save it
mov [si],dl ;swap two bytes to reverse order
inc bx ;point to next byte
dec si ;and get ready for corresponding byte to move
loop iv ;dec cx and repeat until all bytes were swapped
mov bx,[bp+6] ;restore the original string pointer
mov cx,[bx] ;length to cx
mov bx,[bx]+2 ;location in bx
;at this point, all the bytes in the string have been put in reverse order
mov ah,[bx] ;save first string byte into ah
inc bx ;point to second byte
mov al,[bx] ;second byte into al
dec bx ;now point to first byte again
mov dh,ah ;save copies
mov dl,al ;of both bytes
push cx ;save cx=length
mov cl,7 ;get ready to rotate
shl ah,cl ;move low bit left 7 positions for first byte
shr al,cl ;move high bit right 7 positions for second byte
pop cx ;restore count in cx
and dl,07fh ;mask high bit for byte two
add dl,ah ;low bit of byte one to high bit of byte two
shr dh,1 ;shift byte one right one bit
or dh,080h ;and turn high bit on for byte one
cmp al,1 ;check status of former high bit on byte two
jnz v ;high bit wasn't set
push bx ;save string pointer
xor dx,0ffffh ;invert first two bytes
inc bx ;point to second byte
inc bx ;point to third byte
dec cx ;decrement counter accordingly
dec cx
vv: xor byte ptr [bx],0ffh ;invert successive bytes three to end
inc bx ;point to next byte
loop vv ;decrement cx and repeat until done
pop bx ;restore string pointer
v: mov byte ptr [bx],dh ;save altered byte one
inc bx
mov byte ptr [bx],dl ;and byte two
vi: pop si ;restore si
pop bp ;restore old base pointer
ret 2 ;clear 2 bytes of parameters on return
convof ENDP
END


[LISTING FIVE]



.MODEL MEDIUM
.CODE
PUBLIC convnf
;convnf written by Bruce W. Tonkin on 8-13-88 for use with QB 4.0 & MASM 5.0
;convnf will convert an IEEE floating-point number passed as a string into
;a string with the bytes re-ordered so an ASCII-order sort will sort in
;numeric order. It is called with:
;call convnf (x$)
;where x$ is the string to convnf (in the current data segment).
;The routine does not check for a zero length of the passed string.
convnf PROC
push bp ;save old BP
mov bp,sp ;Set framepointer to old stack
mov bx,[bp+6] ;move the string length to cx
mov cx,[bx]
push si ;save si--used by routine
mov ax,cx ;copy cx into ax
dec ax ;subtract one from ax
shr cx,1 ;divide cx by two
mov bx,[bx]+2 ;move the string address to bx
mov si,bx ;set up si to point to bytes to swap
add si,ax ;points to last byte of string
iv: mov dl,[bx] ;first byte of string to dl
mov dh,[si] ;second byte to dh
mov [bx],dh ;and save it
mov [si],dl ;swap two bytes to reverse order
inc bx ;point to next byte
dec si ;and get ready for corresponding byte to move
loop iv ;dec cx and repeat until all bytes were swapped
mov bx,[bp+6] ;restore the original string pointer
mov cx,[bx] ;length to cx
mov bx,[bx]+2 ;location in bx
test byte ptr [bx],080h ;check the high-order bit of the first byte
jnz v ;high-order bit was set
xor byte ptr [bx],080h ;fix the first byte
jmp vi ;and done
v: xor byte ptr [bx],0ffh ;invert all the bytes in the string
inc bx ;next location
loop v ;dec cx and repeat until all bytes have been inverted
vi: pop si ;restore si
pop bp ;restore old base pointer
ret 2 ;clear 2 bytes of parameters on return
convnf ENDP
END



[LISTING SIX]


.MODEL MEDIUM
.CODE
PUBLIC INVERT
;INVERT written by Bruce W. Tonkin on 8-13-88 for use with QB 4.0 & MASM 5.0
;INVERT will xor all the bytes in a string, thus allowing it to be sorted in
;descending order. It is called with:
;call INVERT (x$)
;where x$ is the string to invert (in the current data segment).
;The routine does not check for a zero length of the passed string.
INVERT PROC
push bp ;save old BP
mov bp,sp ;Set framepointer to old stack
mov bx,[bp+6] ;move the string length to cx
mov cx,[bx]
mov bx,[bx]+2 ;put the string address into bx
iv: xor byte ptr [bx],0ffh ;convert the first byte
inc bx
loop iv ;decrement cx and repeat until done
pop bp ;restore old base pointer
ret 2 ;clear 2 bytes of parameters on return
INVERT ENDP
END


[LISTING SEVEN]


defint a-z
dim t!(17)
dim t$(17)
open"o",1,"bench.dat"
cls
t!(0)=timer
for i=1 to 100
for j=1 to 1000
next j
next i
t!(0)=timer-t!(0) 'time for bare loop
t$(0)="Raw integer loop"

d$=mki$(-13)
t!(1)=timer
for i=1 to 100
for j=1 to 1000
CALL convint(d$)
next j
next i
t!(1)=timer-t!(1) 'time for integer conversions
t$(1)="Integer conversion"

d$=mkl$(-130000)
t!(2)=timer
for i=1 to 100
for j=1 to 1000
CALL convlong(d$)
next j
next i
t!(2)=timer-t!(2) 'time for long integer conversions
t$(2)="Long integer conversion"

d$=string$(4,204)
t!(3)=timer
for i=1 to 100
for j=1 to 1000
CALL convof(d$)
next j
next i
t!(3)=timer-t!(3) 'time for old single-precision float conversion
t$(3)="Old single float conversion"

d$=string$(8,204)
t!(4)=timer
for i=1 to 100
for j=1 to 1000
CALL convof(d$)
next j
next i
t!(4)=timer-t!(4) 'time for old double-precision float conversion
t$(4)="Old double float conversion"

d$=mks$(-13.0405)
t!(5)=timer
for i=1 to 100
for j=1 to 1000
CALL convnf(d$)
next j
next i
t!(5)=timer-t!(5) 'time for IEEE single-precision float conversion
t$(5)="IEEE single float conversion"

d$=mkd$(-13.04050607)
t!(6)=timer
for i=1 to 100
for j=1 to 1000
CALL convnf(d$)
next j
next i
t!(6)=timer-t!(6) 'time for IEEE double-precision float conversion
t$(6)="IEEE double float conversion"

t!(7)=timer
for i=1 to 100
for j=1 to 1000
CALL invert(d$)
next j
next i
t!(7)=timer-t!(7) 'time for inverting 8 bytes
t$(7)="Invert 8 bytes"

a$="AB"
b$="AX"
t!(8)=timer
for i=1 to 100
for j=1 to 1000
if a$>b$ then j=j+1
next j
next i
t!(8)=timer-t!(8) 'time to compare two-byte strings
t$(8)="Compare two-byte strings"

a=100
b=200
t!(9)=timer
for i=1 to 100
for j=1 to 1000
if a>b then j=j+1
next j
next i
t!(9)=timer-t!(9) 'time to compare two integers
t$(9)="Compare two integers"

a$="ABCD"
b$="ABCX"
t!(10)=timer
for i=1 to 100
for j=1 to 1000
if a$>b$ then j=j+1
next j
next i
t!(10)=timer-t!(10) 'time to compare two 4-byte strings
t$(10)="Compare two four-byte strings"

a!=100.01!
b!=200.01!
t!(11)=timer
for i=1 to 100
for j=1 to 1000
if a!>b! then j=j+1
next j
next i
t!(11)=timer-t!(11) 'time to compare two single floats
t$(11)="Compare two single floats"

a#=100.01#
b#=200.01#
t!(12)=timer
for i=1 to 100
for j=1 to 1000
if a#>b# then j=j+1
next j
next i
t!(12)=timer-t!(12) 'time to compare two double floats
t$(12)="Compare two double floats"

a$="ABCDEFGH"
b$="ABCDEFGX"
t!(13)=timer
for i=1 to 100
for j=1 to 1000
if a$>b$ then j=j+1
next j
next i
t!(13)=timer-t!(13) 'time to compare two 8-byte strings
t$(13)="Compare two 8-byte strings"

a&=123456&
b&=123457&
t!(14)=timer
for i=1 to 100
for j=1 to 1000
if a&>b& then j=j+1
next j
next i
t!(14)=timer-t!(14) 'time to compare two long integers
t$(14)="Compare two long integers"

a$="ABCDEFGHIJKLMNOPQRST"
b$="ABCDEFGHIJKLMNOPQRSX"
t!(15)=timer
for i=1 to 100
for j=1 to 1000
if a$>b$ then j=j+1
next j
next i
t!(15)=timer-t!(15) 'time to compare two 20-byte strings
t$(15)="Compare two 20-byte strings"

a$="ABCDEFGHIJKLMNOPQRST"
b$="XBCDEFGHIJKLMNOPQRST"
t!(16)=timer
for i=1 to 100
for j=1 to 1000
if a$>b$ then j=j+1
next j
next i
t!(16)=timer-t!(16) 'best? time to compare two 20-byte strings
t$(16)="Compare two 20-byte strings (best?)"

t!(17)=timer
for i=1 to 100
for j=1 to 1000
call dummy(a,b,c)
next j
next i
t!(17)=timer-t!(17) 'time to make a call with three parameters
t$(17)="Three-integer-parameter call"

print t$(0),t!(0)
print #1,t$(0),t!(0)
for i=1 to 17
t!(i)=t!(i)-t!(0)
print t$(i),t!(i)
print #1,t$(i),t!(i)
next i

sub dummy(a,b,c) static
c=1
end sub




  3 Responses to “Category : Files from Magazines
Archive   : DDJ0589.ZIP
Filename : STRUCT.ASC

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/