Programming

Just another WordPress.com weblog

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

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

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

โจทย์ บวกตัวเลขโดยใช้หลักการของการบวกรหัส ASCII

Summation of ASCII
Please Enter First ASCII Integer XXX: 4568
Please Enter Second ASCII Integer XXX: 1112
Summation XXXX: 05680

—————–

TITLE (.asm)

; This program
; Last update:

Include Irvine32.inc
Include Macros.inc
.data

ascii1 BYTE 4 DUP(0)
ascii2 BYTE 4 DUP(0)
ascsum BYTE 5 DUP(0),0

.code
main PROC

Start:

call Clrscr

mGotoxy 20,10
mWrite <”Summation of ASCII”,0dh,0ah>

mGotoxy 20,11
mWrite “Please Enter First ASCII Integer XXX: “

mov ecx,4
mov esi, OFFSET ascii1

L1:

call readChar
cmp al, 30H
jb L1
cmp al, 39H
ja L1

call WriteChar
mov [esi],al

inc esi

loop L1

mGotoxy 20,12
mWrite “Please Enter Second ASCII Integer XXX: “

mov ecx,4
mov esi, OFFSET ascii2

L2:

call readchar
cmp al, 30H
jb L2
cmp al, 39H
ja L2

call WriteChar
mov [esi], al

inc esi

loop L2

CLC

mov esi, OFFSET ascii1 + 3
mov edi, OFFSET ascii2 + 3
mov ebx, OFFSET ascsum + 4

mov ecx, 4

A20:

mov AH,00
mov AL,[esi]

ADC AL,[edi]

AAA

mov [ebx],AL

dec ESI
dec EDI
dec EBX

loop A20

;last carry
mov [ebx],AH

;;change to ascii
mov ebx, OFFSET ascsum+4
mov ecx, 5

A30:

OR BYTE PTR [ebx], 30H
dec ebx

loop A30

;print edx
mGotoxy 20,13
mWrite “Summation XXXX: “
mov edx, OFFSET ascsum
call WriteString

mGotoxy 20,14
mWrite “Continue (y/n): “
call ReadChar
call WriteChar

cmp al,79H
je Start

exit
main ENDP
END main

2 Responses ถึง “ข้อสอบ CT215 ปี 2551 เขียน code assembly ยาว”

  1. Spore กล่าว

    สอบ CT215 ผ่านได้จะยกความดีให้เลยอ่ะ

ใส่ความเห็น

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