欢迎来到Doc100.Net免费学习资源知识分享平台!
您的位置:首页 > 程序异常 >

编译语言的简单入门

更新时间: 2014-01-05 03:16:46 责任编辑: Author_N1

 

汇编语言的简单入门

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

TITLE Write a program

INCLUDE Irvien32.inc

.data

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

.code
mainPROC

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 saved in EAX to [esi]
add esi,TYPE rands         ;point to next element
loop L1

mov esi,offset rands       ;address to the rands
mov ecs,lengthof rands     ;calculate the size of array

L2:
mov eax,[esi]              ;put the [esi] to eax for outputing 
call writeint              ;output
mov eax,' '                ;output the space 
call writechar
add esi,TYPE rands         ;point to next pointer
loop L2

call crlf                  ;next line

mov esi,offset rands + 48  ;address to the last element
mov ebx,offset rands       ;address to the first element
mov ecx,HALF_ARRAY_SIZE    ;execute for HALF_ARRAY_SIZE times

L3:
mov ebp,[esi]              ;use esp to save the last element
mov esp,[ebx]              ;use esp to save the first element
mov [esi],esp              ;reverse the elememt
mov [ebx],ebp              ;
sub esi,TYPE rands         ;pointer point the next pointer from the last one
add ebx,TYPE rands         ;pointer point the next pointer from the first one
loop L3


mov esi,offset rands
mov ecx,ARRAY_SIZE

L4:
mov eax,[esi]
cal writeint
mov eax,' '
call writechar
add esi,TYPE rands
loop L4

call crlf
call waitmsg              ;output "Press any key to continue..."

exit
main ENDP
END main
上一篇:上一篇
下一篇:下一篇

 

随机推荐程序问答结果

 

 

如对文章有任何疑问请提交到问题反馈,或者您对内容不满意,请您反馈给我们DOC100.NET论坛发贴求解。
DOC100.NET资源网,机器学习分类整理更新日期::2014-01-05 03:16:46
如需转载,请注明文章出处和来源网址:http://www.doc100.net/bugs/t/20340/
本文WWW.DOC100.NET DOC100.NET版权所有。