- .model small
- .stack 100h
- .data
- prompt db 'Enter a three-digit number: $'
- result db 'The result is: $'
- .code
- main proc
- mov ax, @data
- mov ds, ax
- ; Print prompt
- lea dx, prompt
- mov ah, 9
- int 21h
- ; Read input number
- mov bx, 0 ; Initialize BX register to store input
- mov cx, 3 ; Counter for 3 digits
- input_loop:
- mov ah, 1 ; Read a character from input
- int 21h
- cmp al, 13 ; Check if Enter key is pressed
- je process ; Jump to process if Enter key is pressed
- sub al, '0' ; Convert ASCII to digit
- push ax ; Push digit onto stack
- loop input_loop
- process:
- mov ax, 0 ; Initialize AX register
- pop bx ; Pop last digit from stack into BX
- mov cx, 100 ; Multiplier for hundreds place
- mul cx ; Multiply BX by 100
- pop cx ; Pop second digit from stack into CX
- mov dx, 10 ; Multiplier for tens place
- mul dx ; Multiply CX by 10
- add ax, cx ; Add to AX
- pop cx ; Pop first digit from stack into CX
- add ax, cx ; Add to AX
- mov bx, 2 ; Multiplier for doubling the number
- mul bx ; Multiply AX by 2
- ; Print result
- lea dx, result
- mov ah, 9
- int 21h
- ; Print the result number
- mov cx, 0 ; Initialize count of digits
- mov bx, 10 ; Divisor for extracting digits
- print_loop:
- mov dx, 0 ; Clear DX register
- div bx ; Divide AX by 10
- push dx ; Push remainder (digit) onto stack
- inc cx ; Increment digit count
- cmp ax, 0 ; Check if quotient is 0
- jne print_loop
- print_digits:
- pop dx ; Pop digit from stack
- add dl, '0' ; Convert digit to ASCII
- mov ah, 2 ; Output character function
- int 21h ; Print character
- loop print_digits
- mov ah, 4ch
- int 21h
- main endp
- end main
[text] 8086
Viewer
Editor
You can edit this paste and save as new:
File Description
- 8086
- Paste Code
- 20 Apr-2024
- 1.84 Kb
You can Share it: