ทำให้สุ่มตัวเลขไม่ซ้ำ ทำยังไงคะ (assembly)
INCLUDE Irvine32.inc .data line byte "____________",0 line2 byte "|",0 line3 byte "------------",0 used DWORD 16 DUP (0) indexUSED DWORD 0 sumROW1 DWORD 0 sumCOL1 DWORD 0 sumROW2 DWORD 0 sumCOL2 DWORD 0 sumROW3 DWORD 0 sumCOL3 DWORD 0 sumROW4 DWORD 0 sumCOL4 DWORD 0
.code main PROC mov edx,OFFSET line call WriteString call crlf mov edx,OFFSET line2 call WriteString call Randomize
RERANDOM1: mov edi,0 mov ecx,16 mov eax,16 call RandomRange CHECKifUSED1: cmp eax,used[edi] je RERANDOM1 inc edi loop CHECKifUSED1 call WriteDec mov edi,indexUSED mov used[edi],eax add sumROW1,eax add sumCOL1,eax inc indexUSED
mov edx,OFFSET line2 call WriteString
RERANDOM2: mov edi,0 mov ecx,16 mov eax,16 call RandomRange CHECKifUSED2: cmp eax,used[edi] je RERANDOM2 inc edi loop CHECKifUSED2 call WriteDec mov edi,indexUSED mov used[edi],eax add sumROW1,eax add sumCOL2,eax inc indexUSED
mov edx,OFFSET line2 call WriteString
RERANDOM3: mov edi,0 mov ecx,16 mov eax,16 call RandomRange CHECKifUSED3: cmp eax,used[edi] je RERANDOM3 inc edi loop CHECKifUSED3 call WriteDec mov edi,indexUSED mov used[edi],eax add sumROW1,eax add sumCOL3,eax inc indexUSED
mov edx,OFFSET line2 call WriteString
RERANDOM4: mov edi,0 mov ecx,16 mov eax,16 call RandomRange CHECKifUSED4: cmp eax,used[edi] je RERANDOM4 inc edi loop CHECKifUSED4 call WriteDec mov edi,indexUSED mov used[edi],eax add sumROW1,eax add sumCOL4,eax inc indexUSED
mov edx,OFFSET line2 call WriteString
call crlf mov edx,OFFSET line3 call WriteString call crlf mov edx,OFFSET line2 call WriteString
RERANDOM5: mov edi,0 mov ecx,16 mov eax,16 call RandomRange CHECKifUSED5: cmp eax,used[edi] je RERANDOM5 inc edi loop CHECKifUSED5 call WriteDec mov edi,indexUSED mov used[edi],eax add sumROW2,eax add sumCOL1,eax inc indexUSED
mov edx,OFFSET line2 call WriteString
RERANDOM6: mov edi,0 mov ecx,16 mov eax,16 call RandomRange CHECKifUSED6: cmp eax,used[edi] je RERANDOM6 inc edi loop CHECKifUSED6 call WriteDec mov edi,indexUSED mov used[edi],eax add sumROW2,eax add sumCOL2,eax inc indexUSED
mov edx,OFFSET line2 call WriteString
RERANDOM7: mov edi,0 mov ecx,16 mov eax,16 call RandomRange CHECKifUSED7: cmp eax,used[edi] je RERANDOM7 inc edi loop CHECKifUSED7 call WriteDec mov edi,indexUSED mov used[edi],eax add sumROW2,eax add sumCOL3,eax inc indexUSED
mov edx,OFFSET line2 call WriteString
RERANDOM8: mov edi,0 mov ecx,16 mov eax,16 call RandomRange CHECKifUSED8: cmp eax,used[edi] je RERANDOM8 inc edi loop CHECKifUSED8 call WriteDec mov edi,indexUSED mov used[edi],eax add sumROW2,eax add sumCOL4,eax inc indexUSED
mov edx,OFFSET line2 call WriteString
call crlf mov edx,OFFSET line3 call WriteString call crlf mov edx,OFFSET line2 call WriteString
RERANDOM9: mov edi,0 mov ecx,16 mov eax,16 call RandomRange CHECKifUSED9: cmp eax,used[edi] je RERANDOM9 inc edi loop CHECKifUSED9 call WriteDec mov edi,indexUSED mov used[edi],eax add sumROW3,eax add sumCOL1,eax inc indexUSED
mov edx,OFFSET line2 call WriteString
RERANDOM10: mov edi,0 mov ecx,16 mov eax,16 call RandomRange CHECKifUSED10: cmp eax,used[edi] je RERANDOM10 inc edi loop CHECKifUSED10 call WriteDec mov edi,indexUSED mov used[edi],eax add sumROW3,eax add sumCOL2,eax inc indexUSED
mov edx,OFFSET line2 call WriteString
RERANDOM11: mov edi,0 mov ecx,16 mov eax,16 call RandomRange CHECKifUSED11: cmp eax,used[edi] je RERANDOM11 inc edi loop CHECKifUSED11 call WriteDec mov edi,indexUSED mov used[edi],eax add sumROW3,eax add sumCOL3,eax inc indexUSED
mov edx,OFFSET line2 call WriteString
RERANDOM12: mov edi,0 mov ecx,16 mov eax,16 call RandomRange CHECKifUSED12: cmp eax,used[edi] je RERANDOM12 inc edi loop CHECKifUSED12 call WriteDec mov edi,indexUSED mov used[edi],eax add sumROW3,eax add sumCOL4,eax inc indexUSED
mov edx,OFFSET line2 call WriteString
call crlf mov edx,OFFSET line3 call WriteString call crlf mov edx,OFFSET line2 call WriteString
RERANDOM13: mov edi,0 mov ecx,16 mov eax,16 call RandomRange CHECKifUSED13: cmp eax,used[edi] je RERANDOM13 inc edi loop CHECKifUSED13 call WriteDec mov edi,indexUSED mov used[edi],eax add sumROW4,eax add sumCOL1,eax inc indexUSED
mov edx,OFFSET line2 call WriteString
RERANDOM14: mov edi,0 mov ecx,16 mov eax,16 call RandomRange CHECKifUSED14: cmp eax,used[edi] je RERANDOM14 inc edi loop CHECKifUSED14 call WriteDec mov edi,indexUSED mov used[edi],eax add sumROW4,eax add sumCOL2,eax inc indexUSED
mov edx,OFFSET line2 call WriteString
RERANDOM15: mov edi,0 mov ecx,16 mov eax,16 call RandomRange CHECKifUSED15: cmp eax,used[edi] je RERANDOM15 inc edi loop CHECKifUSED15 call WriteDec mov edi,indexUSED mov used[edi],eax add sumROW4,eax add sumCOL3,eax inc indexUSED
mov edx,OFFSET line2 call WriteString RERANDOM16: mov edi,0 mov ecx,16 mov eax,16 call RandomRange CHECKifUSED16: cmp eax,used[edi] je RERANDOM16 inc edi loop CHECKifUSED16 call WriteDec mov edi,indexUSED mov used[edi],eax add sumROW4,eax add sumCOL4,eax inc indexUSED mov edx,OFFSET line2 call WriteString call crlf mov edx,OFFSET line3 call WriteString call crlf mov ebx,sumCOL1 call WriteDec
exit main ENDP END main
|