home *** CD-ROM | disk | FTP | other *** search
- ;*--------------------------------------------------------------------*
- ;* STDFUNC -- This is a standard set of Assembler Subroutines that *
- ;* are contained in the STDFUNC.LIB standard assembler *
- ;* linkage library. *
- ;* *
- ;* Author: J.C. Weilandt II Date: 10-07-86 Last Update: 10-08-86 *
- ;* *
- ;* Functions Contained: *
- ;* stdout -- output a single character to the standard out dev *
- ;* stdcrlf -- output a carriage return/line feed sequence stdout *
- ;* stdin -- input a single character with echo from stdin *
- ;* stdinne -- input a single character w/o echo from stdin *
- ;* dec8out -- converts 8-bit binary to decimal and prints *
- ;* dec16out -- converts 16-bit binary to decimal and prints *
- ;* return -- return to MS-DOS *
- ;* prtstr -- prints a string terminated by $ *
- ;* clrscr -- clear the video display screen *
- ;* hex8out -- convert 8-bit binary to display hex and print *
- ;* hex16out -- convert 16-bit binary to display hex and print *
- ;* *
- ;*--------------------------------------------------------------------*
- ;
- codes segment ;dummy segment for assembler
- public stdout ;so we can find it later
- public stdcrlf ;so we can find it later
- public stdin ;so we can find it later
- public stdinne ;so we can find it later
- public dec8out ;so we can find it later
- public dec16out ;so we can find it later
- public return ;so we can find it later
- public prtstr ;so we can find it later
- public clrscr ;so we can find it later
- public hex8out ;so we can find it later
- public hex16out ;so we can find it later
- assume cs:codes ;dummy code segment fixup
- ;
- ;*--------------------------------------------------------------------*
- ;* stdout -- output a single character to standard output device *
- ;* *
- ;* call_seq mov al,_char_ ;move character to al register *
- ;* call stdout ;write character on stdout *
- ;*--------------------------------------------------------------------*
- stdout proc far ;procedure header
- push dx ;save the dx register pair
- mov dl,al ;load character to print
- mov ah,2 ;load DOS function number
- int 21h ;issue DOS function call
- pop dx ;restore dx register pair
- ret ;return to caller
- stdout endp ;procedure trailer
- ;*--------------------------------------------------------------------*
- ;* stdcrlf -- output a carriage return/line feed sequence to stdout *
- ;* *
- ;* call_seq call stdcrlf ;write out CR/LF combination *
- ;*--------------------------------------------------------------------*
- stdcrlf proc far ;procedure header
- push ax ;save the ax register pair
- mov al,0dh ;load character to print
- call stdout ;write out the carriage return
- mov al,0ah ;load character to print
- call stdout ;write out the line feed
- pop ax ;restore ax register pair
- ret ;return to caller
- stdcrlf endp ;procedure trailer
- ;*--------------------------------------------------------------------*
- ;* stdin -- input a single character from standard input device *
- ;* *
- ;* call_seq call stdin ;read character from console *
- ;*--------------------------------------------------------------------*
- stdin proc far ;procedure header
- mov ah,1 ;load DOS function number
- int 21h ;issue DOS function call
- ret ;return to caller
- stdin endp ;procedure trailer
- ;*--------------------------------------------------------------------*
- ;* stdinne -- input a single character from stdin with no echo *
- ;* *
- ;* call_seq call stdinne ;read character from cons w/o echo *
- ;*--------------------------------------------------------------------*
- stdinne proc far ;procedure header
- mov ah,8 ;load DOS function number
- int 21h ;issue DOS function call
- ret ;return to caller
- stdinne endp ;procedure trailer
- ;*--------------------------------------------------------------------*
- ;* dec8out -- convert 8-bit binary to decimal and print to stdout *
- ;* *
- ;* call_seq mov dl,_bin_ ;move binary number to dl register *
- ;* call dec8out ;convert to decimal and print out *
- ;*--------------------------------------------------------------------*
- dec8out proc far ;procedure header
- push ds ;save data segment register
- push di ;save di register pair
- push dx ;save work register pair
- push cx ;save count register pair
- push ax ;save accumulator register pair
- mov ax,seg tbuff ;get segment address of buffer
- mov ds,ax ;put into data segment register
- mov cx,0 ;initialize counter
- mov di,offset tbuff ;point to buffer area
- dec8out1:
- push cx ;save counter register pair
- mov al,dl ;AX now has the numerator
- mov ah,0 ;clear upper half
- mov cl,10 ;divisor of 10
- div cl ;do the division
- mov dl,al ;get the quotient
- mov al,ah ;get the remainder
- add al,30h ;make numeric display
- mov [di],al ;put number into buffer
- inc di ;point to the next byte
- pop cx ;restore counter
- inc cx ;count the digit
- cmp dl,0 ;q.are we all done ??
- jnz dec8out1 ;nope, go do more
- dec8out2:
- dec di ;back up through buffer
- mov al,[di] ;get byte from buffer
- call stdout ;write out the number
- loop dec8out2 ;loop until cx=0
- pop ax ;restore accumulator pair
- pop cx ;restore counter pair
- pop dx ;restore work register pair
- pop di ;restore index pair
- pop ds ;restore data segment pair
- ret ;return to caller
- tbuff dw 32(?) ;buffer storage
- dec8out endp ;procedure trailer
- ;*--------------------------------------------------------------------*
- ;* dec16out -- convert 16-bit binary to decimal and print to stdout *
- ;* *
- ;* call_seq mov dx,_bin_ ;move binary number to dx register *
- ;* call dec16out ;convert to decimal and print out *
- ;*--------------------------------------------------------------------*
- dec16out proc far ;procedure header
- push ds ;save data segment register
- push di ;save di register pair
- push dx ;save work register pair
- push cx ;save count register pair
- push ax ;save accumulator register pair
- mov ax,seg xbuff ;get segment address of buffer
- mov ds,ax ;put into data segment register
- mov cx,0 ;initialize counter
- mov di,offset xbuff ;point to buffer area
- dec16out1:
- push cx ;save counter register pair
- mov ax,dx ;AX now has the numerator
- mov dx,0 ;clear upper half
- mov cx,10 ;divisor of 10
- div cx ;do the division
- xchg ax,dx ;get the quotient
- add al,30h ;make numeric display
- mov [di],al ;put number into buffer
- inc di ;point to the next byte
- pop cx ;restore counter
- inc cx ;count the digit
- cmp dx,0 ;q.are we all done ??
- jnz dec16out1 ;nope, go do more
- dec16out2:
- dec di ;back up through buffer
- mov al,[di] ;get byte from buffer
- call stdout ;write out the number
- loop dec16out2 ;loop until cx=0
- pop ax ;restore accumulator pair
- pop cx ;restore counter pair
- pop dx ;restore work register pair
- pop di ;restore index pair
- pop ds ;restore data segment pair
- ret ;return to caller
- xbuff dw 32 (?) ;buffer storage
- dec16out endp ;procedure trailer
- ;*--------------------------------------------------------------------*
- ;* return -- return to MS-DOS with a good return code *
- ;* *
- ;* call_seq call return ;return to MS-DOS *
- ;*--------------------------------------------------------------------*
- return proc far ;procedure header
- mov ax,4c00h ;load terminate function code
- int 21h ;issue DOS function call
- ret ;return to caller (dummy inst)
- return endp ;procedure trailer
- ;*--------------------------------------------------------------------*
- ;* prtstr -- prints a string terminated by a $ *
- ;* *
- ;* call_seq mov dx,_str_ ;load address of string to print *
- ;* call prtstr ;print the string *
- ;*--------------------------------------------------------------------*
- prtstr proc far ;procedure header
- mov ah,09h ;load print string function code
- int 21h ;issue DOS function call
- ret ;return to caller
- prtstr endp ;procedure trailer
- ;*--------------------------------------------------------------------*
- ;* clrscr -- clear the video display screen *
- ;* *
- ;* call_seq call clrscr ;clear the screen *
- ;*--------------------------------------------------------------------*
- clrscr proc far ;procedure header
- push cx ;save the counter register pair
- push ax ;save the accumulator register pair
- push es ;save extended segment registers
- mov ax,0b800h ;point to color graphics ram
- mov es,ax ;load extended segment register
- mov cx,2000h ;load word count of entire screen
- mov ax,0 ;zero pattern for entire screen
- mov di,ax ;load starting buffer offset addr
- cld ;set direction forward
- rep stosw ;repeat intil cx reached zero
- pop es ;restore extended segment regs
- pop ax ;restore accumulator reg pair
- pop cx ;restore counter reg pair
- ret ;return to caller
- clrscr endp ;procedure trailer
- ;*--------------------------------------------------------------------*
- ;* hex8out -- convert 8-bit binary to display hexidecimal and print *
- ;* *
- ;* call_seq mov dl,_bin_ ;load binary representation *
- ;* call hex8out ;display hexidecimal output *
- ;*--------------------------------------------------------------------*
- hex8out proc far ;procedure header
- push cx ;save the counter register pair
- push ax ;save the accumulator register pair
- mov cx,2 ;load maximum count field
- hex8out1:
- push cx ;save the counter register pair
- mov cl,4 ;load bit shift count
- rol dl,cl ;rotate dl register left
- mov al,dl ;move result to al register
- and al,00fh ;get rid of extra stuff
- daa ;add 6 if result is A-F
- add al,0f0h ;turn on carry if A-F
- adc al,040h ;make al register ascii display
- call stdout ;write the character out
- pop cx ;restore count register
- loop hex8out1 ;return if more digits
- pop ax ;restore accumulator pair
- pop cx ;restore counter pair
- ret ;return to caller
- hex8out endp ;procedure trailer
- ;*--------------------------------------------------------------------*
- ;* hex16out -- convert 16-bit binary to display hexidecimal and print *
- ;* *
- ;* call_seq mov dx,_bin_ ;load binary representation *
- ;* call hex16out ;display hexidecimal output *
- ;*--------------------------------------------------------------------*
- hex16out proc far ;procedure header
- push cx ;save the counter register pair
- push ax ;save the accumulator register pair
- mov cx,4 ;load maximum count field
- hex16out1:
- push cx ;save the counter register pair
- mov cl,4 ;load bit shift count
- rol dx,cl ;rotate dx register left
- mov al,dl ;move result to al register
- and al,00fh ;get rid of extra stuff
- daa ;add 6 if result is A-F
- add al,0f0h ;turn on carry if A-F
- adc al,040h ;make al register ascii display
- call stdout ;write the character out
- pop cx ;restore count register
- loop hex16out1 ;return if more digits
- pop ax ;restore accumulator pair
- pop cx ;restore counter pair
- ret ;return to caller
- hex16out endp ;procedure trailer
- ;*--------------------------------------------------------------------*
- ;* New routines must be inserted before this point *
- ;*--------------------------------------------------------------------*
- ;
- codes ends ;terminate dummy segment
- end ;terminate assembly sysin