Lab09
-------
-----------------------------------------------------------------
โจทย์ ถ้ามีข้อมูลชนิดเลขจำนวนเต็ม 1 เวิร์ด (2 ไบท์-16 บิท) ที่ num
จงแสดงผลออกเป็นตัวเลขฐานสิบ 5 หลักที่เป็นค่าของ num
;convert num word to 5 chars string
.data
num word 0109h
OutStr byte 5 dup (20h)
byte '$'
.code
:
:
mov di,offset OutStr
mov cx,5
mov bx,10
mov ax,num
L2:
mov dx,0
div bx
add dl,30h
mov [di],dl
dec di
loop L2
;display OutStr
:
:
---> ตรวจสอบคำตอบ ผลที่แสดงบนจอต้องเป็น 0 0 2 5 6 <---
--------------------------------------------------------------------
ท้าทาย level 1: กำหนดค่า num1 และ num2 เป็นข้อมูลชนิดเวิร์ด
ให้คำนวณหาค่า num = num1+num2
ผลที่ได้แสดงบนจอ เช่น
num1 word 260d
num2 word 132d
num word ?
OutStr byte 5 dup (20h)
byte '$'
แสดงผลเป็น 3 9 2 หรือ 0 0 3 9 2
ท้าทาย level 2: กำหนดค่า num1 และ num2 เป็นข้อมูลชนิดเวิร์ด
อ่านข้อมูลจากแป้นพิมพ์ 3 หลักเป็นจำนวนที่ 1 convert เป็นค่า num1 เช่น
ป้อนข้อมูลเป็น '1' '2' '0' ได้ค่าเป็น 120d
อ่านข้อมูลจากแป้นพิมพ์ 3 หลักเป็นจำนวนที่ 2 convert เป็นค่า num2 เช่น
ป้อนข้อมูลเป็น '0' '2' '5' ได้ค่าเป็น 25d
ให้คำนวณหาค่า num = num1+num2
ผลที่ได้แสดงบนจอ เช่น
num1 word ?
num2 word ?
num word ?
แสดงผลเป็น 1 4 5 หรือ 0 0 1 4 5
***การ convert จาก input string ให้เป็นเลขจำนวน (convert to num)
ดูได้จากเว็บ 172.17.2.5 ***
หมายเหตุ คำสั่งคูณ MUL BL หมายถึงคูณค่าใน AX ด้วย BL
ผลลัพธ์เก็บไว้ที่ AX
คำสั่งคูณ MUL BX หมายถึงคูณค่าใน AX ด้วย BX
ผลลัพธ์เก็บไว้ที่ AX เมื่อ CF=0(หรือ DX:AX เมื่อ CF=1)
คำสั่งหาร DIV BX หมายถึงหารค่าใน AX ด้วย BX
ผลลัพธ์เก็บไว้ที่ AX เศษเก็บไว้ที่ DL
คำสั่งหาร DIV BL หมายถึงหารค่าใน AX ด้วย BL
ผลลัพธ์เก็บไว้ที่ AL เศษเก็บไว้ที่ AH
ตัวอย่างโปรแกรม
-------------------------------------------------------------------------------
.model small
.data
msg1 byte 0ah,0dh,"input string num1:"
instr1 byte 4 dup (20h)
byte 0ah,0dh,"$"
msg2 byte 0ah,0dh,"input string num2:"
instr2 byte 4 dup (20h)
byte 0ah,0dh,"$"
num1 word 0
num2 word 0
num word 0
result byte "result is "
outstr byte 5 dup (20h)
byte "$"
.code
main proc
mov ax,@data
mov ds,ax
mov di,offset instr1
call GetInp
mov dx, offset msg1
call DispOut
:
:
;convert to num word
:
mov di,offset instr2
call GetInp
mov dx, offset msg2
call DispOut
:
:
;convert to num word
:
mov ax,num1
add ax,num2
mov num,ax
call ConvOutstr
mov dx,offset result
call DispOut
mov ax,4c00h
int 21h
main endp
;----------------------------------------------------------------
GetInp proc ;get 4 digit input from k/b
mov cx,4
L1:
mov ah,1
int 21h
mov [di],al
inc di
loop L1
ret
GetInp endp
;-----------------------------------------------------------------
ConvertNum proc ;convert input string to Num word
:
:
ret
ConvertNum endp
;-----------------------------------------------------------------
ConvOutstr proc ;convert from num to output string
mov di,offset outstr
mov cx,5
mov bx,10
mov ax,num
L2:
mov dx,0
div bx
add dl,30h
mov [di],dl
dec di
loop L2
ret
ConvOutstr endp
;-----------------------------------------------------------------
DispOut proc ;display output string
mov ah,9
int 21h
ret
DispOut endp
;-----------------------------------------------------------------
end
สมัครสมาชิก:
ส่งความคิดเห็น (Atom)

http://f1.uploadfile.biz/file/?i=MNEZMEIEIEDHMX
ตอบลบไฟล์เพิ่มเติม
ตอบลบhttp://f1.uploadfile.biz/file/?i=MNEZMEIEIEDHMX
http://f1.uploadfile.biz/file/?i=MNEZMEIEIMMIEX
ตอบลบfile work sent to teacher
ตอบลบhttp://f1.uploadfile.biz/file/?i=MNEZMEIEIMMIEX