วันพฤหัสบดีที่ 26 สิงหาคม พ.ศ. 2553

Assemble-com: lab09 onvert-num-word2char

Assemble-com: lab09 onvert-num-word2char: "Lab09 ------- ----------------------------------------------------------------- โจทย์ ถ้ามีข้อมูลชนิดเลขจำนวนเต็ม 1 เวิร์ด (2 ไบท์-16 ..."

lab09 onvert-num-word2char

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

วันอังคารที่ 24 สิงหาคม พ.ศ. 2553

java

public class array {
private int x;

public void aArray(){
int[]array1 = new int[13];
int i=0;
int l=1;
for( i = 0; l<=12; i++){
array1[i]=2*l;
System.out.println(array1[i]);
l++;
}
}

public void triple(){
int[]array2 = new int[10];
for(int i=0;i<=9;i++){
array2[i] = i*i*i;
System.out.println(array2[i]);
}
}

public void sum1(){
int sum = 0;
int[]array1 = new int[13];
int i=0;
for( i = 1; i<=12; i++){
array1[i]=2*i;
sum = sum+array1[i];
}System.out.println("SUMARRAY1 :"+sum);
}

public void sum2(){
int sum =0;
int[]array2 = new int[10];
for(int i=0;i<=9;i++){
array2[i] = i*i*i;
sum = sum+array2[i];
}System.out.println("SUMARRAY2 :"+sum);
}

public void sumArray(){

int sumIndex =0;
int[]array1 = new int[10];
int []array2 = new int[10];
int i=0;
int j=1;

for( i = 0; i<=9; i++){
array1[j]=2*j;
array2[i]=i*i*i;
sumIndex = array1[j]+array2[i];
System.out.println(sumIndex);
j++;
}
}
public void Sort(){
int[]array={14,25,7,8,19};
int i=0;
int j =4;
int swarp = 0;
for(i=0;i<=2;i++){
swarp=array[i];
array[i]=array[j];
array[j]=swarp;
j--;
}
for(int swapp=0;swapp
System.out.print(array[swapp]+" ");
}
}
}


Main



public class mainArray {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
array a = new array();
//a.aArray();
//System.out.println();
//a.triple();
//a.sum1();
//a.sum2();
//a.sumArray();
a.Sort();
}

}

วันพฤหัสบดีที่ 29 กรกฎาคม พ.ศ. 2553

num

;program add_num;Jirayu Yawut 5204101319
.model small.datanum1 byte ? ;first numnum2 byte ? ;second num
msg1 byte 0ah,0dh,"INPUT NUMBER>$"msg2 byte 0ah,0dh,"SUM IS>"result byte "*$"
.codemain proc mov ax,@data ;data segment mov ds,ax mov cx,1 mov bx,0
mov ah,9 mov dx,offset msg1 ;show msg1 int 21h mov ah,1 ;wait from keyboard int 21h mov num1[bx],al sub al,30h inc bx
mov ah,9 mov dx,offset msg1 ;show msg1 int 21h
mov ah,1 ;wait from keyboard int 21h mov num2[bx],bl sub bl,30h inc bx
add bl,al mov result,bl
mov ah,9 mov dx,offset msg2 ;show msg2 int 21h
add bl,30h mov result,bl
mov ah,9 mov dx,offset msg2 ;show msg2 int 21h
mov ah,4ch ;exit to DOS int 21h
main endpend

วันพฤหัสบดีที่ 22 กรกฎาคม พ.ศ. 2553

assbly coppy der

Microsoft (R) Macro Assembler Version 6.15.8803 07/23/10 09:22:52
First Pass 1 - 1


;Input string area print reverse direction
;WICHAI JANWISED ID 5204101389
.model small
0000 .data
msg1 byte 0ah,0dh, "Hello,Welcome to MJU"
byte 0ah,0dh, "Your reverse name is $ "
inst byte "??????$"
msg2 byte 0ah,0dh, "Glad to see you naja$"
CrLf byte 0ah,0dh,'$'
0000 .code
0000 main proc
mov ax,DGROUP ;define data segment
mov ds,ax
mov cx,6
mov bx,5
loop1:
mov ah,1 ;wait for kb
int 21h
mov inst[bx],al
dec bx
loop loop1

