Advertisement
NB52053

bleh

Jul 21st, 2018
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.                                        
  2. ; You may customize this and other start-up templates;
  3. ; The location of this template is c:\emu8086\inc\0_com_template.txt
  4.  
  5. org 100h
  6. .stack
  7. .data
  8.  
  9.     count db 0
  10.     res db 0
  11.     nl db 0dh, 0ah, '$'
  12.  
  13. .code
  14.  
  15. onem macro x
  16.     push ax
  17.      
  18.     mov dx, x
  19.     mov ah, 2
  20.     add dl, '0'
  21.     int 21h
  22.    
  23.     pop ax
  24. endm onem
  25.  
  26.  
  27. newl macro
  28.     mov ah, 9
  29.     lea dx, nl
  30.     int 21h
  31. endm newl
  32.  
  33. proc main
  34. mov dx, @data
  35. mov ds, dx
  36.     call inputAX
  37.     newl
  38.     mov ah, 0
  39.     mov al, res
  40.     ;mov al, 'a'
  41.     ;mov ax, 12345
  42.     call printAX
  43.    
  44. mov ah, 4ch
  45. int 21h
  46. endp main
  47.    
  48. inputAX proc
  49.     mov ax, 0
  50.     mov bl, 10
  51.     inputloop:
  52.         mov ah, 1
  53.         int 21h
  54.                
  55.         cmp al, 0dh
  56.         je doneinput
  57.        
  58.         sub al, '0' ; ascii -> value
  59.         mov dl, al  ; new input
  60.        
  61.         mov al, res ; al = res
  62.         mul bl      ; al = res * 10
  63.         mov res, al
  64.         add res, dl ; al = res + new digit        
  65.                      
  66.         jmp inputloop
  67.        
  68.     doneinput:
  69.         mov al, res
  70.     ret
  71. endp inputAX  
  72.    
  73. printAX proc
  74.    
  75.     mov bx, 10
  76.  
  77.     L1:
  78.         xor dx, dx
  79.         div bx ; DX = AX  10, AX = AX/10  
  80.         push dx
  81.         inc count  
  82.         cmp ax, 0
  83.     je L2
  84.     jmp L1
  85.  
  86.     L2:
  87.         dec count
  88.         pop dx  
  89.         onem dx
  90.         cmp count, 0
  91.         je done
  92.         jmp L2
  93.     done:
  94.    
  95.     ret
  96. endp printAX
  97.  
  98. end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement