Advertisement
qberik

Untitled

Nov 29th, 2022
2,859
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. input_to_ax macro
  2.   local _input, _not_first_symbol, _incorrect, _correct, _clear_symb, _input_end, _process_number, _neg_flag, _end_of_processing
  3.   push bx
  4.   push cx
  5.   push dx
  6.   xor cx, cx
  7.   xor bx, bx
  8.   xor dx, dx
  9. _input:
  10.   xor ax, ax
  11.   mov ah, 01
  12.   int 21h
  13.   cmp al, 0Dh
  14.   je _correct
  15.   cmp al, 08h
  16.   je _correct
  17.   cmp cx, 0
  18.   jg _not_first_symbol
  19.   cmp al, 2Dh
  20.   je _correct
  21. _not_first_symbol:
  22.   cmp al, 30h
  23.   jl _incorrect
  24.   cmp al, 39h
  25.   jg _incorrect
  26.   jmp _correct
  27. _incorrect:
  28.   mov dl, 08h
  29.   mov ah, 02h
  30.   int 21h
  31.   mov dl, 20h
  32.   mov ah, 02h
  33.   int 21h
  34.   mov dl, 08h
  35.   mov ah, 02h
  36.   int 21h
  37.   jmp _input
  38. _correct:
  39.   cmp al, 0Dh ; ENTER
  40.   je _input_end
  41.   cmp al, 08h ; BACKSPACE
  42.   je _clear_symb
  43.   mov ah, 0
  44.   push ax
  45.   inc cx
  46.   jmp _input
  47. _clear_symb:
  48.   cmp cx, 0
  49.   je _input
  50.   pop ax
  51.   dec cx
  52.   mov dl, 20h
  53.   mov ah, 02h
  54.   int 21h
  55.   mov dl, 08h
  56.   mov ah, 02h
  57.   int 21h
  58.   jmp _input
  59. _input_end:
  60.   xor dx, dx
  61.   mov bx, 1
  62.   cmp cx, 0
  63.   jne _process_number
  64.   mov ax, 0
  65.   jmp _end_of_processing
  66. _process_number:
  67.   pop ax
  68.   cmp al, 02dh ; - sign
  69.   jne _neg_flag
  70.   neg dx
  71.   jmp _end_of_processing
  72. _neg_flag:
  73.   sub al, 30h
  74.   mov ah, 0
  75.   push dx
  76.   mul bx
  77.   pop dx
  78.   add dx, ax
  79.   mov ax, bx
  80.   mov bx, 10
  81.   push dx
  82.   mul bx
  83.   pop dx
  84.   mov bx, ax
  85.   loop _process_number
  86. _end_of_processing:
  87.   mov ax, dx
  88.   pop dx
  89.   pop cx
  90.   pop bx
  91.  
  92.  
  93. endm input_to_ax
  94.  
  95.  
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement