Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;--------------------------------------------------------------------------
- ;
- ; Program: dcomp
- ; Author: Ty Devries
- ; Clint Fitch
- ; Date: 26 October, 2011
- ;
- ; Function: Dcomp decompresses ASCII text.
- ;
- ; Input:
- ; - si points to the string of compressed data
- ; - di points to the empty list into which the decompressed data is stored
- ;
- ; Output:
- ;
- ; - The compressed data in inlist is decompressed into output list
- ; - The compressed data is not modified
- ; - All registers contain their original value except ax
- ; ax = 0 Invalid compressed bit pattern found
- ; ax = 1...n Okay and n = size of decompressed data
- ;
- ;--------------------------------------------------------------------------
- ;----------------------------------
- .model small ;64k code and 64k data
- .8086 ;only allow 8086 instructions
- public dcomp ;allow linker to access dcomp
- public getbit ;allow linker to access getbit
- ;----------------------------------
- .data
- ;-------------------------------------------------------------
- ;
- ;-------------------------------------------------------------
- .code
- ;----------------------------------
- ;
- ;----------------------------------
- dcomp:
- ;
- ret ; return
- ;---------------------------------;
- .data
- ;----------------------------------
- ;
- ;----------------------------------
- eight db 8 ; mothafuckin 8
- ;----------------------------------
- ; GETBIT
- ;
- ; Input:
- ; - ax contains the bit number requested ( 0 to 1783 are valid)
- ; - si points to the input compressed data string 1 to 223 bytes
- ;
- ; Output
- ; - if the requested bit number is valid (0 to 1783) then
- ; ax contains the bit value 0 - 1
- ; - if the requested bit number is invalid (greater than 1783) then
- ; ax is unchanged
- ; - the subroutine must save and restore any other used register
- ; - the input compressed data may not be changed
- ;----------------------------------
- .code ;
- ;----------------------------------
- ; Prepare bit to be got
- ;----------------------------------
- getbit: ;
- cmp ax,1783 ; compare ax to 1783
- ja return ; if ax > 1783, return
- push bx ; store bx
- push cx ; store cx
- div [eight] ; ah = remainder, al = quotient
- mov bl,al ; bl is byte offset
- mov bh,0 ; convert bl to word
- mov al,[bx+si] ; looking at correct byte
- mov cl,ah ; cl is bit offset
- inc cl ; always loop once more
- ;----------------------------------
- ; Shift bitwise to the desired bit
- ;----------------------------------
- shift: ;
- shl al,cl ; shift left once
- ;----------------------------------
- ; Move the registers back to their
- ; former values
- ;----------------------------------
- restore: ;
- pop cx ; restore cx
- pop bx ; restore bx
- ;----------------------------------
- ; Set ax to 1 if CF is 1
- ;----------------------------------
- getflag: ;
- jnc zero ; check the carry flag
- mov ax,1 ; bit is a 1
- ret ; return to main
- ;----------------------------------
- ; Otherwise set ax to 0
- ;----------------------------------
- zero: ;
- mov ax,0 ; bit is a 0
- ;----------------------------------
- ; Exit subroutine and return to
- ; main
- ;----------------------------------
- return: ;
- ret ; return bit
- ;----------------------------------
- end
Add Comment
Please, Sign In to add comment