the first demo: HelloWorld compiled by masm5.0
2011-02-24 11:13
232 查看
编辑一个16位的 IBM-CP 汇编小程序的一般步骤如下:
1.编辑汇编源程序(edit the source file): 如 demo.asm
Code:
data segment
message db 'Hello World! welcome to assemble world',13, 10, '$'
data ends
stack segment
dw 100 dup(?)
tos equ this type word
stack ends
code segment
assume cs:code, ds:data, ss:stack
start:
mov ax, data
mov ds, ax
mov ax, stack
mov ss, ax
mov dx, offset message
mov ah, 09h
int 21h
mov ah, 4ch
int 21h
code ends
end start
2.用汇编程序masm5.0 对源程序进行编译:(complie the source file with assemble complier masm5.0)
首先 winkey +r 启动运行对话框,在“运行”输入“cmd” enter,启动命令行窗口,进入工作区:就是你存放汇编源程序的目录:若该目录为 d:/work 则执行如下操作:
Code:
Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.
C:/Documents and Settings/253642xvvn>d:
D:/>cd work
D:/work>dir
驱动器 D 中的卷没有标签。
卷的序列号是 0478-A8CB
D:/work 的目录
2011-02-24 09:31 <DIR> .
2011-02-24 09:31 <DIR> ..
2011-02-23 19:34 <DIR> bin
2011-02-24 09:12 389 demo.asm
2011-02-24 09:11 350 demo.asm~
2011-02-24 09:30 243 DEMO.CRF
2011-02-24 09:30 789 DEMO.EXE
2011-02-24 09:30 2,188 DEMO.LST
2011-02-24 09:30 271 DEMO.MAP
2011-02-24 09:30 180 DEMO.OBJ
2011-02-23 20:35 0 HelloWorld.asm
2011-02-23 20:37 405 hw.asm
2011-02-23 14:50 407 keydown.asm
2011-02-23 20:35 0 key_pressdown.asm
2011-02-23 20:35 0 lcate_cursor.asm
2011-02-23 19:45 626 movsb.asm
2011-02-23 20:08 2,073 vector.asm
2011-02-23 20:23 667 VECTOR.EXE
2011-02-23 19:12 404 World.asm
16 个文件 8,992 字节
3 个目录 28,501,487,616 可用字节
D:/work>
接着,需要设置编译器的路径:以下操作只是将汇编器masm5.0的所在的目录 d:/masm5.0 临时追加在环境变量path中;
此时,该追加的路径,只对当前命令行窗口以及其后继窗口(由start启动的)有效; 要想永久有效,可以设置系统环境变量
,设置方法: 右击我的电脑--》属性--》高级--》环境变量 找到path, 编辑;具体方式,百度吧,有图文并茂的,O(∩_∩)O~。
Code:
Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.
C:/Documents and Settings/253642xvvn>d:
D:/>cd work
D:/work>dir
驱动器 D 中的卷没有标签。
卷的序列号是 0478-A8CB
D:/work 的目录
2011-02-24 10:07 <DIR> .
2011-02-24 10:07 <DIR> ..
2011-02-23 19:34 <DIR> bin
2011-02-24 09:12 389 demo.asm
2011-02-24 09:11 350 demo.asm~
2011-02-24 09:55 243 DEMO.CRF
2011-02-24 09:55 789 DEMO.EXE
2011-02-24 09:55 2,188 DEMO.LST
2011-02-24 09:30 271 DEMO.MAP
2011-02-24 09:55 180 DEMO.OBJ
2011-02-24 10:07 0 dir
2011-02-23 20:35 0 HelloWorld.asm
2011-02-23 20:37 405 hw.asm
2011-02-23 14:50 407 keydown.asm
2011-02-23 20:35 0 key_pressdown.asm
2011-02-23 20:35 0 lcate_cursor.asm
2011-02-23 19:45 626 movsb.asm
2011-02-24 10:07 0 path
2011-02-23 20:08 2,073 vector.asm
2011-02-23 20:23 667 VECTOR.EXE
2011-02-23 19:12 404 World.asm
18 个文件 8,992 字节
3 个目录 28,501,487,616 可用字节
D:/work>dir d:/masm5.0
驱动器 D 中的卷没有标签。
卷的序列号是 0478-A8CB
d:/masm5.0 的目录
2011-02-23 18:57 <DIR> .
2011-02-23 18:57 <DIR> ..
1987-07-31 00:00 15,830 CREF.EXE
1987-07-31 00:00 9,499 ERROUT.EXE
1987-07-31 00:00 12,149 EXEMOD.EXE
1987-10-15 05:00 14,803 EXEPACK.EXE
1987-07-31 00:00 32,150 LIB.EXE
1987-07-31 00:00 39,100 LINK.EXE
1987-07-31 00:00 24,199 MAKE.EXE
2002-10-12 11:27 967 MAKE.PIF
1987-07-31 00:00 65,557 MASM.EXE
1987-07-31 00:00 10,601 SETENV.EXE
10 个文件 224,855 字节
2 个目录 28,501,487,616 可用字节
D:/work>path
PATH=e:/Xilinx/10.1/EDK/bin/nt;e:/Xilinx/10.1/EDK/lib/nt;e:/Xilinx/10.1/ISE/bin/
nt;e:/Xilinx/10.1/ISE/lib/nt;%LMC_HOME%/lib/pcnt.lib;D:/jdk1.6.0_21/bin;C:/WINDO
WS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;C:/Program Files/Intel/DMIX;C:/P
rogram Files/Common Files/Thunder Network/KanKan/Codecs;D:/jdk1.6.0_21/mingw/bin
;e:/Xilinx/10.1/ChipScope/bin/nt;c:/Program Files/Microsoft SQL Server/100/Tools
/Binn/;c:/Program Files/Microsoft SQL Server/100/DTS/Binn/;C:/Program Files/doxy
gen/bin;D:/jdk1.6.0_21/jre/bin;C:/Program Files/Common Files/TTKN/Bin;D:/Program
Files/Microsoft Visual Studio/Common/Tools/WinNT;D:/Program Files/Microsoft Vis
ual Studio/Common/MSDev98/Bin;D:/Program Files/Microsoft Visual Studio/Common/To
ols;D:/Program Files/Microsoft Visual Studio/VC98/bin;C:/Program Files/Nmap;C:/P
rogram Files/SSH Communications Security/SSH Secure Shell
D:/work>echo %path%
e:/Xilinx/10.1/EDK/bin/nt;e:/Xilinx/10.1/EDK/lib/nt;e:/Xilinx/10.1/ISE/bin/nt;e:
/Xilinx/10.1/ISE/lib/nt;%LMC_HOME%/lib/pcnt.lib;D:/jdk1.6.0_21/bin;C:/WINDOWS/sy
stem32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;C:/Program Files/Intel/DMIX;C:/Progra
m Files/Common Files/Thunder Network/KanKan/Codecs;D:/jdk1.6.0_21/mingw/bin;e:/X
ilinx/10.1/ChipScope/bin/nt;c:/Program Files/Microsoft SQL Server/100/Tools/Binn
/;c:/Program Files/Microsoft SQL Server/100/DTS/Binn/;C:/Program Files/doxygen/b
in;D:/jdk1.6.0_21/jre/bin;C:/Program Files/Common Files/TTKN/Bin;D:/Program File
s/Microsoft Visual Studio/Common/Tools/WinNT;D:/Program Files/Microsoft Visual S
tudio/Common/MSDev98/Bin;D:/Program Files/Microsoft Visual Studio/Common/Tools;D
:/Program Files/Microsoft Visual Studio/VC98/bin;C:/Program Files/Nmap;C:/Progra
m Files/SSH Communications Security/SSH Secure Shell
D:/work>set path=d:/masm5.0;%path%
D:/work>path
PATH=d:/masm5.0;e:/Xilinx/10.1/EDK/bin/nt;e:/Xilinx/10.1/EDK/lib/nt;e:/Xilinx/10
.1/ISE/bin/nt;e:/Xilinx/10.1/ISE/lib/nt;%LMC_HOME%/lib/pcnt.lib;D:/jdk1.6.0_21/b
in;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;C:/Program Files/Inte
l/DMIX;C:/Program Files/Common Files/Thunder Network/KanKan/Codecs;D:/jdk1.6.0_2
1/mingw/bin;e:/Xilinx/10.1/ChipScope/bin/nt;c:/Program Files/Microsoft SQL Serve
r/100/Tools/Binn/;c:/Program Files/Microsoft SQL Server/100/DTS/Binn/;C:/Program
Files/doxygen/bin;D:/jdk1.6.0_21/jre/bin;C:/Program Files/Common Files/TTKN/Bin
;D:/Program Files/Microsoft Visual Studio/Common/Tools/WinNT;D:/Program Files/Mi
crosoft Visual Studio/Common/MSDev98/Bin;D:/Program Files/Microsoft Visual Studi
o/Common/Tools;D:/Program Files/Microsoft Visual Studio/VC98/bin;C:/Program File
s/Nmap;C:/Program Files/SSH Communications Security/SSH Secure Shell
D:/work>echo %path%
d:/masm5.0;e:/Xilinx/10.1/EDK/bin/nt;e:/Xilinx/10.1/EDK/lib/nt;e:/Xilinx/10.1/IS
E/bin/nt;e:/Xilinx/10.1/ISE/lib/nt;%LMC_HOME%/lib/pcnt.lib;D:/jdk1.6.0_21/bin;C:
/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;C:/Program Files/Intel/DMI
X;C:/Program Files/Common Files/Thunder Network/KanKan/Codecs;D:/jdk1.6.0_21/min
gw/bin;e:/Xilinx/10.1/ChipScope/bin/nt;c:/Program Files/Microsoft SQL Server/100
/Tools/Binn/;c:/Program Files/Microsoft SQL Server/100/DTS/Binn/;C:/Program File
s/doxygen/bin;D:/jdk1.6.0_21/jre/bin;C:/Program Files/Common Files/TTKN/Bin;D:/P
rogram Files/Microsoft Visual Studio/Common/Tools/WinNT;D:/Program Files/Microso
ft Visual Studio/Common/MSDev98/Bin;D:/Program Files/Microsoft Visual Studio/Com
mon/Tools;D:/Program Files/Microsoft Visual Studio/VC98/bin;C:/Program Files/Nma
p;C:/Program Files/SSH Communications Security/SSH Secure Shell
D:/work>
用masm5.0 汇编器masm 和链接器link 分别对源文件,进行编译连接。
Code:
D:/work>masm demo.asm
Microsoft (R) Macro Assembler Version 5.00
Copyright (C) Microsoft Corp 1981-1985, 1987. All rights reserved.
Object filename [demo.OBJ]: demo
Source listing [NUL.LST]: demo
Cross-reference [NUL.CRF]: demo
49376 + 400128 Bytes symbol space free
0 Warning Errors
0 Severe Errors
D:/work>link demo
Microsoft (R) Overlay Linker Version 3.60
Copyright (C) Microsoft Corp 1983-1987. All rights reserved.
Run File [DEMO.EXE]: demo
List File [NUL.MAP]: demo
Libraries [.LIB]:
LINK : warning L4021: no stack segment
D:/work>demo
Hello World! welcome to assemble world
D:/work>link demo;
Microsoft (R) Overlay Linker Version 3.60
Copyright (C) Microsoft Corp 1983-1987. All rights reserved.
LINK : warning L4021: no stack segment
3.运行编译和链接后生成可执行程序: demo.exe
Code:
D:/work>demo
Hello World! welcome to assemble world
D:/work>demo.exe
Hello World! welcome to assemble world
D:/work>
总结:值得一提的是在编译的过程中生成的 *.lst, *.crf 和连接后生成的*.map 非常有用的。当编译出错时,可以同过*.list 文件进行查看错误的位置》 crf文件是一个十六进制的文件, map文件是object文件连接时重定位的依据,记录各个段的映射信息。
下面看一个出错的例子:
Code:
data segment
message db 'Hello World! welcome to assemble world',13, 10, '$'
data ends
stack segment
dw 100 dup(?)
tos equ this type word
stack ends
code segment
assume cs:code, ds:data, ss:stack
start:
mov ax, data
mov ds, ax
mov ax, stack
mov ss, ax
mov dx, offset massage
mov ah, 09h
int 21h
mov ah, 4ch
int 21h
code ends
end start
汇编时:
Code:
D:/work>masm demo.asm
Microsoft (R) Macro Assembler Version 5.00
Copyright (C) Microsoft Corp 1981-1985, 1987. All rights reserved.
Object filename [demo.OBJ]: demo
Source listing [NUL.LST]: demo
Cross-reference [NUL.CRF]: demo
demo.asm(18): error A2009: Symbol not defined: MASSAGE
48692 + 399436 Bytes symbol space free
0 Warning Errors
1 Severe Errors
D:/work>
1 severe Errors 说明出现了一个严重的错误,但错误在哪里呢? 这使,列表文件demo.lst文件就有用处了,看看的它的内容:
可以进入demo.lst所在的目录,用文本编辑器查看,也可以在命令行下用如下方式查看:
Code:
D:/work>type demo.lst | more
Microsoft (R) Macro Assembler Version 5.00 2/24/11 10:39:04
Page 1-1
1 0000 data segment
2 0000 48 65 6C 6C 6F 20 57 message db 'Hello World! welcom
e to assemble world',13, 10, '$'
3 6F 72 6C 64 21 20 77
4 65 6C 63 6F 6D 65 20
5 74 6F 20 61 73 73 65
6 6D 62 6C 65 20 77 6F
7 72 6C 64 0D 0A 24
8 0029 data ends
9
10 0000 stack segment
11 0000 0064[ dw 100 dup(?)
12 ????
13 ]
14
15 = tos equ this type word
16 00C8 stack ends
17
18 0000 code segment
19 assume cs:code, ds:data, ss:sta
ck
20 0000 start:
21 0000 B8 ---- R mov ax, data
22 0003 8E D8 mov ds, ax
23 0005 B8 ---- R mov ax, stack
24 0008 8E D0 mov ss, ax
25
26 000A BA 0000 U mov dx, offset massage
demo.asm(18): error A2009: Symbol not defined: MASSAGE
27 000D B4 09 mov ah, 09h
28 000F CD 21 int 21h
29
30 0011 B4 4C mov ah, 4ch
31 0013 CD 21 int 21h
32
33
34 0015 code ends
35 end start
Microsoft (R) Macro Assembler Version 5.00 2/24/11 10:39:04
Symbols-1
Segments and Groups:
N a m e Length Align Combine Class
CODE . . . . . . . . . . . . . . 0015 PARA NONE
DATA . . . . . . . . . . . . . . 0029 PARA NONE
STACK . . . . . . . . . . . . . 00C8 PARA NONE
Symbols:
N a m e Type Value Attr
MESSAGE . . . . . . . . . . . . L BYTE 0000 DATA
START . . . . . . . . . . . . . L NEAR 0000 CODE
TOS . . . . . . . . . . . . . . TEXT this type word
@FILENAME . . . . . . . . . . . TEXT demo
27 Source Lines
27 Total Lines
8 Symbols
48692 + 399436 Bytes symbol space free
0 Warning Errors
1 Severe Errors
发现该文件,是对汇编的一些详细信息,很容易就找到了发生错误的地方:
demo.asm(18): error A2009: Symbol not defined: MASSAGE
下面就修改一下,源文件demo.asm的18行:
Code:
data segment
message db 'Hello World! welcome to assemble world',13, 10, '$'
data ends
stack segment
dw 100 dup(?)
tos equ this type word
stack ends
code segment
assume cs:code, ds:data, ss:stack
start:
mov ax, data
mov ds, ax
mov ax, stack
mov ss, ax
mov dx, offset massage
mov ah, 09h
int 21h
mov ah, 4ch
int 21h
code ends
end start
原来,数据段定义的变量 message ,此处误写成了 massage,所以就有了变量符号massage无定义的错误。修改后,就能编译通过了:
Code:
D:/work>masm demo.asm
Microsoft (R) Macro Assembler Version 5.00
Copyright (C) Microsoft Corp 1981-1985, 1987. All rights reserved.
Object filename [demo.OBJ]: demo
Source listing [NUL.LST]: demo
Cross-reference [NUL.CRF]: demo
48692 + 399436 Bytes symbol space free
0 Warning Errors
0 Severe Errors
接着link, link 的一种快捷方式 link demo; 就不需要指派文件名了
Code:
D:/work>link demo ;
Microsoft (R) Overlay Linker Version 3.60
Copyright (C) Microsoft Corp 1983-1987. All rights reserved.
LINK : warning L4021: no stack segment
D:/work>link demo
Microsoft (R) Overlay Linker Version 3.60
Copyright (C) Microsoft Corp 1983-1987. All rights reserved.
Run File [DEMO.EXE]: demo
List File [NUL.MAP]: demo
Libraries [.LIB]:
LINK : warning L4021: no stack segment
D:/work>
下面看一看, demo.lst, demo.crf. demo.map文件的内容吧:
demo.lst文件的内容
Code:
Microsoft (R) Macro Assembler Version 5.00 2/24/11 10:57:05
Page 1-1
1 0000 data segment
2 0000 48 65 6C 6C 6F 20 57 message db 'Hello World! welcom
e to assemble world',13, 10, '$'
3 6F 72 6C 64 21 20 77
4 65 6C 63 6F 6D 65 20
5 74 6F 20 61 73 73 65
6 6D 62 6C 65 20 77 6F
7 72 6C 64 0D 0A 24
8 0029 data ends
9
10 0000 stack segment
11 0000 0064[ dw 100 dup(?)
12 ????
13 ]
14
15 = tos equ this type word
16 00C8 stack ends
17
18 0000 code segment
19 assume cs:code, ds:data, ss:sta
ck
20 0000 start:
21 0000 B8 ---- R mov ax, data
22 0003 8E D8 mov ds, ax
23 0005 B8 ---- R mov ax, stack
24 0008 8E D0 mov ss, ax
25
26 000A BA 0000 R mov dx, offset message
27 000D B4 09 mov ah, 09h
28 000F CD 21 int 21h
29
30 0011 B4 4C mov ah, 4ch
31 0013 CD 21 int 21h
32
33
34 0015 code ends
35 end start
Microsoft (R) Macro Assembler Version 5.00 2/24/11 10:57:05
Symbols-1
Segments and Groups:
N a m e Length Align Combine Class
CODE . . . . . . . . . . . . . . 0015 PARA NONE
DATA . . . . . . . . . . . . . . 0029 PARA NONE
STACK . . . . . . . . . . . . . 00C8 PARA NONE
Symbols:
N a m e Type Value Attr
MESSAGE . . . . . . . . . . . . L BYTE 0000 DATA
START . . . . . . . . . . . . . L NEAR 0000 CODE
TOS . . . . . . . . . . . . . . TEXT this type word
@FILENAME . . . . . . . . . . . TEXT demo
27 Source Lines
27 Total Lines
8 Symbols
48692 + 399436 Bytes symbol space free
0 Warning Errors
0 Severe Errors
demo.crf文件的内容:(用十六进制显示)
Code:
0000000: 073a 4f08 6465 6d6f 2e61 736d 0200 0005 .:O.demo.asm....
0000010: 0044 4154 4104 0100 0202 0025 024d 4553 .DATA......%.MES
0000020: 5341 4745 0402 0004 0300 0404 0004 0500 SAGE............
0000030: 0406 0004 0700 0104 4441 5441 0408 0004 ........DATA....
0000040: 0900 0200 0005 0053 5441 434b 040a 0004 .......STACK....
0000050: 0b00 040c 0004 0d00 040e 0002 0000 2506 ..............%.
0000060: 544f 5304 0f00 0104 5354 4143 4b04 1000 TOS.....STACK...
0000070: 0411 0002 0000 0500 434f 4445 0412 0001 ........CODE....
0000080: 0443 4f44 4501 0444 4154 4101 0453 5441 .CODE..DATA..STA
0000090: 434b 0413 0002 ffff 2502 5354 4152 5404 CK......%.START.
00000a0: 1400 0101 4441 5441 0415 0004 1600 0101 ....DATA........
00000b0: 5354 4143 4b04 1700 0418 0004 1900 0101 STACK...........
00000c0: 4d45 5353 4147 4504 1a00 041b 0004 1c00 MESSAGE.........
00000d0: 041d 0004 1e00 041f 0004 2000 0421 0001 .......... ..!..
00000e0: 0443 4f44 4504 2200 0104 5354 4152 5404 .CODE."...START.
00000f0: 2300 050a #...
demo.map文件的内容如下:
Code:
LINK : warning L4021: no stack segment
Start Stop Length Name Class
00000H 00028H 00029H DATA
00030H 000F7H 000C8H STACK
00100H 00114H 00015H CODE
Program entry point at 0010:0000
呵呵,这几个文件时不不是很有用呀。
编译成功了,link也成功了,但是运行不是我们想要的结果,该怎么办呢? 用调试命令debug;
Code:
D:/work>debug demo
File not found
-u
13F4:0100 21E8 AND AX,BP
13F4:0102 4C DEC SP
13F4:0103 1483 ADC AL,83
13F4:0105 C4068946 LES AX,[4689]
13F4:0109 F8 CLC
13F4:010A 8956FA MOV [BP-06],DX
13F4:010D A1B817 MOV AX,[17B8]
13F4:0110 0B06BA17 OR AX,[17BA]
13F4:0114 751C JNZ 0132
13F4:0116 837E0AFF CMP WORD PTR [BP+0A],-01
13F4:011A 7408 JZ 0124
13F4:011C 3400 XOR AL,00
13F4:011E E313 JCXZ 0133
-t
AX=0000 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=13F4 ES=13F4 SS=13F4 CS=13F4 IP=0102 NV UP EI PL ZR NA PE NC
13F4:0102 4C DEC SP
-?
assemble A [address]
compare C range address
dump D [range]
enter E address [list]
fill F range list
go G [=address] [addresses]
hex H value1 value2
input I port
load L [address] [drive] [firstsector] [number]
move M range address
name N [pathname] [arglist]
output O port byte
proceed P [=address] [number]
quit Q
register R [register]
search S range list
trace T [=address] [value]
unassemble U [range]
write W [address] [drive] [firstsector] [number]
allocate expanded memory XA [#pages]
deallocate expanded memory XD [handle]
map expanded memory pages XM [Lpage] [Ppage] [handle]
display expanded memory status XS
-q
debug 几个有用的命令 :
u :反汇编
t:单步执行
q:退出debug:
具体参数的用法可在debug 下用? 查看。
Code:
D:/work>debug
-?
assemble A [address]
compare C range address
dump D [range]
enter E address [list]
fill F range list
go G [=address] [addresses]
hex H value1 value2
input I port
load L [address] [drive] [firstsector] [number]
move M range address
name N [pathname] [arglist]
output O port byte
proceed P [=address] [number]
quit Q
register R [register]
search S range list
trace T [=address] [value]
unassemble U [range]
write W [address] [drive] [firstsector] [number]
allocate expanded memory XA [#pages]
deallocate expanded memory XD [handle]
map expanded memory pages XM [Lpage] [Ppage] [handle]
display expanded memory status XS
-q
D:/work>
以上就是一个程序的开发流程。其实,和其他语言的大致一样,基本上都是这个流程。这就是程序设计语言的相似性。
1.编辑汇编源程序(edit the source file): 如 demo.asm
Code:
data segment
message db 'Hello World! welcome to assemble world',13, 10, '$'
data ends
stack segment
dw 100 dup(?)
tos equ this type word
stack ends
code segment
assume cs:code, ds:data, ss:stack
start:
mov ax, data
mov ds, ax
mov ax, stack
mov ss, ax
mov dx, offset message
mov ah, 09h
int 21h
mov ah, 4ch
int 21h
code ends
end start
2.用汇编程序masm5.0 对源程序进行编译:(complie the source file with assemble complier masm5.0)
首先 winkey +r 启动运行对话框,在“运行”输入“cmd” enter,启动命令行窗口,进入工作区:就是你存放汇编源程序的目录:若该目录为 d:/work 则执行如下操作:
Code:
Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.
C:/Documents and Settings/253642xvvn>d:
D:/>cd work
D:/work>dir
驱动器 D 中的卷没有标签。
卷的序列号是 0478-A8CB
D:/work 的目录
2011-02-24 09:31 <DIR> .
2011-02-24 09:31 <DIR> ..
2011-02-23 19:34 <DIR> bin
2011-02-24 09:12 389 demo.asm
2011-02-24 09:11 350 demo.asm~
2011-02-24 09:30 243 DEMO.CRF
2011-02-24 09:30 789 DEMO.EXE
2011-02-24 09:30 2,188 DEMO.LST
2011-02-24 09:30 271 DEMO.MAP
2011-02-24 09:30 180 DEMO.OBJ
2011-02-23 20:35 0 HelloWorld.asm
2011-02-23 20:37 405 hw.asm
2011-02-23 14:50 407 keydown.asm
2011-02-23 20:35 0 key_pressdown.asm
2011-02-23 20:35 0 lcate_cursor.asm
2011-02-23 19:45 626 movsb.asm
2011-02-23 20:08 2,073 vector.asm
2011-02-23 20:23 667 VECTOR.EXE
2011-02-23 19:12 404 World.asm
16 个文件 8,992 字节
3 个目录 28,501,487,616 可用字节
D:/work>
接着,需要设置编译器的路径:以下操作只是将汇编器masm5.0的所在的目录 d:/masm5.0 临时追加在环境变量path中;
此时,该追加的路径,只对当前命令行窗口以及其后继窗口(由start启动的)有效; 要想永久有效,可以设置系统环境变量
,设置方法: 右击我的电脑--》属性--》高级--》环境变量 找到path, 编辑;具体方式,百度吧,有图文并茂的,O(∩_∩)O~。
Code:
Microsoft Windows XP [版本 5.1.2600]
(C) 版权所有 1985-2001 Microsoft Corp.
C:/Documents and Settings/253642xvvn>d:
D:/>cd work
D:/work>dir
驱动器 D 中的卷没有标签。
卷的序列号是 0478-A8CB
D:/work 的目录
2011-02-24 10:07 <DIR> .
2011-02-24 10:07 <DIR> ..
2011-02-23 19:34 <DIR> bin
2011-02-24 09:12 389 demo.asm
2011-02-24 09:11 350 demo.asm~
2011-02-24 09:55 243 DEMO.CRF
2011-02-24 09:55 789 DEMO.EXE
2011-02-24 09:55 2,188 DEMO.LST
2011-02-24 09:30 271 DEMO.MAP
2011-02-24 09:55 180 DEMO.OBJ
2011-02-24 10:07 0 dir
2011-02-23 20:35 0 HelloWorld.asm
2011-02-23 20:37 405 hw.asm
2011-02-23 14:50 407 keydown.asm
2011-02-23 20:35 0 key_pressdown.asm
2011-02-23 20:35 0 lcate_cursor.asm
2011-02-23 19:45 626 movsb.asm
2011-02-24 10:07 0 path
2011-02-23 20:08 2,073 vector.asm
2011-02-23 20:23 667 VECTOR.EXE
2011-02-23 19:12 404 World.asm
18 个文件 8,992 字节
3 个目录 28,501,487,616 可用字节
D:/work>dir d:/masm5.0
驱动器 D 中的卷没有标签。
卷的序列号是 0478-A8CB
d:/masm5.0 的目录
2011-02-23 18:57 <DIR> .
2011-02-23 18:57 <DIR> ..
1987-07-31 00:00 15,830 CREF.EXE
1987-07-31 00:00 9,499 ERROUT.EXE
1987-07-31 00:00 12,149 EXEMOD.EXE
1987-10-15 05:00 14,803 EXEPACK.EXE
1987-07-31 00:00 32,150 LIB.EXE
1987-07-31 00:00 39,100 LINK.EXE
1987-07-31 00:00 24,199 MAKE.EXE
2002-10-12 11:27 967 MAKE.PIF
1987-07-31 00:00 65,557 MASM.EXE
1987-07-31 00:00 10,601 SETENV.EXE
10 个文件 224,855 字节
2 个目录 28,501,487,616 可用字节
D:/work>path
PATH=e:/Xilinx/10.1/EDK/bin/nt;e:/Xilinx/10.1/EDK/lib/nt;e:/Xilinx/10.1/ISE/bin/
nt;e:/Xilinx/10.1/ISE/lib/nt;%LMC_HOME%/lib/pcnt.lib;D:/jdk1.6.0_21/bin;C:/WINDO
WS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;C:/Program Files/Intel/DMIX;C:/P
rogram Files/Common Files/Thunder Network/KanKan/Codecs;D:/jdk1.6.0_21/mingw/bin
;e:/Xilinx/10.1/ChipScope/bin/nt;c:/Program Files/Microsoft SQL Server/100/Tools
/Binn/;c:/Program Files/Microsoft SQL Server/100/DTS/Binn/;C:/Program Files/doxy
gen/bin;D:/jdk1.6.0_21/jre/bin;C:/Program Files/Common Files/TTKN/Bin;D:/Program
Files/Microsoft Visual Studio/Common/Tools/WinNT;D:/Program Files/Microsoft Vis
ual Studio/Common/MSDev98/Bin;D:/Program Files/Microsoft Visual Studio/Common/To
ols;D:/Program Files/Microsoft Visual Studio/VC98/bin;C:/Program Files/Nmap;C:/P
rogram Files/SSH Communications Security/SSH Secure Shell
D:/work>echo %path%
e:/Xilinx/10.1/EDK/bin/nt;e:/Xilinx/10.1/EDK/lib/nt;e:/Xilinx/10.1/ISE/bin/nt;e:
/Xilinx/10.1/ISE/lib/nt;%LMC_HOME%/lib/pcnt.lib;D:/jdk1.6.0_21/bin;C:/WINDOWS/sy
stem32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;C:/Program Files/Intel/DMIX;C:/Progra
m Files/Common Files/Thunder Network/KanKan/Codecs;D:/jdk1.6.0_21/mingw/bin;e:/X
ilinx/10.1/ChipScope/bin/nt;c:/Program Files/Microsoft SQL Server/100/Tools/Binn
/;c:/Program Files/Microsoft SQL Server/100/DTS/Binn/;C:/Program Files/doxygen/b
in;D:/jdk1.6.0_21/jre/bin;C:/Program Files/Common Files/TTKN/Bin;D:/Program File
s/Microsoft Visual Studio/Common/Tools/WinNT;D:/Program Files/Microsoft Visual S
tudio/Common/MSDev98/Bin;D:/Program Files/Microsoft Visual Studio/Common/Tools;D
:/Program Files/Microsoft Visual Studio/VC98/bin;C:/Program Files/Nmap;C:/Progra
m Files/SSH Communications Security/SSH Secure Shell
D:/work>set path=d:/masm5.0;%path%
D:/work>path
PATH=d:/masm5.0;e:/Xilinx/10.1/EDK/bin/nt;e:/Xilinx/10.1/EDK/lib/nt;e:/Xilinx/10
.1/ISE/bin/nt;e:/Xilinx/10.1/ISE/lib/nt;%LMC_HOME%/lib/pcnt.lib;D:/jdk1.6.0_21/b
in;C:/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;C:/Program Files/Inte
l/DMIX;C:/Program Files/Common Files/Thunder Network/KanKan/Codecs;D:/jdk1.6.0_2
1/mingw/bin;e:/Xilinx/10.1/ChipScope/bin/nt;c:/Program Files/Microsoft SQL Serve
r/100/Tools/Binn/;c:/Program Files/Microsoft SQL Server/100/DTS/Binn/;C:/Program
Files/doxygen/bin;D:/jdk1.6.0_21/jre/bin;C:/Program Files/Common Files/TTKN/Bin
;D:/Program Files/Microsoft Visual Studio/Common/Tools/WinNT;D:/Program Files/Mi
crosoft Visual Studio/Common/MSDev98/Bin;D:/Program Files/Microsoft Visual Studi
o/Common/Tools;D:/Program Files/Microsoft Visual Studio/VC98/bin;C:/Program File
s/Nmap;C:/Program Files/SSH Communications Security/SSH Secure Shell
D:/work>echo %path%
d:/masm5.0;e:/Xilinx/10.1/EDK/bin/nt;e:/Xilinx/10.1/EDK/lib/nt;e:/Xilinx/10.1/IS
E/bin/nt;e:/Xilinx/10.1/ISE/lib/nt;%LMC_HOME%/lib/pcnt.lib;D:/jdk1.6.0_21/bin;C:
/WINDOWS/system32;C:/WINDOWS;C:/WINDOWS/System32/Wbem;C:/Program Files/Intel/DMI
X;C:/Program Files/Common Files/Thunder Network/KanKan/Codecs;D:/jdk1.6.0_21/min
gw/bin;e:/Xilinx/10.1/ChipScope/bin/nt;c:/Program Files/Microsoft SQL Server/100
/Tools/Binn/;c:/Program Files/Microsoft SQL Server/100/DTS/Binn/;C:/Program File
s/doxygen/bin;D:/jdk1.6.0_21/jre/bin;C:/Program Files/Common Files/TTKN/Bin;D:/P
rogram Files/Microsoft Visual Studio/Common/Tools/WinNT;D:/Program Files/Microso
ft Visual Studio/Common/MSDev98/Bin;D:/Program Files/Microsoft Visual Studio/Com
mon/Tools;D:/Program Files/Microsoft Visual Studio/VC98/bin;C:/Program Files/Nma
p;C:/Program Files/SSH Communications Security/SSH Secure Shell
D:/work>
用masm5.0 汇编器masm 和链接器link 分别对源文件,进行编译连接。
Code:
D:/work>masm demo.asm
Microsoft (R) Macro Assembler Version 5.00
Copyright (C) Microsoft Corp 1981-1985, 1987. All rights reserved.
Object filename [demo.OBJ]: demo
Source listing [NUL.LST]: demo
Cross-reference [NUL.CRF]: demo
49376 + 400128 Bytes symbol space free
0 Warning Errors
0 Severe Errors
D:/work>link demo
Microsoft (R) Overlay Linker Version 3.60
Copyright (C) Microsoft Corp 1983-1987. All rights reserved.
Run File [DEMO.EXE]: demo
List File [NUL.MAP]: demo
Libraries [.LIB]:
LINK : warning L4021: no stack segment
D:/work>demo
Hello World! welcome to assemble world
D:/work>link demo;
Microsoft (R) Overlay Linker Version 3.60
Copyright (C) Microsoft Corp 1983-1987. All rights reserved.
LINK : warning L4021: no stack segment
3.运行编译和链接后生成可执行程序: demo.exe
Code:
D:/work>demo
Hello World! welcome to assemble world
D:/work>demo.exe
Hello World! welcome to assemble world
D:/work>
总结:值得一提的是在编译的过程中生成的 *.lst, *.crf 和连接后生成的*.map 非常有用的。当编译出错时,可以同过*.list 文件进行查看错误的位置》 crf文件是一个十六进制的文件, map文件是object文件连接时重定位的依据,记录各个段的映射信息。
下面看一个出错的例子:
Code:
data segment
message db 'Hello World! welcome to assemble world',13, 10, '$'
data ends
stack segment
dw 100 dup(?)
tos equ this type word
stack ends
code segment
assume cs:code, ds:data, ss:stack
start:
mov ax, data
mov ds, ax
mov ax, stack
mov ss, ax
mov dx, offset massage
mov ah, 09h
int 21h
mov ah, 4ch
int 21h
code ends
end start
汇编时:
Code:
D:/work>masm demo.asm
Microsoft (R) Macro Assembler Version 5.00
Copyright (C) Microsoft Corp 1981-1985, 1987. All rights reserved.
Object filename [demo.OBJ]: demo
Source listing [NUL.LST]: demo
Cross-reference [NUL.CRF]: demo
demo.asm(18): error A2009: Symbol not defined: MASSAGE
48692 + 399436 Bytes symbol space free
0 Warning Errors
1 Severe Errors
D:/work>
1 severe Errors 说明出现了一个严重的错误,但错误在哪里呢? 这使,列表文件demo.lst文件就有用处了,看看的它的内容:
可以进入demo.lst所在的目录,用文本编辑器查看,也可以在命令行下用如下方式查看:
Code:
D:/work>type demo.lst | more
Microsoft (R) Macro Assembler Version 5.00 2/24/11 10:39:04
Page 1-1
1 0000 data segment
2 0000 48 65 6C 6C 6F 20 57 message db 'Hello World! welcom
e to assemble world',13, 10, '$'
3 6F 72 6C 64 21 20 77
4 65 6C 63 6F 6D 65 20
5 74 6F 20 61 73 73 65
6 6D 62 6C 65 20 77 6F
7 72 6C 64 0D 0A 24
8 0029 data ends
9
10 0000 stack segment
11 0000 0064[ dw 100 dup(?)
12 ????
13 ]
14
15 = tos equ this type word
16 00C8 stack ends
17
18 0000 code segment
19 assume cs:code, ds:data, ss:sta
ck
20 0000 start:
21 0000 B8 ---- R mov ax, data
22 0003 8E D8 mov ds, ax
23 0005 B8 ---- R mov ax, stack
24 0008 8E D0 mov ss, ax
25
26 000A BA 0000 U mov dx, offset massage
demo.asm(18): error A2009: Symbol not defined: MASSAGE
27 000D B4 09 mov ah, 09h
28 000F CD 21 int 21h
29
30 0011 B4 4C mov ah, 4ch
31 0013 CD 21 int 21h
32
33
34 0015 code ends
35 end start
Microsoft (R) Macro Assembler Version 5.00 2/24/11 10:39:04
Symbols-1
Segments and Groups:
N a m e Length Align Combine Class
CODE . . . . . . . . . . . . . . 0015 PARA NONE
DATA . . . . . . . . . . . . . . 0029 PARA NONE
STACK . . . . . . . . . . . . . 00C8 PARA NONE
Symbols:
N a m e Type Value Attr
MESSAGE . . . . . . . . . . . . L BYTE 0000 DATA
START . . . . . . . . . . . . . L NEAR 0000 CODE
TOS . . . . . . . . . . . . . . TEXT this type word
@FILENAME . . . . . . . . . . . TEXT demo
27 Source Lines
27 Total Lines
8 Symbols
48692 + 399436 Bytes symbol space free
0 Warning Errors
1 Severe Errors
发现该文件,是对汇编的一些详细信息,很容易就找到了发生错误的地方:
demo.asm(18): error A2009: Symbol not defined: MASSAGE
下面就修改一下,源文件demo.asm的18行:
Code:
data segment
message db 'Hello World! welcome to assemble world',13, 10, '$'
data ends
stack segment
dw 100 dup(?)
tos equ this type word
stack ends
code segment
assume cs:code, ds:data, ss:stack
start:
mov ax, data
mov ds, ax
mov ax, stack
mov ss, ax
mov dx, offset massage
mov ah, 09h
int 21h
mov ah, 4ch
int 21h
code ends
end start
原来,数据段定义的变量 message ,此处误写成了 massage,所以就有了变量符号massage无定义的错误。修改后,就能编译通过了:
Code:
D:/work>masm demo.asm
Microsoft (R) Macro Assembler Version 5.00
Copyright (C) Microsoft Corp 1981-1985, 1987. All rights reserved.
Object filename [demo.OBJ]: demo
Source listing [NUL.LST]: demo
Cross-reference [NUL.CRF]: demo
48692 + 399436 Bytes symbol space free
0 Warning Errors
0 Severe Errors
接着link, link 的一种快捷方式 link demo; 就不需要指派文件名了
Code:
D:/work>link demo ;
Microsoft (R) Overlay Linker Version 3.60
Copyright (C) Microsoft Corp 1983-1987. All rights reserved.
LINK : warning L4021: no stack segment
D:/work>link demo
Microsoft (R) Overlay Linker Version 3.60
Copyright (C) Microsoft Corp 1983-1987. All rights reserved.
Run File [DEMO.EXE]: demo
List File [NUL.MAP]: demo
Libraries [.LIB]:
LINK : warning L4021: no stack segment
D:/work>
下面看一看, demo.lst, demo.crf. demo.map文件的内容吧:
demo.lst文件的内容
Code:
Microsoft (R) Macro Assembler Version 5.00 2/24/11 10:57:05
Page 1-1
1 0000 data segment
2 0000 48 65 6C 6C 6F 20 57 message db 'Hello World! welcom
e to assemble world',13, 10, '$'
3 6F 72 6C 64 21 20 77
4 65 6C 63 6F 6D 65 20
5 74 6F 20 61 73 73 65
6 6D 62 6C 65 20 77 6F
7 72 6C 64 0D 0A 24
8 0029 data ends
9
10 0000 stack segment
11 0000 0064[ dw 100 dup(?)
12 ????
13 ]
14
15 = tos equ this type word
16 00C8 stack ends
17
18 0000 code segment
19 assume cs:code, ds:data, ss:sta
ck
20 0000 start:
21 0000 B8 ---- R mov ax, data
22 0003 8E D8 mov ds, ax
23 0005 B8 ---- R mov ax, stack
24 0008 8E D0 mov ss, ax
25
26 000A BA 0000 R mov dx, offset message
27 000D B4 09 mov ah, 09h
28 000F CD 21 int 21h
29
30 0011 B4 4C mov ah, 4ch
31 0013 CD 21 int 21h
32
33
34 0015 code ends
35 end start
Microsoft (R) Macro Assembler Version 5.00 2/24/11 10:57:05
Symbols-1
Segments and Groups:
N a m e Length Align Combine Class
CODE . . . . . . . . . . . . . . 0015 PARA NONE
DATA . . . . . . . . . . . . . . 0029 PARA NONE
STACK . . . . . . . . . . . . . 00C8 PARA NONE
Symbols:
N a m e Type Value Attr
MESSAGE . . . . . . . . . . . . L BYTE 0000 DATA
START . . . . . . . . . . . . . L NEAR 0000 CODE
TOS . . . . . . . . . . . . . . TEXT this type word
@FILENAME . . . . . . . . . . . TEXT demo
27 Source Lines
27 Total Lines
8 Symbols
48692 + 399436 Bytes symbol space free
0 Warning Errors
0 Severe Errors
demo.crf文件的内容:(用十六进制显示)
Code:
0000000: 073a 4f08 6465 6d6f 2e61 736d 0200 0005 .:O.demo.asm....
0000010: 0044 4154 4104 0100 0202 0025 024d 4553 .DATA......%.MES
0000020: 5341 4745 0402 0004 0300 0404 0004 0500 SAGE............
0000030: 0406 0004 0700 0104 4441 5441 0408 0004 ........DATA....
0000040: 0900 0200 0005 0053 5441 434b 040a 0004 .......STACK....
0000050: 0b00 040c 0004 0d00 040e 0002 0000 2506 ..............%.
0000060: 544f 5304 0f00 0104 5354 4143 4b04 1000 TOS.....STACK...
0000070: 0411 0002 0000 0500 434f 4445 0412 0001 ........CODE....
0000080: 0443 4f44 4501 0444 4154 4101 0453 5441 .CODE..DATA..STA
0000090: 434b 0413 0002 ffff 2502 5354 4152 5404 CK......%.START.
00000a0: 1400 0101 4441 5441 0415 0004 1600 0101 ....DATA........
00000b0: 5354 4143 4b04 1700 0418 0004 1900 0101 STACK...........
00000c0: 4d45 5353 4147 4504 1a00 041b 0004 1c00 MESSAGE.........
00000d0: 041d 0004 1e00 041f 0004 2000 0421 0001 .......... ..!..
00000e0: 0443 4f44 4504 2200 0104 5354 4152 5404 .CODE."...START.
00000f0: 2300 050a #...
demo.map文件的内容如下:
Code:
LINK : warning L4021: no stack segment
Start Stop Length Name Class
00000H 00028H 00029H DATA
00030H 000F7H 000C8H STACK
00100H 00114H 00015H CODE
Program entry point at 0010:0000
呵呵,这几个文件时不不是很有用呀。
编译成功了,link也成功了,但是运行不是我们想要的结果,该怎么办呢? 用调试命令debug;
Code:
D:/work>debug demo
File not found
-u
13F4:0100 21E8 AND AX,BP
13F4:0102 4C DEC SP
13F4:0103 1483 ADC AL,83
13F4:0105 C4068946 LES AX,[4689]
13F4:0109 F8 CLC
13F4:010A 8956FA MOV [BP-06],DX
13F4:010D A1B817 MOV AX,[17B8]
13F4:0110 0B06BA17 OR AX,[17BA]
13F4:0114 751C JNZ 0132
13F4:0116 837E0AFF CMP WORD PTR [BP+0A],-01
13F4:011A 7408 JZ 0124
13F4:011C 3400 XOR AL,00
13F4:011E E313 JCXZ 0133
-t
AX=0000 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=13F4 ES=13F4 SS=13F4 CS=13F4 IP=0102 NV UP EI PL ZR NA PE NC
13F4:0102 4C DEC SP
-?
assemble A [address]
compare C range address
dump D [range]
enter E address [list]
fill F range list
go G [=address] [addresses]
hex H value1 value2
input I port
load L [address] [drive] [firstsector] [number]
move M range address
name N [pathname] [arglist]
output O port byte
proceed P [=address] [number]
quit Q
register R [register]
search S range list
trace T [=address] [value]
unassemble U [range]
write W [address] [drive] [firstsector] [number]
allocate expanded memory XA [#pages]
deallocate expanded memory XD [handle]
map expanded memory pages XM [Lpage] [Ppage] [handle]
display expanded memory status XS
-q
debug 几个有用的命令 :
u :反汇编
t:单步执行
q:退出debug:
具体参数的用法可在debug 下用? 查看。
Code:
D:/work>debug
-?
assemble A [address]
compare C range address
dump D [range]
enter E address [list]
fill F range list
go G [=address] [addresses]
hex H value1 value2
input I port
load L [address] [drive] [firstsector] [number]
move M range address
name N [pathname] [arglist]
output O port byte
proceed P [=address] [number]
quit Q
register R [register]
search S range list
trace T [=address] [value]
unassemble U [range]
write W [address] [drive] [firstsector] [number]
allocate expanded memory XA [#pages]
deallocate expanded memory XD [handle]
map expanded memory pages XM [Lpage] [Ppage] [handle]
display expanded memory status XS
-q
D:/work>
以上就是一个程序的开发流程。其实,和其他语言的大致一样,基本上都是这个流程。这就是程序设计语言的相似性。
相关文章推荐
- 在android真机上运行cocos2d-html5-2.2自带的HelloHTML5World和其它demo
- Drools入门-----------环境搭建,分析Helloworld Drools5.0的xls文件转drl文件提升解析效率 使用BRMS的Tomcat6.0配置
- React(antd和react-bootstrap)的HelloWorld Demo
- JFinal First Demo "Hello World"
- Spring3 mvc hello world demo
- (1)轻松构建DuiLib HelloWorld By DuiCreator(上)
- Python 2.7.9 Demo - 001.print_hello_world - 002.print_chinese
- mina推送场景小hello world demo
- Neo4j Hello World demo
- (2)轻松构建DuiLib HelloWorld By DuiCreator(下)
- Flex HelloWorld Demo
- grpc java helloworld 简单demo实现
- Hello World by Microsoft Speech SDK 5.1
- win32 asm Hello World Demo
- BUG Lcom/demo/helloworld/widget/viewpagerindicator/simple/BaseSampleActivity; (107)错误
- HelloWorld by Thrift
- minigui demo helloworld在arm目标板子上的运行
- Hello World by Microsoft Speech SDK 5.1
- win32 asm Hello World Demo
- php的扩展和嵌入--c扩展开发demo! print "helloworld"