Guest User

Untitled

a guest
Feb 20th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .data
  2. ;----------------------------------
  3. ;
  4. ;----------------------------------
  5. eight   db  8         ; mothafuckin 8
  6. ;----------------------------------
  7. ; GETBIT
  8. ;
  9. ; Input:
  10. ; - ax contains  the bit number requested ( 0 to 1783 are valid)
  11. ; - si points to the input compressed data string 1 to 223 bytes
  12. ;
  13. ; Output
  14. ; - if the requested bit number is valid (0 to 1783) then
  15. ;   ax contains the bit value 0 - 1
  16. ; - if the requested bit number is invalid  (greater than 1783)  then
  17. ;   ax is unchanged
  18. ; - the subroutine must save and restore any other used register
  19. ; - the input compressed data may not be changed
  20. ;----------------------------------
  21.          .code                    ;
  22. getbit:                           ;
  23.      cmp    ax,1783       ; compare ax to 1783
  24.      jg return        ; if ax > 1783, return
  25.      cmp    ax,0          ; compare ax to 0
  26.      jl return        ; if ax < 0, return
  27.      push   bx        ; store bx
  28.      push   cx        ; store cx
  29.      div    [eight]       ; ah = remainder, al = quotient
  30.      mov    bl,al         ; bx is byte offset
  31.      mov    bh,0          ; convert bl to word
  32.      mov    al,[bx+si]    ; looking at correct byte
  33.          mov    cl,ah         ; cx is bit offset to CF
  34.          mov    ch,0          ; convert ch to
  35.      inc    cx        ; always loop once more
  36. shift:                ;
  37.      shl    al,1          ; shift left once
  38.      loop   shift         ; loop cx times
  39. restore:              ;
  40.      pop    cx        ; restore cx
  41.      pop    bx        ; restore bx
  42. getflag:              ;
  43.      jnc    zero          ; check the carry flag
  44.      mov    ax,1          ; bit is a 1
  45.      ret              ; return to main
  46. zero:                 ;
  47.      mov    ax,0          ; bit is a 0
  48. return:               ;
  49.          ret                      ; return bit
  50. ;----------------------------------
  51.          end
Add Comment
Please, Sign In to add comment