Programming

Just another WordPress.com weblog

ข้อสอบ CT215 แยก input ที่ใส่เข้าไป ตัวใหญ่,ตัวเล็ก,ตัวเลข

แสดงความเห็นโดย จั่น บน ธันวาคม 10, 2008

โจทย์ ป้อนตัวอักขระตัวเล็กตัวใหญ่ตัวเลขปนๆกันแล้วให้แยกออกมาว่ามีตัวเล็กอะไรบ้าง

และตัวใหญ่อะไรบ้างและตัวเลขอะไรบ้าง

Program Identify Lower,Upper,Digits
Input Lower or Upper or Digits: Junabcd1234s
LowerCase Characters: unabcds
UpperCase Characters: J
Digits Characters: 1234
Run Again (y/n):

————–

TITLE (.asm)

; This program
; Last update:

Include Irvine32.inc
Include Macros.inc
.data

allchars BYTE 128 DUP(0)

.code
main PROC

Start:

call Clrscr

mov esi, OFFSET allchars

mGotoxy 20,10
mWrite <”Program Identify Lower,Upper,Digits”,0dh,0ah>

mGotoxy 20,11
mWrite “Input Lower or Upper or Digits: “

mov ebx,0
mov ecx,0

L1:

call ReadChar
cmp al, 0DH
;if ENTER
je L2

;if less than ‘a’
cmp al,61H
jb LBIG

;if more than ‘z’
cmp al,7AH
ja L1

;ok a-z
call WriteChar

mov [esi], al

INC esi
INC ebx

jmp L1

LBIG:

;if less than ‘A’
cmp al,41H
jb LDIGITS

;if more than ‘Z’
cmp al,5AH
ja L1

;ok A-Z
call WriteChar

mov [esi], al

INC esi
INC ebx

jmp L1

LDIGITS:

;if less than ‘0′
cmp al,30H
jb L1

;if more than ‘9′
cmp al,39H
ja L1

;ok 0-9
call WriteChar

mov [esi], al

INC esi
INC ebx

jmp L1

L2:

mGotoxy 20,12
mWrite “LowerCase Characters: “

mov esi, OFFSET allchars
mov ecx, ebx

LPrintLower:

mov al, [esi]
;if less than ‘a’
cmp al,61H
jb L2X

;if more than ‘z’
cmp al,7AH
ja L2X

;ok a-z
call WriteChar

L2X: INC esi

LOOP LPrintLower

L3:

mGotoxy 20,13
mWrite “UpperCase Characters: “

mov esi, OFFSET allchars
mov ecx, ebx

LPrintUpper:

mov al, [esi]
;if less than ‘A’
cmp al,41H
jb L3X

;if more than ‘Z’
cmp al,5AH
ja L3X

;ok A-Z
call WriteChar

L3X: INC esi

LOOP LPrintUpper

L4:

mGotoxy 20,14
mWrite “Digits Characters: “

mov esi, OFFSET allchars
mov ecx, ebx

LPrintDigits:

mov al, [esi]
;if less than ‘0′
cmp al,30H
jb L4X

;if more than ‘9′
cmp al,39H
ja L4X

;ok 0-9
call WriteChar

L4X: INC esi

LOOP LPrintDigits

mGotoxy 20,15
mWrite “Run Again (y/n): “

L5:

call ReadChar
call WriteChar

;if equals ‘y’
cmp al,79H
je Start

exit
main ENDP
END main

ใส่ความเห็น

XHTML: คุณสามารถใช้แท็กเหล่านี้ได้: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>