組合語言的簡單入門--Loop and output,input

來源:互聯網
上載者:User

程式的目的:將13個隨機數[0-100)儲存在數組裡面,翻轉,輸出。

TITLE Write a program

INCLUDE Irvine32.inc.data

ARRAY_SIZE = 13RAND_MAX = 100HALF_ARRAY_SIZE = ARRAY_SIZE/2rands DWORD ARRAY_SIZE dup(0)

 .codemain PROC

mov esi,offset rands                     ;address to the randsmov ecx,lengthof rands                   ;calculate the size of arrayL1: 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 randsmov ecx,lengthof rands                   ;calculate the size of array

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

 loop L2 call crlf

 

mov esi,offset randsmov ecx,HALF_ARRAY_SIZEmov eax,48L3: 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 randsmov 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

exitmain ENDPEND main


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.