Tuesday 27 January 2009

Corrected A Program From An Assembly Language Book

The code on the book Assembly Languuage Programming is like this:[without bold sentences]

TITLE EG617

STACKSG SEGMENT STACK 'STACK'
DW 32 DUP(0)
STACKSG ENDS

DATASG SEGMENT
CR EQU 13
LF EQU 10
CHARIN DB 'PLEASE INPUT A CHARACTER:','$'
CHAROUT DB 'THE RESULT IS:','$'
LOUT DB 'LETTER','$'
NOUT DB 'NUMBER','$'
OOUT DB 'OTHERS','$'
CRLF DB CR,LF,'$'
DATASG ENDS

CODESG SEGMENT
MAIN PROC FAR
ASSUME CS:CODESG,DS:DATASG,SS:STACKSG
MOV AX,DATASG
MOV DS,AX

LEA DX,CHARIN
MOV AH,9
INT 21H

MOV AH,1
INT 21H
;MOV CL,AL

LEA DX,CRLF
MOV AH,9
INT 21H

LEA DX,CHAROUT
MOV AH,9
INT 21H

;MOV AL,CL

CMP AL,'0'
JB OTHERS
CMP AL,'9'
JA CON1

LEA DX,NOUT
MOV AH,9
INT 21H
JMP EXIT

CON1:
CMP AL,'A'
JB OTHERS
CMP AL,'Z'
JA CON2

LEA DX,LOUT
MOV AH,9
INT 21H
JMP EXIT

CON2:
CMP AL,'a'
JB OTHERS
CMP AL,'z'
JA OTHERS

LEA DX,LOUT
MOV AH,9
INT 21H
JMP EXIT

OTHERS:
LEA DX,OOUT
MOV AH,9
INT 21H

EXIT:
MOV AX,4C00H
INT 21H
MAIN ENDP
CODESG ENDS
END MAIN

Before I correct it,it always return the result from the proc OTHERS,so I add those two sentences into the code and it became correct.I think it may because the following code:

LEA DX,CRLF
MOV AH,9
INT 21H

LEA DX,CHAROUT
MOV AH,9
INT 21H

changed the value stored by the register AL,so I copyed it into the register CL,and it then became correct.

By the way,found that Assembly Language is very interesting and powerful~~

No comments:

Post a Comment