gbilios
asked on
CALL getC
I use call getc to read in a character from the keyboard in a label called reads1, which test if the character is lowecase or uppercase. a label isUPPER & isLOWER display messages.
I have in my lecture notes JE (Jump if equal) - a code for testing equality. How does this check if the characters read from the keyboard is uppercase or lowecase?
.MODEL SMALL
.STACK 100h
.DATA
bdos EQU 21H
cr EQU 0DH
lf EQU 0AH
enter1 DB 'Enter a character $'
UPPER DB ' The character is uppercase $'
LOWER DB ' The character is lowercase $'
NUMERIC DB ' The character is numeric $'
NEITHER DB ' The character is not lowercase, uppercase or numeric $'
.CODE
INCLUDE ioproc.asm
start:
MOV AX,@data
MOV DS,AX
CALL newline
reads1:
MOV DX,OFFSET(enter1)
MOV AH,09H
INT bdos
CALL newline
CALL getc
CMP AL,cr
JE isUPPER
;CMP AL,cr
;JE isLOWER
MOV DX,OFFSET(NEITHER)
MOV AH,09H
INT bdos
CALL newline
JMP reads1
isUPPER:
MOV DX,OFFSET(UPPER)
MOV AH,09H
INT bdos
CALL newline
JMP reads1
isLOWER:
MOV DX,OFFSET(LOWER)
MOV AH,09H
INT bdos
CALL newline
JMP reads1
isNUMERIC:
MOV DX,OFFSET(NUMERIC)
MOV AH,09H
INT bdos
CALL newline
JMP reads1
isNEITHER:
MOV DX,OFFSET(NEITHER)
MOV AH,09H
INT bdos
CALL newline
JMP reads1
finish:
CALL newline
MOV AX,4C00H
INT bdos
END start
I have in my lecture notes JE (Jump if equal) - a code for testing equality. How does this check if the characters read from the keyboard is uppercase or lowecase?
.MODEL SMALL
.STACK 100h
.DATA
bdos EQU 21H
cr EQU 0DH
lf EQU 0AH
enter1 DB 'Enter a character $'
UPPER DB ' The character is uppercase $'
LOWER DB ' The character is lowercase $'
NUMERIC DB ' The character is numeric $'
NEITHER DB ' The character is not lowercase, uppercase or numeric $'
.CODE
INCLUDE ioproc.asm
start:
MOV AX,@data
MOV DS,AX
CALL newline
reads1:
MOV DX,OFFSET(enter1)
MOV AH,09H
INT bdos
CALL newline
CALL getc
CMP AL,cr
JE isUPPER
;CMP AL,cr
;JE isLOWER
MOV DX,OFFSET(NEITHER)
MOV AH,09H
INT bdos
CALL newline
JMP reads1
isUPPER:
MOV DX,OFFSET(UPPER)
MOV AH,09H
INT bdos
CALL newline
JMP reads1
isLOWER:
MOV DX,OFFSET(LOWER)
MOV AH,09H
INT bdos
CALL newline
JMP reads1
isNUMERIC:
MOV DX,OFFSET(NUMERIC)
MOV AH,09H
INT bdos
CALL newline
JMP reads1
isNEITHER:
MOV DX,OFFSET(NEITHER)
MOV AH,09H
INT bdos
CALL newline
JMP reads1
finish:
CALL newline
MOV AX,4C00H
INT bdos
END start
As a note, in most compilers you can use characters constants to make the source more human-readable.
/* check if the character in al is in upper case */
cmp al, 'A'
jge chk2 /* if greater or equal */
; not in upper case
chk2:
cmp al, 'Z'
jl upper /* if less */
upper:
;print upper /* It is in upper case */
similarly do for lower case,
cmp al, 'a'
jge chk2 /* if greater or equal */
; not in upper case
chk2:
cmp al, 'z'
jl upper /* if less */
upper:
;print lower /* it is in lower case */
/* check if the character in al is in upper case */
cmp al, 'A'
jge chk2 /* if greater or equal */
; not in upper case
chk2:
cmp al, 'Z'
jl upper /* if less */
upper:
;print upper /* It is in upper case */
similarly do for lower case,
cmp al, 'a'
jge chk2 /* if greater or equal */
; not in upper case
chk2:
cmp al, 'z'
jl upper /* if less */
upper:
;print lower /* it is in lower case */
ASKER
For the reply. i added the code and tested it. I get a the same result if i read in a lowercase or uppercase. Have i got it right?
reads1:
MOV DX,OFFSET(enter1)
MOV AH,09H
INT bdos
CALL newline
CALL getc
CMP AL,cr
CMP AL,64
JA isLOWER
;CMP AL,91
;JB isUPPER
;CMP AL,cr
;JE isLOWER
MOV DX,OFFSET(NEITHER)
MOV AH,09H
INT bdos
CALL newline
JMP reads1
isUPPER:
MOV DX,OFFSET(UPPER)
MOV AH,09H
INT bdos
CALL newline
JMP reads1
isLOWER:
MOV DX,OFFSET(LOWER)
MOV AH,09H
INT bdos
CALL newline
JMP reads1
reads1:
MOV DX,OFFSET(enter1)
MOV AH,09H
INT bdos
CALL newline
CALL getc
CMP AL,cr
CMP AL,64
JA isLOWER
;CMP AL,91
;JB isUPPER
;CMP AL,cr
;JE isLOWER
MOV DX,OFFSET(NEITHER)
MOV AH,09H
INT bdos
CALL newline
JMP reads1
isUPPER:
MOV DX,OFFSET(UPPER)
MOV AH,09H
INT bdos
CALL newline
JMP reads1
isLOWER:
MOV DX,OFFSET(LOWER)
MOV AH,09H
INT bdos
CALL newline
JMP reads1
hi,
Do it this way.
reads1:
MOV DX,OFFSET(enter1)
MOV AH,09H
INT bdos
CALL newline
CALL getc
; CMP AL,cr
CMP AL,64
JA isUPPER
cmp al, 96
ja isLOWER
;CMP AL,91
;JB isUPPER
;CMP AL,cr
;JE isLOWER
MOV DX,OFFSET(NEITHER)
MOV AH,09H
INT bdos
CALL newline
JMP reads1
isUPPER:
cmp al, 91
ja goend
MOV DX,OFFSET(UPPER)
MOV AH,09H
INT bdos
CALL newline
JMP reads1
isLOWER:
cmp al, 126
ja goend
MOV DX,OFFSET(LOWER)
MOV AH,09H
INT bdos
CALL newline
JMP reads1
goend:
end
regards manish
Do it this way.
reads1:
MOV DX,OFFSET(enter1)
MOV AH,09H
INT bdos
CALL newline
CALL getc
; CMP AL,cr
CMP AL,64
JA isUPPER
cmp al, 96
ja isLOWER
;CMP AL,91
;JB isUPPER
;CMP AL,cr
;JE isLOWER
MOV DX,OFFSET(NEITHER)
MOV AH,09H
INT bdos
CALL newline
JMP reads1
isUPPER:
cmp al, 91
ja goend
MOV DX,OFFSET(UPPER)
MOV AH,09H
INT bdos
CALL newline
JMP reads1
isLOWER:
cmp al, 126
ja goend
MOV DX,OFFSET(LOWER)
MOV AH,09H
INT bdos
CALL newline
JMP reads1
goend:
end
regards manish
ASKER
If i wanted to test if the character was a numeric type, then would I use the following:
CALL getc
CMP AL,cr
CMP AL,9
JB isNUMERIC
CALL getc
CMP AL,cr
CMP AL,9
JB isNUMERIC
no,
check for the ascii value
0= 48,
cmp al, 47
ja chk2
chk2:
cmp al, 58
ja end
print it is numeric.
in short numeric value is fro 48 to 57.
regards manish
check for the ascii value
0= 48,
cmp al, 47
ja chk2
chk2:
cmp al, 58
ja end
print it is numeric.
in short numeric value is fro 48 to 57.
regards manish
ASKER
Not sure why the isNumeric is overriden. i tested it on its own and works but not with the code below.
reads1:
MOV DX,OFFSET(enter1)
MOV AH,09H
INT bdos
CALL newline
CALL getc
CMP AL,cr
CMP AL,96
JA isLOWER
CMP AL,126
JB isUPPER
CMP AL,58
JB isNumeric
;else
MOV DX,OFFSET(NEITHER)
MOV AH,09H
INT bdos
CALL newline
JMP reads1
reads1:
MOV DX,OFFSET(enter1)
MOV AH,09H
INT bdos
CALL newline
CALL getc
CMP AL,cr
CMP AL,96
JA isLOWER
CMP AL,126
JB isUPPER
CMP AL,58
JB isNumeric
;else
MOV DX,OFFSET(NEITHER)
MOV AH,09H
INT bdos
CALL newline
JMP reads1
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can check if character is greater than 64 and smaller than 91, it is upper case and if
it is greater than 96 and smaller than 126.
/* check if the character in al is in upper case */
cmp al, 64
ja chk2 /* if above */
; not in upper case
chk2:
cmp al, 91
jb upper /* if below */
upper:
;print upper /* It is in upper case */
similarly do for lower case,
cmp al, 96
ja chk2 /* if above */
; not in upper case
chk2:
cmp al, 126
jb upper /* if below */
upper:
;print lower /* it is in lower case */