Repository navigation
Expand file tree
/
Copy pathp3code3.asm
More file actions
50 lines (38 loc) · 1.39 KB
/
Copy pathp3code3.asm
File metadata and controls
50 lines (38 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
TITLE AL-033 : An AL Program that reads a number from 0 to 9 and prints EVEN if
it is even and ODD if it is an odd number (using the TEST instruction).
.MODEL SMALL
.STACK 100H
.DATA
PROMPT_1 DB 'Enter the number from 0 to 9 : $'
PROMPT_2 DB 0DH,0AH,'The number is : $'
EVEN_MSG DB 'EVEN$', 0
ODD_MSG DB 'ODD$', 0
.CODE
MAIN PROC
MOV AX, @DATA ; Initialize DS
MOV DS, AX
LEA DX, PROMPT_1 ; Load and print PROMPT_1
MOV AH, 9
INT 21H
MOV AH, 1 ; Read a digit (from the user)
INT 21H
MOV BL, AL ; Save the digit in BL
LEA DX, PROMPT_2 ; Load and print PROMPT_2
MOV AH, 9
INT 21H
TEST BL, 01H ; Check the least significant bit for even or odd
JZ @EVEN ; If the least significant bit is 0 (even), jump to @EVEN
; If odd, print "ODD"
LEA DX, ODD_MSG ; Load ODD message
MOV AH, 9
INT 21H
JMP @EXIT ; Jump to exit after printing ODD
@EVEN: ; Label for even number
LEA DX, EVEN_MSG ; Load EVEN message
MOV AH, 9
INT 21H
@EXIT: ; Exit label
MOV AH, 4CH ; Return control to DOS
INT 21H
MAIN ENDP
END MAIN