Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .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 ;
- getbit: ;
- cmp ax,1783 ; compare ax to 1783
- jg return ; if ax > 1783, return
- cmp ax,0 ; compare ax to 0
- jl return ; if ax < 0, return
- push bx ; store bx
- push cx ; store cx
- div [eight] ; ah = remainder, al = quotient
- mov bl,al ; bx is byte offset
- mov bh,0 ; convert bl to word
- mov al,[bx+si] ; looking at correct byte
- mov cl,ah ; cx is bit offset to CF
- mov ch,0 ; convert ch to
- inc cx ; always loop once more
- shift: ;
- shl al,1 ; shift left once
- loop shift ; loop cx times
- restore: ;
- pop cx ; restore cx
- pop bx ; restore bx
- getflag: ;
- jnc zero ; check the carry flag
- mov ax,1 ; bit is a 1
- ret ; return to main
- zero: ;
- mov ax,0 ; bit is a 0
- return: ;
- ret ; return bit
- ;----------------------------------
- end
Add Comment
Please, Sign In to add comment