为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

汇编语言例

2012-06-29 40页 pdf 343KB 19阅读

用户头像

is_544305

暂无简介

举报
汇编语言例 1读寄存器内容的源代码 我的环境是WINXP+MASM5.0通过编译生成可执 行文 件,双击,提示写入文件成功,按任意键推出。 在程序的同一目录下的 TEMP.TXT中已经写入了: ABCD 4645 4F5B FFFF 四行用来测试而显示送入寄存器的值。 以下是完整的代码, MovToVar Macro m_Reg,Asc_AX mov bx,m_Reg call ConvertToAsc lea si,CAscii lea di,Asc_AX mov cx,4d rep movsb EndM data segmen...
汇编语言例
1读寄存器内容的源代码 我的环境是WINXP+MASM5.0通过编译生成可执 行文 件,双击,提示写入文件成功,按任意键推出。 在程序的同一目录下的 TEMP.TXT中已经写入了: ABCD 4645 4F5B FFFF 四行用来测试而显示送入寄存器的值。 以下是完整的代码, MovToVar Macro m_Reg,Asc_AX mov bx,m_Reg call ConvertToAsc lea si,CAscii lea di,Asc_AX mov cx,4d rep movsb EndM data segment mAX dw 0 mBX dw 0 mCX dw 0 mDX dw 0 AscAX db 4 dup(?),0dh,0ah AscBX db 4 dup(?),0dh,0ah AscCX db 4 dup(?),0dh,0ah AscDX db 4 dup(?),0dh,0ah WriteBytes EQU $-AscAX CAscii db 5 dup(?) ;临时存放转化结果 filename db 'temp.txt$',0h filehandle dw ? ferr_num1 db 'Error occurred when create file!$' ferr_num2 db 'Write file error!$' tssaveok db 'Write register value to file success.$' tsexit db 'Press any key to exit...$' data ends Code segment assume cs:code,ds:data,es:data Main proc far start: push ds sub ax,ax mov ax,data mov ds,ax mov es,ax sub ax,ax mov ax,0ABCDh ;四个测试数据 mov bx,4645h mov cx,4F5Bh mov dx,0FFFFh call SaveRegToMem call MovAll call SaveToFile call NextLine lea dx,tsexit call ShowString waittoexit: mov ah,0h int 16h exitprogram: mov ah,4ch int 21h Main Endp MovAll proc near push ax push bx push cx push dx MovToVar mAX,AscAX MovToVar mBX,AscBX MovToVar mCX,AscCX MovToVar mDX,AscDX pop dx pop cx pop bx pop ax ret MovAll endp SaveRegToMem proc near mov mAX,ax mov mBX,bx mov mCX,cx mov mDX,dx ret SaveRegToMem endp ShowString proc near ;显示 DX所指的字符串 push ax mov ah,09h int 21h pop ax ret ShowString endp NextLine proc near ;回车换行 mov ah,02h mov dl,0dh int 21h mov ah,02h mov dl,0ah int 21h ret NextLine endp ConvertToAsc proc near ;参数为 BX ;将 BX中的二进制数据转化成相应的 ASCII码, ;并将结果保存到 CAscii[] PUSH AX PUSH CX PUSH DX mov bp,0h mov ch,4h xh: mov cl,4h rol bx,cl mov al,bl and al,0fh add al,30h cmp al,3ah ;whether >'9'(Ascii:49) jl toCascii ;if not then store to CAscii add al,7h ;if yes then convert it to ascii toCascii: mov CAscii[bp],al inc bp dec ch jnz xh mov CAscii[bp],'$' POP DX POP CX POPAX ret ConvertToAsc endp SaveToFile PROC NEAR ;保存内存中的数据到文件中 mov ah,3ch mov cx,0h lea dx,filename int 21h ;建立文件 jc ferr1 ;如果建立出错,跳转到显示相应信息 mov filehandle,ax ;文件代号存放入内存变量 mov ah,40h mov bx,filehandle mov cx,WriteBytes ;将要写入文件的字节数送入 CX lea dx,AscAX int 21h ;向文件写入以记录首地址开始的 AX个字 节 jc ferr1 ;如果写入错误,则跳转到显示相关信息处 cmp ax,WriteBytes ;如果写入文件的实际字节数不 是要求写入的字节数 jne ferr2 ;则显示跳转到显示出错信息 mov bx,filehandle mov ah,3eh int 21h ;关闭文件 lea dx,tssaveok call showstring call nextline ret ferr1: lea dx,ferr_num1 call showstring call nextline ret ferr2: lea dx,ferr_num2 call showstring call nextline ret SaveToFile ENDP Code ends end start 2汇编语言制作的光带菜单及源程序(1.0) 这个是我上大二的时候的汇编语言课程。自己 做得很满意。现在拿出来,给大家看看。我对部分 代码又从新做了调整。编译后大小比原来大了一 点,不过速度上去了。其实就是一个图形接口。你 只要在中间加上自己的实用功能,就可以直接用 了。代码我都有注释,读起来应该不会有什么问题。 当然,汇编的代码本身就很难读。所以有什么不是 很好懂的地方,可以直接同我联系。 我还给同学做过一个 C语言版的光带菜单, 不过很可惜的是自己做得不是很满意,就把程序给 删掉了。大家也就看不到了 本程序用 tasm 进行编译,tlink 进行连接。 menu.asm 主程序 mnmacro.asm 功能调用宏文件 menu.exe 编译后的可执行文件 menu.asm 主程序 include mnmacro.asm data segment scrmm db 100 dup(?) ;主菜单名 mainmenu1 db 'File' mainmenu2 db 'Edit' mainmenu3 db 'Run' mainmenu4 db 'Debug' mainmenu5 db 'Help' ;主菜单 File 下的子菜单名 submenu11 db 'Save' submenu12 db 'Open' submenu13 db 'Exit' ;主菜单 Edit下的子菜单名 submenu21 db 'Cut' submenu22 db 'Past' submenu23 db 'Copy' ;主菜单 Run下的子菜单名 submenu31 db 'Run' submenu32 db 'Go to' submenu33 db 'Step' ;主菜单 Debug下的子菜单名 submenu41 db 'Call' submenu42 db 'Find' submenu43 db 'Source' ;主菜单 Help下的子菜单名 submenu51 db 'About' submenu52 db 'Our' submenu53 db 'Web' ;欢迎窗口信息 msgtitle db 'Assemble Design' msg1 db 'Please press Alt+F,Alt+E,Alt+R,Alt+D,Alt+H or ',19h,' to open the submenu.' msg2 db 'Please press Enter (',11h,0c4h,0d9h,') to close the submenu.' msg3 db 'Please press ',1bh,' or ',1ah,' to select the mainmenu.' msg4 db 'Please press ',18h,' or ',19h,' to select the submenu.' msg5 db 'Copyright 2002 mikespook' msg6 db 'Press any key to continue...' msg7 db ' ' ;退出窗口信息 ' over db 'Thank you for uesing...Good buy~~ ' ;其他信息 escape db 'Press ESC to exit.' text1 db 'This is a example showing you how to make a menu with assemble.' text2 db 'And you could get it for free from http://lucky7.yeah.net.' text3 db 'You could use it in your software freely.' text4 db 'But please send me a copy of your software.' text5 db 'Thank you. Have a good time.' text6 db '--Yours truly mikespook' sub11 db 'Select Save' sub12 db 'Select Open' sub13 db 'Select Exit' sub21 db 'Select Cut' sub22 db 'Select Past' sub23 db 'Select Copy' sub31 db 'Select Run' sub32 db 'Select Go to' sub33 db 'Select Step' sub41 db 'Select Call' sub42 db 'Select Find' sub43 db 'Select Source' sub51 db 'Select About' sub52 db 'Select Our' sub53 db 'Select Web' ;------------------------- mainnum db 1;主菜单序列号 subnum db ?;子菜单序列号 subshow db 0;为 0时子菜单未显示 mainindex db ?;主菜单字符长度 data ends ;-------------------------------- code segment assume cs:code,ds:data,es:data start: mov ax,data mov ds,ax mov es,ax ;******************* 初始化屏幕开始 mov ah,0 mov al,03h int 10h ;******************* 初始化屏幕结束 showcur 1 ;隐藏光标 ;************************************* 开 始 主窗口的绘制 drawwindow 1eh,0,0,24,79 outputstr msgtitle,15,10,30,13h outputstr msg1,68,15,5,17h changemenu 15,18,5,1eh changemenu 15,24,5,1eh changemenu 15,30,5,1eh changemenu 15,36,5,1eh changemenu 15,42,5,1eh changemenu 15,51,1,1eh outputstr msg2,46,16,5,17h changemenu 16,18,11,1eh outputstr msg3,43,17,5,17h changemenu 17,18,1,1eh changemenu 17,23,1,1eh outputstr msg4,42,18,5,17h changemenu 18,18,1,1eh changemenu 18,23,1,1eh outputstr msg5,24,13,5,1fh outputstr msg6,28,20,40,9eh outputstr msg7,19,9,28,93h outputstr msg7,19,11,28,93h setpos 10,28 outputchar ' ',93h,1 setpos 10,46 outputchar ' ',93h,1 mov ah,07h int 21h drawwindow 1eh,0,0,24,79 drawwindow 70h,0,0,0,79 drawwindow 70h,24,0,24,79 setpos 1,0 windowtandb 0d5h,0cdh,0b8h,1,0,80,1eh mov al,2 draw: windowlandr 0b3h,al,0,80,1eh inc al cmp al,17h jne draw windowtandb 0c0h,0c4h,0d9h,23,0,80,1eh outputstr escape,18,24,3,70h ;********** *****************************开始主菜单的绘 制 setpos 0,3 outputstr mainmenu1,4,0,3,0fh outputstr mainmenu2,4,0,13,70h changemenu 0,13,1,74h outputstr mainmenu3,3,0,23,70h changemenu 0,23,1,74h outputstr mainmenu4,5,0,33,70h changemenu 0,33,1,74h outputstr mainmenu5,4,0,43,70h changemenu 0,43,1,74h setpos 0,3 ;*********************************** 结束主 窗口和主菜单的绘制 outputstr msg1,68,15,5,17h changemenu 15,18,5,1eh changemenu 15,24,5,1eh changemenu 15,30,5,1eh changemenu 15,36,5,1eh changemenu 15,42,5,1eh changemenu 15,51,1,1eh outputstr msg2,46,16,5,17h changemenu 16,18,11,1eh outputstr msg3,43,17,5,17h changemenu 17,18,1,1eh changemenu 17,23,1,1eh outputstr msg4,42,18,5,17h changemenu 18,18,1,1eh changemenu 18,23,1,1eh outputstr text1,63,3,5,1ah outputstr text2,58,4,5,1ah outputstr text3,41,5,5,1ah outputstr text4,43,6,5,1ah outputstr text5,28,7,5,1ah outputstr text6,23,9,25,1ah input:;消息接收循环 mov ah,0 int 16h cmp ah,01h jne continue1 call exit jmp input continue1: cmp ah,4bh jne continue2 call prsleft jmp input continue2: cmp ah,4dh jne continue3 call prsright jmp input continue3: cmp ah,50h jne continue4 call prsdown jmp input continue4: cmp ah,21h jne continue5 mov ah,02h int 16h and al,0fh cmp al,08h jne continue5 call FAlt jmp input continue5: cmp ah,12h jne continue6 mov ah,02h int 16h and al,0fh cmp al,08h jne continue6 call EAlt jmp input continue6: cmp ah,13h jne continue7 mov ah,02h int 16h and al,0fh cmp al,08h jne continue7 call RAlt jmp input continue7: cmp ah,20h jne continue8 mov ah,02h int 16h and al,0fh cmp al,08h jne continue8 call DAlt jmp input continue8: cmp ah,23h jne continue9 mov ah,02h int 16h and al,0fh cmp al,08h jne continue9 call HAlt jmp input continue9: cmp ah,48h jne continue10 call prsup jmp input continue10: cmp ah,1ch jne continue11 call prsenter jmp input continue11: jmp input ;----------------- prsenter proc near;按下 ENTER键 cmp subshow,0 jne enter1 call prsdown ret enter1: mov al,mainnum push ax mov cl,0ah mul cl sub ax,07h mov mainnum,al dec mainnum writescr mainnum,scrmm inc mainnum setpos 0,mainnum pop ax mov mainnum,al drawwindow 13h,22,4,22,50 cmp mainnum,1 jne prsenter1 cmp subnum,2 jne entersub12 outputstr sub11,11,22,5,13h entersub12: cmp subnum,3 jne entersub13 outputstr sub12,11,22,5,13h entersub13: cmp subnum,4 jne prsenter1 outputstr sub13,11,22,5,13h call exit prsenter1: cmp mainnum,2 jne prsenter2 cmp subnum,2 jne entersub22 outputstr sub21,10,22,5,13h entersub22: cmp subnum,3 jne entersub23 outputstr sub22,11,22,5,13h entersub23: cmp subnum,4 jne prsenter2 outputstr sub23,11,22,5,13h prsenter2: cmp mainnum,3 jne prsenter3 cmp subnum,2 jne entersub32 outputstr sub31,10,22,5,13h entersub32: cmp subnum,3 jne entersub33 outputstr sub32,12,22,5,13h entersub33: cmp subnum,4 jne prsenter3 outputstr sub33,11,22,5,13h prsenter3: cmp mainnum,4 jne prsenter4 cmp subnum,2 jne entersub42 outputstr sub41,11,22,5,13h entersub42: cmp subnum,3 jne entersub43 outputstr sub42,11,22,5,13h entersub43: cmp subnum,4 jne prsenter4 outputstr sub43,13,22,5,13h prsenter4: cmp mainnum,5 jne prsenter5 cmp subnum,2 jne entersub52 outputstr sub51,12,22,5,13h entersub52: cmp subnum,3 jne entersub53 outputstr sub52,10,22,5,13h entersub53: cmp subnum,4 jne prsenter5 outputstr sub53,10,22,5,13h prsenter5: mov subshow,0 ret prsenter endp ;---------------- halt proc near;H+Alt mov al,mainnum mov cl,0ah mul cl sub ax,07h mov mainnum,al cmp subshow,1 jne hshow dec mainnum writescr mainnum,scrmm inc mainnum hshow: readscr 42,scrmm submenu 42,submenu51,5,submenu52,3,submenu53,3,9 changemenu 0,mainnum,5,70h changemenu 0,mainnum,1,74h mov mainnum,05h changemenu 0,43,4,0fh changemenu 2,44,6,0fh mov subnum,2 mov subshow,1 setpos 0,43 ret halt endp ;---------------- dalt proc near;D+Alt mov al,mainnum mov cl,0ah mul cl sub ax,07h mov mainnum,al cmp subshow,1 jne dshow dec mainnum writescr mainnum,scrmm inc mainnum dshow: readscr 32,scrmm submenu 32,submenu41,4,submenu42,4,submenu43,6,9 changemenu 0,mainnum,5,70h changemenu 0,mainnum,1,74h mov mainnum,04h changemenu 0,33,5,0fh changemenu 2,34,6,0fh mov subnum,2 mov subshow,1 setpos 0,33 ret dalt endp ;---------------- ralt proc near;R+Alt mov al,mainnum mov cl,0ah mul cl sub ax,07h mov mainnum,al cmp subshow,1 jne rshow dec mainnum writescr mainnum,scrmm inc mainnum rshow: readscr 22,scrmm submenu 22,submenu31,3,submenu32,5,submenu33,4,9 changemenu 0,mainnum,5,70h changemenu 0,mainnum,1,74h mov mainnum,03h changemenu 0,23,3,0fh changemenu 2,24,6,0fh mov subnum,2 mov subshow,1 setpos 0,23 ret ralt endp ;---------------- ealt proc near;E+Alt mov al,mainnum mov cl,0ah mul cl sub ax,07h mov mainnum,al cmp subshow,1 jne eshow dec mainnum writescr mainnum,scrmm inc mainnum eshow: readscr 12,scrmm submenu 12,submenu21,3,submenu22,4,submenu23,4,9 changemenu 0,mainnum,5,70h changemenu 0,mainnum,1,74h mov mainnum,02h changemenu 0,13,4,0fh changemenu 2,14,6,0fh mov subnum,2 mov subshow,1 setpos 0,13 ret ealt endp ;---------------- falt proc near;F+Alt mov al,mainnum mov cl,0ah mul cl sub ax,07h mov mainnum,al cmp subshow,1 jne fshow dec mainnum writescr mainnum,scrmm inc mainnum fshow: readscr 2,scrmm submenu 2,submenu11,4,submenu12,4,submenu13,4,9 changemenu 0,mainnum,5,70h changemenu 0,mainnum,1,74h mov mainnum,01h changemenu 0,3,4,0fh changemenu 2,4,6,0fh mov subnum,2 mov subshow,1 setpos 0,3 ret falt endp ;---------------- prsup proc near; 按上箭头 cmp subshow,0 jne prsup2 ret prsup2: mov al,mainnum push ax mov cl,0ah mul cl sub ax,07h mov mainnum,al changemenu subnum,mainnum,8,70h inc mainnum changemenu subnum,mainnum,1,74h pop ax mov mainnum,al cmp subnum,02h jne prsuptop mov subnum,04h jmp prsup1 prsuptop: dec subnum prsup1: mov al,mainnum push ax mov cl,0ah mul cl sub ax,07h mov mainnum,al changemenu subnum,mainnum,8,0fh pop ax mov mainnum,al ret prsup endp ;---------------- prsdown proc near; 按下箭头 cmp subshow,0 jne prsdown2 cmp mainnum,1 jne prsdown3 call falt jmp prsdown7 prsdown3: cmp mainnum,2 jne prsdown4 call ealt jmp prsdown7 prsdown4: cmp mainnum,3 jne prsdown5 call ralt jmp prsdown7 prsdown5: cmp mainnum,4 jne prsdown6 call dalt jmp prsdown7 prsdown6: call halt prsdown7: ret prsdown2: mov al,mainnum push ax mov cl,0ah mul cl sub ax,07h mov mainnum,al changemenu subnum,mainnum,8,70h inc mainnum changemenu subnum,mainnum,1,74h pop ax mov mainnum,al cmp subnum,04h jne prsdownbot >mov subnum,02h jmp prsdown1 prsdownbot: inc subnum prsdown1: mov al,mainnum push ax mov cl,0ah mul cl sub ax,07h mov mainnum,al changemenu subnum,mainnum,8,0fh pop ax mov mainnum,al ret prsdown endp ;---------------- prsright proc near; 按右箭头 cmp subshow,0 je prsright1 call prsrgtsub ret prsright1: mov al,mainnum push ax mov cl,0ah mul cl sub ax,07h mov mainnum,al changemenu 0,mainnum,5,70h changemenu 0,mainnum,1,74h pop ax mov mainnum,al cmp mainnum,05h jne prsright2 mov mainnum,01h jmp prsright3 prsright2: inc mainnum prsright3: cmp mainnum,1 je prsright4 cmp mainnum,2 je prsright4 cmp mainnum,5 je prsright4 cmp mainnum,3 je prsright5 cmp mainnum,4 je prsright6 prsright4: mov mainindex,4 jmp prsright7 prsright5: mov mainindex,3 jmp prsright7 prsright6: mov mainindex,5 prsright7: mov al,mainnum push ax mov cl,0ah mul cl sub ax,07h mov mainnum,al changemenu 0,mainnum,mainindex,0fh pop ax mov mainnum,al ret prsright endp ;---------------- prsrgtsub proc near;当子菜单打开时按右箭头 cmp mainnum,1 jne prsrgt1 call ealt jmp prsrgt5 prsrgt1: cmp mainnum,2 jne prsrgt2 call ralt jmp prsrgt5 prsrgt2: cmp mainnum,3 jne prsrgt3 call dalt jmp prsrgt5 prsrgt3: cmp mainnum,4 jne prsrgt4 call halt jmp prsrgt5 prsrgt4: call falt prsrgt5: ret prsrgtsub endp ;---------------- prsleft proc near;按左箭头 cmp subshow,0 je prsleft1 call prslftsub ret prsleft1: mov al,mainnum push ax mov cl,0ah mul cl sub ax,07h mov mainnum,al changemenu 0,mainnum,5,70h changemenu 0,mainnum,1,74h pop ax mov mainnum,al cmp mainnum,01h jne prsleft2 mov mainnum,05h jmp prsleft3 prsleft2: dec mainnum prsleft3: cmp mainnum,1 je prsleft4 cmp mainnum,2 je prsleft4 cmp mainnum,5 je prsleft4 cmp mainnum,3 je prsleft5 cmp mainnum,4 je prsleft6 prsleft4: mov mainindex,4 jmp prsleft7 prsleft5: mov mainindex,3 jmp prsleft7 prsleft6: mov mainindex,5 prsleft7: mov al,mainnum push ax mov cl,0ah mul cl sub ax,07h mov mainnum,al changemenu 0,mainnum,mainindex,0fh pop ax mov mainnum,al ret prsleft endp ;---------------- prslftsub proc near;当子菜单打开时按左箭头 cmp mainnum,1 jne prslft1 call halt jmp prslft5 prslft1: cmp mainnum,2 jne prslft2 call falt jmp prslft5 prslft2: cmp mainnum,3 jne prslft3 call ealt jmp prslft5 prslft3: cmp mainnum,4 jne prslft4 call ralt jmp prslft5 prslft4: call dalt prslft5: ret prslftsub endp ;---------------- exit proc near;退出子过程 drawwindow 1eh,0,0,24,79 outputstr msgtitle,15,10,30,13h outputstr over,34,15,21,15h outputstr msg7,19,9,28,93h outputstr msg7,19,11,28,93h setpos 10,28 outputchar ' ',93h,1 setpos 10,46 outputchar ' ',93h,1 mov ah,07h int 21h mov ah,0 mov al,03h int 10h mov ah,4ch int 21h ret exit endp ;----------------- code ends ;----------------------- end start mnmacro.asm 功能调用宏文件 ;设置光标位置 setpos macro top,left mov ah,02h mov bx,0 mov dh,top mov dl,left int 10h endm ;修改菜单属性 changemenu macro top,left,width,attr local chg mov dl,left chg: setpos top,dl mov bh,0 mov ah,08h int 10h mov bl,attr mov cx,1 mov ah,09h int 10h inc dl mov al,left add al,width cmp dl,al jne chg setpos top,left endm ;绘制窗口 drawwindow macro attr,top,left,bottom ,right push ax push bx push cx push dx mov ah,06h mov al,0 mov bh,attr mov ch,top mov cl,left mov dh,bottom mov dl,right int 10h pop dx pop cx pop bx pop ax endm ;绘制窗口上下边框 windowtandb macro l,m,r,top,left,width,attr setpos top,left outputchar l,attr,1 setpos top,left+1 outputchar m,attr,width-2 setpos top,left+width-1 outputchar r,attr,1 endm ;绘制窗口左右边框 windowlandr macro char,top,left,width,attr setpos top,left outputchar char,attr,1 setpos top,left+width-1 outputchar char,attr,1 endm ;输出字符 outputchar macro char,attr,num push ax mov bh,0 mov ah,09h mov al,char mov bl,attr mov cx,num int 10h pop ax endm ;输出字符串 outputstr macro str,num,top,left,attr push ax push bx push bp push cx push dx mov ah,13h lea bp,str mov cx,num mov dh,top mov dl,left mov bh,0 mov al,1 mov bl,attr int 10h pop dx pop cx pop bp pop bx pop ax endm ;绘制子菜单 submenu macro left,menu1,num1,menu2,num2,menu3,num3,width local menu drawwindow 70h,1,left,5,left+width windowtandb 0dah,0c4h,0bfh,1,left,width+1,70h mov al,2 menu: windowlandr 0b3h,al,left,width+1,70h inc al cmp al,5 jne menu windowtandb 0c0h,0c4h,0d9h,5,left,width+1,70h outputstr menu1,num1,2,left+2,0fh changemenu 2,left+1,8,0fh outputstr menu2,num2,3,left+2,70h changemenu 3,left+2,1,74h outputstr menu3,num3,4,left+2,70h changemenu 4,left+2,1,74h setpos 2,left+2 endm ;读取屏幕内容 readscr macro left,memory local read sub ax,ax mov si,ax read: add ah,left inc al inc si mov ch,ah setpos al,ch mov ah,08h mov bh,0 int 10h mov memory[si],al mov memory[si+50],ah mov ax,si mov bl,10 div bl cmp si,50 jne read endm ;写入屏幕 writescr macro left,memory local read sub ax,ax mov si,ax read: add ah,left inc al inc si mov ch,ah setpos al,ch mov al,memory[si] mov ah,memory[si+50] mov dl,al mov dh,ah outputchar dl,dh,1 mov ax,si mov bl,10 div bl cmp si,50 jne read endm ;设置光标属性 showcur macro show push ax push cx mov ah,1 mov cl,0 mov ch,show int 10h pop cx pop ax endm 3获得操作系统版本的汇编源代码 dos下可以调用 DOS中断服务程序, WINDOWS下可以调用 API 函数 GetVersionEx() 这是我测试 PE 格式的 STUB 的源代码 , 可以在 DOS和WINDOWS下运行,其功能是报告当前 OS 信息. ; @@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@ ; FileName: os_type.asm ; function: Reports current operation system type ; Author : Purple Endurer ; Version : 0.1 ; ; OS Name Offset of INT 08h Offset of INT 43h ; ------------------------------------------------------- ; MS DOS 7.00 001Fh 5710h ; MS DOS 7.10 18DEh 6EE5h ; UCDOS 1AF3h ; UCDOS98 1AEBh 6E20h ; MSDOS mode 0000h ; PDOS95 0A50h 6E20h ; ; Date Summary ; ------------------------------------------------------- ; 2002.04.07 Created from software paper 95P125 ; 2002.06.11 Show version if os is MS-DOS ; 2002.08.07 Convert it to DOS EXE format to be stub ; program in PE format execute file ; 2004.02.09 Added the condition asm var 'UseStack' ; Question: ; Why can this program run normally with stack segment, ; though there is push and pop instruction in bin2dec proc? UseStack equ 0 data segment strMSDOS db "MS DOS " cMajorVer db ' ' db '.' cMinorVer db " $" strUCDOS db "UCDOS" cUCDOSVer db " 98特别版$" strPDOS95 db "Windows95中文 DOS方 式 PDOS95$" data ends if UseStack sseg segment stack db 10 dup(?) sseg ends endif code segment ;-------------------------------------- if UseStack assume cs: code, ds: data, ss: sseg else assume cs: code, ds: data endif main proc start: mov ax, data mov ds, ax if UseStack mov ax, sseg mov ss, ax endif mov ah, 30h ; Get Version int 21h add al, '0' mov cMajorVer, al mov bx, offset cMinorVer call bin2dec mov ax, 3508h int 21h mov dx, offset strMSDOS mov ah, 09h int 21h cmp bx, 1fh je @end ;Here is DOS 7.00 only cmp bx, 18deh je @End ;Here is DOS 7.10 only mov dx, offset strUCDOS cmp bx, 1aebh je @Report cmp bx, 1af3h jne @next2 mov cUCDOSVer, '$' jmp @report @next2: mov dx, offset strPDOS95 cmp bx, 0a50h jne @End @Report: ;mov ah, 09h int 21h @End: mov ax, 4c00h int 21h main endp ; ====================================== ================== ; Input : AH = the Binary will be translated) ; BX = First offset of memory us to store the result ; Output: BX = First offset of memory stored the result ; -------------------------------------------------------- bin2dec proc push dx mov dl, 10 @LoopDiv: mov al, ah xor ah, ah div dl ; (AL) <- (AX) / (DL) (AH) <- (AX) % (DL) add al, '0' mov [bx], al inc bx cmp ah, 10 jg @LoopDiv add ah, '0' mov [bx], ah pop dx ret bin2dec endp ;====================================== === code ends end main ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< <<<<<<<<<<<<<<<<<<<<<< ;FileName: StubDemo.asm ; Fuction: Demo how to use the custome stub of PE exe files. ; Author: Purple Endurer stub ;The command line refered cursom STUB program: ;\masm32\bin\link /stub: /subsystem:windows ;Example: ;D:\masm32v6\WORKS\m
/
本文档为【汇编语言例】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索