Reputation: 1
I am using procedures for printing even and odd numbers but it is not working what is wrong with my code? since I am new to assembly language
This is my main funtion:
.data
S BYTE ?
.code
main proc
call ven
MOV AH,4ch
INT 21h
main endp
this is my procedure:
ven proc
MOV S,0 \\ S is a variable
L1:
JE ter
MOV AX,S
MOV bl,2
DIV bl
CMP AH,0
JE EVE
JNE ODD
EVE:
MOV AH,2
MOV DL,AL
INT 21h
jmp L1
ODD:
MOV AH,2
MOV DL,AL
INT 21h
jmp L1
ter:
RET
ven ENDP
END MAIN
is there is something with my ven
procedure aur I am linking it with main with a wrong manner.
Upvotes: 0
Views: 426
Reputation: 10381
there are some little errors in you code, I fixed them and pointed them with arrows (◄■■■
) :
.stack 100h ;◄■■■ PROCEDURES REQUIERE STACK.
.data
S dw ? ;◄■■■ DW, NOT BYTE, BECAUSE AX IS TYPE DW.
.code
main proc
call ven
;call outdec
MOV AH,4ch
INT 21h
main endp
ven proc
MOV S,0
L1:
INC S ;◄■■■ S+1
CMP S,20 ;◄■■■ IF S > 20...
JA ter ;◄■■■ ...JUMP TO TER.
MOV AX,S
MOV bl,2
DIV bl
CMP AH,0
JE EVE
JNE ODD
EVE:
MOV AH,2
MOV DL,AL ;◄■■■ HERE YOU PRINT "AL", BUT THE NUMBER
INT 21h ;◄■■■ TO PRINT IS "S". USE "CALL OUTDEC".
jmp L1
ODD:
MOV AH,2
MOV DL,AL ;◄■■■ HERE YOU PRINT "AL", BUT THE NUMBER
INT 21h ;◄■■■ TO PRINT IS "S". USE "CALL OUTDEC".
jmp L1
ter:
RET
ven ENDP
END MAIN
Upvotes: 1