汇编学习笔记《一》

来源:互联网 发布:淘宝网店铺装修实战 编辑:程序博客网 时间:2024/05/25 05:38

两个程序,

1.从键盘输入10个学生成绩,然后输入一个查询成绩,找出是第几个学生的成绩。

2.将一个16进制的数字输出(字符形式)

提供了用于输入,输出的库。

第一个 想用字符串处理,然后数组的元素+1


include io32.inc.datacout dword 0studentdata byte 256 dup(0),0num byte 256 dup(0),0msgtipdis byte '请输入学生成绩',13,0msgreadstudentdata byte '第1个学生成绩',10,13,0  ;1-9个学生集中处理msgreadstudentdatas byte '第10个学生成绩',10,13,0 ;10特殊处理msgselect byte '请输入查找学生的分数',13,10,0msgselectwin byte '该学生是',0                msgfailure byte '没有找到该学生',13,10,0.codestart:mov eax, offset msgtipdiscall dispmsgmov ecx, 9mov ebx,offset studentdatadisstudent:                    ;每次msgreadstudentdata[2]+1,屏幕分别显示1,2,3,4,5,6,7,8,9个学生mov eax,offset msgreadstudentdatacall dispmsgmov eax,ebxcall readmsginc msgreadstudentdata[2]add ebx,2loop disstudentmov eax,offset msgreadstudentdatascall dispmsg mov eax,ebxcall readmsg;mov eax,offset studentdata;call dispmsgmov eax,offset msgselect ;查找学生分数的字符串call dispmsgmov eax,offset num;输入需要查找的学生成绩call readmsg;readmsg接口是 eax=[字符串地址]mov esi,offset studentdata;studentdata地址给esimov edi, offset num;num地址给edimov ecx,10;循环10次again:inc coutmov bx,[esi]mov ax,[edi]and ax,65535and bx,65535cmp ax,bx    ;每次比对je printfadd esi,2loop againjmp overprintf:mov eax,offset msgselectwincall dispmsgmov eax,coutcall dispsidover:exit 0end start 

第2个有点蛋疼了,因为是32位存数,进行8次移位循环,每次ROL4位,本来很简单的,浪费了很多时间。

;转化16进制include io32.inc   .datanum1 dword 123ccHpromotmsg byte '16进制数字转化为字符输出.num=123ccH',13,10,0result byte 'num=',32 dup(0),'H',13,10,0.codestart:mov eax,offset promotmsgcall dispmsgmov eax,num1mov ecx,8mov esi,0shiftfour:     ;每次移动4位  rol eax,4  ;循环右移动,每次移动4个位,地位不会丢失  push eax  call changefour  mov result+4[esi],al  pop eax  inc esiloop shiftfourmov eax,offset resultcall dispmsgexit 0     changefour:          and eax,0fh          or eax,30h      ;‘0’的ascall码值为30H          cmp al,'9'      jbe over           add al,7     over :                 retend start



原创粉丝点击