资源描述
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
POP AX
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 .'
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
cal
展开阅读全文