mov ah,9 ;display newline
mov dx,offset CrLf
int 21h

mov ah,9 ;display msg1
mov dx,offset msg1
int 21h

mov ah,9 ;display inst
mov dx,offset inst
int 21h

mov ah,9 ;display msg2
mov dx,offset msg2
int 21h

;exit to DOS
mov ah,4ch
int 21h
0036 main endp
end
Microsoft (R) Macro Assembler Version 6.15.8803 07/23/10 09:22:52
reverse.asm Page 1 - 1


;Input string area print reverse direction
;WICHAI JANWISED ID 5204101389
.model small
0000 .data
0000 0A 0D 48 65 6C 6C msg1 byte 0ah,0dh, "Hello,Welcome to MJU"
6F 2C 57 65 6C 63
6F 6D 65 20 74 6F
20 4D 4A 55
0016 0A 0D 59 6F 75 72 byte 0ah,0dh, "Your reverse name is $ "
20 72 65 76 65 72
73 65 20 6E 61 6D
65 20 69 73 20 24
20
002F 3F 3F 3F 3F 3F 3F inst byte "??????$"
24
0036 0A 0D 47 6C 61 64 msg2 byte 0ah,0dh, "Glad to see you naja$"
20 74 6F 20 73 65
65 20 79 6F 75 20
6E 61 6A 61 24
004D 0A 0D 24 CrLf byte 0ah,0dh,'$'
0000 .code
0000 main proc
0000 B8 ---- R mov ax,@data ;define data segment
0003 8E D8 mov ds,ax
0005 B9 0006 mov cx,6
0008 BB 0005 mov bx,5
000B loop1:
000B B4 01 mov ah,1 ;wait for kb
000D CD 21 int 21h
000F 88 87 002F R mov inst[bx],al
0013 4B dec bx
0014 E2 F5 loop loop1

0016 B4 09 mov ah,9 ;display newline
0018 BA 004D R mov dx,offset CrLf
001B CD 21 int 21h

001D B4 09 mov ah,9 ;display msg1
001F BA 0000 R mov dx,offset msg1
0022 CD 21 int 21h

0024 B4 09 mov ah,9 ;display inst
0026 BA 002F R mov dx,offset inst
0029 CD 21 int 21h

002B B4 09 mov ah,9 ;display msg2
002D BA 0036 R mov dx,offset msg2
0030 CD 21 int 21h

;exit to DOS
0032 B4 4C mov ah,4ch
0034 CD 21 int 21h
0036 main endp
end
Microsoft (R) Macro Assembler Version 6.15.8803 07/23/10 09:22:52
reverse.asm Symbols 2 - 1




Segments and Groups:

N a m e Size Length Align Combine Class

DGROUP . . . . . . . . . . . . . GROUP
_DATA . . . . . . . . . . . . . 16 Bit 0050 Word Public 'DATA'
_TEXT . . . . . . . . . . . . . 16 Bit 0036 Word Public 'CODE'


Procedures, parameters and locals:

N a m e Type Value Attr

main . . . . . . . . . . . . . . P Near 0000 _TEXT Length= 0036 Private


Symbols:

N a m e Type Value Attr

@CodeSize . . . . . . . . . . . Number 0000h
@DataSize . . . . . . . . . . . Number 0000h
@Interface . . . . . . . . . . . Number 0000h
@Model . . . . . . . . . . . . . Number 0002h
@code . . . . . . . . . . . . . Text _TEXT
@data . . . . . . . . . . . . . Text DGROUP
@fardata? . . . . . . . . . . . Text FAR_BSS
@fardata . . . . . . . . . . . . Text FAR_DATA
@stack . . . . . . . . . . . . . Text DGROUP
CrLf . . . . . . . . . . . . . . Byte 004D _DATA
inst . . . . . . . . . . . . . . Byte 002F _DATA
loop1 . . . . . . . . . . . . . L Near 000B _TEXT
msg1 . . . . . . . . . . . . . . Byte 0000 _DATA
msg2 . . . . . . . . . . . . . . Byte 0036 _DATA

0 Warnings
0 Errors
WICHAI

Hello,Welcome to MJU
Your reverse name is IAHCIW
Glad to see you naja