asm code
user_3924995
plain_text
a year ago
1.7 kB
3
Indexable
assume CS:Code, DS:Data, SS:Stack
Code Segment
Start:
mov ax, Data
mov ds, ax
mov dx, offset prompt
mov ah, 09h
int 21h
mov ah, 01h
int 21h
sub al, '0' ; Convert ASCII to integer
mov value, al
; input check
cmp al, 2
jb fault ; Jump if below 2
cmp al, 5
ja fault ; Jump if above 5
; Countdown loop from 9 to 0
mov cl, 9 ; Start countdown from 9
Countdown:
mov dx, offset message
mov ah, 09h
int 21h
; Print current number
mov al, cl
add al, '0' ; Convert to ASCII
mov dl, al
mov ah, 02h ; Function to print character
int 21h
; New line after printing number
mov dx, offset newline
mov ah, 09h
int 21h
; delay
push cx ; Save CX
mov cx, 0FFFFh ; Set delay count
delay:
nop ; do nothing
loop delay ; Loop until CX is zero
pop cx ; Restore CX
; Decrement counter and check
dec cl ; Decrement CL
jnz Countdown ; Loop until CL is zero
End_program:
mov ax, 4C00h
int 21h
fault:
mov dx, offset prompt
mov ah, 09h
int 21h
jmp Start ; Restart program
Code Ends
Data Segment
prompt db 'Enter a number between 2 and 5: $'
value db ? ; Variable to store user input
newline db 0Dh, 0Ah, '$' ; New line
message: db 'Counting down: $'
Data Ends
Stack Segment
Stack Ends
End Start
Editor is loading...
Leave a Comment