当前位置: 代码迷 >> 汇编语言 >> 编译语言的简单入门
  详细解决方案

编译语言的简单入门

热度:219   发布时间:2016-05-02 04:49:00.0
汇编语言的简单入门

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

TITLE Write a programINCLUDE Irvien32.inc.dataARRAY_SIZE = 13RAND_MAX = 100HALF_ARRAY_SIZE = ARRAY_SIZE/2rands DWORD ARRAY_SIZE dup(0).codemainPROCmov esi,offset rands       ;address to the randsmov ecx,lengthof rands     ;calculate the size of arrayL1:mov eax,RAND_MAX           ;for random the maxinum numbercall RandomRange           ;call this functionmov [esi],eax 		   ;set the element that is saved in EAX to [esi]add esi,TYPE rands         ;point to next elementloop L1mov esi,offset rands       ;address to the randsmov ecs,lengthof rands     ;calculate the size of arrayL2:mov eax,[esi]              ;put the [esi] to eax for outputing call writeint              ;outputmov eax,' '                ;output the space call writecharadd esi,TYPE rands         ;point to next pointerloop L2call crlf                  ;next linemov esi,offset rands + 48  ;address to the last elementmov ebx,offset rands       ;address to the first elementmov ecx,HALF_ARRAY_SIZE    ;execute for HALF_ARRAY_SIZE timesL3:mov ebp,[esi]              ;use esp to save the last elementmov esp,[ebx]              ;use esp to save the first elementmov [esi],esp              ;reverse the elememtmov [ebx],ebp              ;sub esi,TYPE rands         ;pointer point the next pointer from the last oneadd ebx,TYPE rands         ;pointer point the next pointer from the first oneloop L3mov esi,offset randsmov ecx,ARRAY_SIZEL4:mov eax,[esi]cal writeintmov eax,' 'call writecharadd esi,TYPE randsloop L4call crlfcall waitmsg              ;output "Press any key to continue..."exitmain ENDPEND main
  相关解决方案