[text] 8086

Viewer

  1. .model small
  2. .stack 100h
  3.  
  4. .data
  5.     prompt db 'Enter a three-digit number: $'
  6.     result db 'The result is: $'
  7.  
  8. .code
  9. main proc
  10.     mov ax, @data
  11.     mov ds, ax
  12.  
  13.     ; Print prompt
  14.     lea dx, prompt
  15.     mov ah, 9
  16.     int 21h
  17.  
  18.     ; Read input number
  19.     mov bx, 0   ; Initialize BX register to store input
  20.     mov cx, 3   ; Counter for 3 digits
  21.  
  22. input_loop:
  23.     mov ah, 1   ; Read a character from input
  24.     int 21h
  25.     cmp al, 13  ; Check if Enter key is pressed
  26.     je process  ; Jump to process if Enter key is pressed
  27.     sub al, '0' ; Convert ASCII to digit
  28.     push ax     ; Push digit onto stack
  29.     loop input_loop
  30.  
  31. process:
  32.     mov ax, 0   ; Initialize AX register
  33.     pop bx      ; Pop last digit from stack into BX
  34.     mov cx, 100 ; Multiplier for hundreds place
  35.     mul cx      ; Multiply BX by 100
  36.     pop cx      ; Pop second digit from stack into CX
  37.     mov dx, 10  ; Multiplier for tens place
  38.     mul dx      ; Multiply CX by 10
  39.     add ax, cx  ; Add to AX
  40.     pop cx      ; Pop first digit from stack into CX
  41.     add ax, cx  ; Add to AX
  42.  
  43.     mov bx, 2   ; Multiplier for doubling the number
  44.     mul bx      ; Multiply AX by 2
  45.  
  46.     ; Print result
  47.     lea dx, result
  48.     mov ah, 9
  49.     int 21h
  50.  
  51.     ; Print the result number
  52.     mov cx, 0   ; Initialize count of digits
  53.     mov bx, 10  ; Divisor for extracting digits
  54.  
  55. print_loop:
  56.     mov dx, 0   ; Clear DX register
  57.     div bx      ; Divide AX by 10
  58.     push dx     ; Push remainder (digit) onto stack
  59.     inc cx      ; Increment digit count
  60.     cmp ax, 0   ; Check if quotient is 0
  61.     jne print_loop
  62.  
  63. print_digits:
  64.     pop dx      ; Pop digit from stack
  65.     add dl, '0' ; Convert digit to ASCII
  66.     mov ah, 2   ; Output character function
  67.     int 21h     ; Print character
  68.     loop print_digits
  69.  
  70.     mov ah, 4ch
  71.     int 21h
  72. main endp
  73. end main

Editor

You can edit this paste and save as new: