开源中文网

您的位置: 首页 > 编程开发 > 汇编语言 > 正文

汇编语言的简单入门--Loop and output,input

来源: csdn博客  作者: 我叫huazhi

程序的目的:将13个随机数[0-100)存储在数组里面,翻转,输出。

INCLUDE Irvine32.inc 
.data</p><p>ARRAY_SIZE = 13 
RAND_MAX = 100 
HALF_ARRAY_SIZE = ARRAY_SIZE/2 
rands DWORD ARRAY_SIZE dup(0)</p><p>  
.code 
main PROC</p><p>mov esi,offset rands                     ;address to the rands 
mov ecx,lengthof rands                   ;calculate the size of array 
L1: 
mov eax,RAND_MAX                     ;for random the maxinum number 
call RandomRange         ;call this function 
mov [esi],eax                   ;set the element that is save in EAX to [esi] 
add esi,TYPE rands                   ;point to next element 
loop L1 
  
mov esi,offset rands      ;address to the rands 
mov ecx,lengthof rands                   ;calculate the size of array</p><p>L2: 
mov eax,[esi]                        ;put the [esi] to eax for outputing 
call writeint 
mov eax,' '                          ;output the space 
call writechar 
add esi,TYPE rands                   ;point to next pointer</p><p> loop L2 
  
call crlf</p><p> </p><p>mov esi,offset rands 
mov ecx,HALF_ARRAY_SIZE 
mov eax,48 
L3: 
mov ebx,[esi]                 ;put the first element to ebx 
mov ebp,[esi + eax]           ;put the last element to ebp 
mov [esi + eax],ebx           ;exchange the element 
mov [esi],ebp 
  
sub eax,8                     ;for changeing the pointer 
add esi,TYPE rands 
loop L3 
  
mov esi,offset rands 
mov ecx,ARRAY_SIZE 
                                            ;for outputing 
                 ; 
L4: 
mov eax,[esi] 
call writeint 
mov eax,' ' 
call writechar 
add esi,TYPE rands 
loop L4  
  
call crlf   
call waitmsg</p><p>exit 
main ENDP 
END main  

Tags:Loop and output input
相关文章列表:
关于开源中文网 - 联系我们 - 广告服务 - 网站地图 - 版权声明