Advertisement
PaulPaulAga

Untitled

Apr 23rd, 2020
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. PUBLIC  read_sd
  2.  
  3. EXTRN   read_str:       near
  4. EXTRN   print_newline:  near
  5. EXTRN   number:         byte
  6. EXTRN   bin_num:        byte
  7.  
  8. DataSeg     SEGMENT PARA PUBLIC 'DATA'
  9.     inputStr db 'abcdfkjdslkfd'
  10. DataSeg     ENDS
  11.  
  12. CodeSeg     SEGMENT PARA PUBLIC 'CODE'
  13. assume CS:CodeSeg, DS:DataSeg
  14. read_sd proc near
  15.     call    print_newline
  16.     mov     dx, offset inputStr
  17.     call    read_str
  18.     call    clear_number
  19.     call    save_dec
  20.     call    to_bin
  21.     ret
  22. read_sd endp
  23. clear_number proc near
  24.     mov     si, 0
  25.     mov     cx, 7
  26.     clear_loop:
  27.         mov     number[si], 'a'
  28.         inc     si
  29.         loop    clear_loop
  30.     ret
  31. clear_number endp
  32.  
  33. save_dec proc near
  34.     mov     si, 0
  35.     safe_loop:
  36.         cmp     inputStr[si + 2], 13
  37.         je      exit
  38.         mov     al, inputStr[si + 2]
  39.  
  40.         mov     number[si], al
  41.         inc     si
  42.         jne     safe_loop
  43. exit:
  44.     mov     number[si], '$'
  45.     ret
  46. save_dec endp
  47.  
  48. to_bin proc near
  49.     mov     si, 0
  50.     mov     ax, 0
  51.     cmp     number[0], '-'
  52.     jne     num_loop
  53.     inc     si
  54.     cmp     number[0], '-'
  55.     je      num_loop
  56. loop_end:
  57.     cmp     number[0], '-'
  58.     je      make_neg
  59. exit:
  60.     mov     word ptr bin_num, ax
  61.     ret    
  62.  
  63. make_neg:
  64.     neg     ax
  65.     jmp     exit
  66.  
  67. num_loop:
  68.     cmp     number[si], '$'
  69.     je      loop_end
  70.     mov     dx, 10
  71.     mul     dx
  72.     mov     dx, 0
  73.     mov     dl, number[si]
  74.     sub     dl, '0'
  75.     add     ax, dx
  76.     inc     si
  77.     jmp     num_loop
  78.  
  79. to_bin endp
  80.  
  81. CodeSeg ENDS
  82. END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement