masm615 組合語言 的 不重複亂數問題,附有程式碼
大家好~~
我所使用的組合語言軟體是 masm615
問題是,我想要用組合語言寫出不重複亂數,我有用C寫出來,但是組合不會寫
但是去 不知道錯誤在那裡,請高手們 幫幫忙寫出來,若可以的話,請順手注解意思
謝謝~~~
INCLUDE Irvine32.inc
.data
a DWORD 10 dup(0)
count dword 1
x dword 0
y dword 0
str1 byte "success",13,10,0
.code
main PROC
call clrscr
mov esi,offset a
call randomize
.while (x<10)
mov eax,10
call randomrange
mov esi,offset a
.while(count == 1)
mov y,0
.while(y<10)
.if([esi]==eax)
mov count,1
mov esi,offset a
mov eax,10
call randomrange
.else
add esi,4
mov count,0
.endif
add y,1
.endw ;while inside
.endw
mov [esi],eax
add esi,4
call writeint
inc x
.endw
exit
main ENDP
END main
我學習過 用 DEC C++ 寫 C程式
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define max 10
int HasAppear(int a[max],int);/*檢查已出現的數值*/
void ShowArray(int a[max]);/*顯示陣列*/
//===================================
int main(void)
{
int i,j;
int card[max]={0};
int temp;/*作為 暫存亂數 的 元素*/
srand(time(NULL));
for(i=0;i<max;i++)
{
temp=rand()%max + 1; /*產生亂數*/
while(HasAppear(card, temp) == 1)/*呼叫副程式比較是否曾經出現*/
{
temp=rand()%max +1;/*曾經出現,再重新產生亂數*/
}
card[i]=temp;/*暫存元素 存入 陣列內*/
}
ShowArray(card);
system("Pause");
return 0;
}
//======================================================
int HasAppear(int a[max], int temp)
{
int i,j;
for(i=0;i<max;i++)
{
if(a[i]==temp) return 1;/*跑陣列,01234這樣慢慢的比較整個回圈,相同的就回傳true*/
}
return 0;/*沒有相同的就 回傳 false*/
}
//=======================================================
void ShowArray(int a[])
{
int i,j;
for(i=0;i<max;i++)
{
printf("%2d", a[i]);
printf("\n");
}
}
|