Programming

Just another WordPress.com weblog

ข้อสอบ CT215 ปี 2551 เขียน code assembly ยาว

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

เป็นส่วนของการเขียน program ยาว ซึ่งเป็นตัวอย่างหนึ่งเท่านั้น อาจารย์สามารถออกโจทย์ได้เยอะมากครับ

โจทย์ ป้อนตัวอักษร a-z พิมพ์เล็ก เมื่อกด Enter จะให้พิมพ์ตัวอักษรพิมพ์ใหญ่ออกมาและพิมพ์จำนวนตัวอักษรออกมา จากนั้น program จะถาม y/n ว่าจะ run ต่อหรือไม่

LowerCase To UpperCase
LowerCase Characters: abcdefg
UpperCase Characters: ABCDEFG
Num of Uppercase Characters: +7
Run Again (y/n):

————–

TITLE (.asm)

; This program
; Last update:

Include Irvine32.inc
Include Macros.inc
.data

lowerchars BYTE 128 DUP(0)

.code
main PROC

Start:

call Clrscr

mov esi, OFFSET lowerchars

mGotoxy 20,10
mWrite <”LowerCase To UpperCase”,0dh,0ah>

mGotoxy 20,11
mWrite “LowerCase Characters: “

mov ebx,0
mov ecx,0

L1:

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

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

;if less than ‘z’
cmp al,7aH
ja L1

;ok a-z
call WriteChar

mov [esi], al

INC esi
INC ebx

jmp L1

L2:

mGotoxy 20,12
mWrite “UpperCase Characters: “

mov esi, OFFSET lowerchars
mov ecx, ebx

cmp ecx,0
je LX

L3:

mov al, [esi]
sub al, 20H

call WriteChar

INC esi

LOOP L3

LX:

mGotoxy 20,13
mWrite “Num of Uppercase Characters: “
mov eax, ebx
call WriteInt

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

L4:

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>