Advertisement
palmerstone

macros

Sep 14th, 2012
2,790
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. include 'emu8086.inc'
  2.  
  3. org  100h ; set location counter to 100h
  4.  
  5. main proc
  6.     call scanf
  7.     mov ax, cx
  8.     call printf
  9.     mov ax, cx
  10.     call printf
  11.    
  12. main endp
  13. ret
  14.  
  15. printf proc
  16.    push ax
  17.    push cx
  18.    push bx
  19.    push dx
  20.    mov bl, 0
  21.    mov cx, 10
  22.    
  23.    PrintLoopStart:
  24.        mov dx, 0
  25.        div cx
  26.        add dx, 48
  27.        push dx
  28.        add si, 2
  29.        add bl, 2
  30.        
  31.        cmp ax, 0
  32.        jne PrintLoopStart
  33.        
  34.    SecondLoopStart:
  35.        pop dx
  36.        mov ah, 2
  37.        int 21h
  38.        sub bl, 2
  39.        cmp bl, 0
  40.        jne SecondLoopStart
  41.        
  42.    mov ah, 2
  43.    mov dl, 0ah
  44.    int 21h
  45.    mov dl, 0dh
  46.    int 21h
  47.    
  48.    pop dx
  49.    pop bx
  50.    pop cx
  51.    pop ax
  52.    
  53.    
  54.    ret
  55. printf endp
  56.  
  57.  
  58. scanf proc
  59.    push ax
  60.    push bx
  61.    push dx
  62.    mov cx, 0
  63.    
  64.    ScanLoopStart:
  65.       mov ah, 1
  66.       int 21h
  67.       mov ah, 0
  68.       cmp al, 48
  69.       jl Exit
  70.       cmp al, 57
  71.       jg Exit
  72.      
  73.       mov bx, cx
  74.       shl bx, 1
  75.       shl cx, 3
  76.       add cx, bx
  77.       sub ax, 48
  78.       add cx, ax
  79.      
  80.       cmp ax, -1
  81.       jne ScanLoopStart
  82.      
  83.    Exit:
  84.    
  85.    mov ah, 2
  86.    mov dl, 0ah
  87.    int 21h
  88.    mov dl, 0dh
  89.    int 21h
  90.    
  91.    pop dx
  92.    pop bx
  93.    pop ax
  94.    
  95.    ret
  96.  
  97. scanf endp
  98.  
  99.    
  100. DEFINE_PRINT_STRING
  101. DEFINE_SCAN_NUM
  102. DEFINE_PRINT_NUM
  103. DEFINE_PRINT_NUM_UNS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement