home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
terabyteunlimited.com
/
2014.06.terabyteunlimited.com.tar
/
terabyteunlimited.com
/
pushenve.txt
< prev
next >
Wrap
Text File
|
2010-09-22
|
3KB
|
102 lines
Back in the good ole days there was a great magazine called PC Tech Journal
then later PC TECHNIQUES. One of my favorite columns was
"Pushing the Envelope" by Michael Abrash.
I entered his first challenge (word count) and improved it by roughly 2
times. I was frustrated to learn that the winning entry (3x) was based
on the first idea I had of using a 64K lookup table. I abandoned it because
I figured it would break the rules of being more than 200 lines.
(This oddly had a profound effect on shaping my entire life with regards
to rules)
Future challenges were issued:
"Short Sorts"
Beat David Stafford's 25-byte C-callable small model routine that sorts an
array of integers in ascending order. So I did! (see code below)
"Hi/Lo"
Beat David Stafford's 24-byte C-callable small model routine that finds the
greatest or smallest unsigned int in 24 bytes or less". So I did!
(see code below)
;------------------------------------------------------------------------
; c small model
;
; Sorts an array of ints. 23 bytes
;
; void sort( int num, int a[] );
;
; David Flicek
;------------------------------------------------------------------------
.model small
.code
public _sort
top: lodsw
cmp ax,[si] ; are these two word in order?
jl cont ; yes - continue
xchg ax,[si] ; else swap words
mov [si-2],ax
cont: loop top ; next
_sort: cld ; foward direction
pop dx ; ip
pop cx ; num
pop si ; a[]
dec cx ; num--
push si ; put regs back on stack
push cx
push dx
jg top ; cx>0 then jmp
ret
end
;------------------------------------------------------------------------
; c small model (23 bytes)
; c tiny model (22 bytes with ds overide)
;
; Find the greatest or smallest unsigned int.
;
; #define hi 0x72 (jb)
; #define lo 0x77 (ja)
; void findint(char hilo, int num, unsigned a[] );
;
; David Flicek
;------------------------------------------------------------------------
.model small
.code
public _findint
_findint:
pop dx ; ret address
pop ax ; opcode ja or jb
pop cx ; num
pop bx ; a[]
push bx ; put back on stack
push cx
push ax
push dx
mov byte ptr [$+8],al ; patch in opcode
get: mov ax,[bx] ; get int
check: cmp ax,[bx] ; check saved with next
jmp short get ; place holder for opcode
inc bx ; point to next int
inc bx
loop check ; loop until done
ret
end
jmpfar macro jseg, joff
db 0EAh
dw joff
dw jseg
endm