汇编问题

zhouxi 2004-04-10 06:10:55
;Display string (09H)
CODE SEGMENT PUBLIC
ASSUME CS:CODE,DS:CODE
ORG 100H
START: JMP BEGIN
MSG DB 'Hi! This is a dollar sign terminated string.','$'
BEGIN: MOV AX,CS
MOV DS,AX
MOV DX,OFFSET,SG ;(9)
MOV AH,09H
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
END START ;(15)

这是照抄书上的,我用Visual Studio.NET 2003里自代的MASM版本信息如下:

Microsoft (R) Macro Assembler Version 7.10.3077
Copyright (C) Microsoft Corporation. All rights reserved.

usage: ML [ options ] filelist [ /link linkoptions]
Run "ML /help" or "ML /?" for more info

错误信息如下:

Microsoft (R) Macro Assembler Version 7.10.3077
Copyright (C) Microsoft Corporation. All rights reserved.

Assembling: C:\Downloads\123.asm
C:\Downloads\123.asm(9) : error A2008: syntax error : ,
C:\Downloads\123.asm(15) : warning A4023: with /coff switch, leading underscore required for start address : START

我的OS是:XP+SP1

请问我在XP下怎样才能让这段代码过?
小弟才学汇编想跟书上的脚步走可是每次汇编都失败,请各位老师指点。
...全文
84 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhouxi 2004-04-10
  • 打赏
  • 举报
回复
真是非常感谢。
constname 2004-04-10
  • 打赏
  • 举报
回复
第二次编译
----------------------------------------------------------------------
D:\asm>masm display_1.asm dis_1.obj dis_1.lst
Microsoft (R) MASM Compatibility Driver
Copyright (C) Microsoft Corp 1993. All rights reserved.

Invoking: ML.EXE /I. /Zm /c /Fodis_1.obj /Fldis_1.lst /Ta display_1.asm

Microsoft (R) Macro Assembler Version 6.11
Copyright (C) Microsoft Corp 1981-1993. All rights reserved.

Assembling: display_1.asm
display_1.asm(9): error A2006: undefined symbol : SG
------------------------------------------------------------------------------
提示 SG 为未定义标识符, 从你的代码来看,这是一个COM文件, 数据在代码段内定义, 但是只有定义了 MSG, 所以估计是把 MSG打成了 ,SG 的结果,改为
MOV DX,OFFSET MSG 或者 LEA DX,MSG
然后编译连接. 结果为
D:\asm>masm display_1.asm dis_1.obj dis_1.lst
............
D:\asm>LINK DIS_1.OBJ

Microsoft (R) Segmented Executable Linker Version 5.31.009 Jul 13 1992
Copyright (C) Microsoft Corp 1984-1992. All rights reserved.

Run File [DIS_1.exe]:
List File [nul.map]:
Libraries [.lib]:
Definitions File [nul.def]:
LINK : warning L4021: no stack segment

D:\asm>DIS_1
Hi! This is a dollar sign terminated string.
D:\asm>
constname 2004-04-10
  • 打赏
  • 举报
回复
MASM 的用法:
--------------------------------------------------------------------------------
D:\asm>masm
Microsoft (R) MASM Compatibility Driver Version 6.11
Copyright (C) Microsoft Corp 1993. All rights reserved.

usage: MASM [option...] source(.asm),[out(.obj)],[list(.lst)],[cref(.crf)][;]
Run "MASM /H" for more info

---------------------------------------------------------------------------------
masm 可以输出.lst 文件, 通过此文件可以找到原代码错误之处.
D:\asm>masm display_1.asm dis_1.obj dis_1.lst
---------------------dis_1.lst-----------------------------------------------------
Microsoft (R) Macro Assembler Version 6.11 04/10/04 18:24:50
display_1.asm Page 1 - 1


;Display string (09H)
0000 CODE SEGMENT PUBLIC
ASSUME CS:CODE,DS:CODE
ORG 100H
0100 EB 2D START: JMP BEGIN
0102 48 69 21 20 54 68 MSG DB 'Hi! This is a dollar sign terminated string.','$'
69 73 20 69 73 20
61 20 64 6F 6C 6C
61 72 20 73 69 67
6E 20 74 65 72 6D
69 6E 61 74 65 64
20 73 74 72 69 6E
67 2E 24
012F 8C C8 BEGIN: MOV AX,CS
0131 8E D8 MOV DS,AX
MOV DX,OFFSET,SG ;(9)
display_1.asm(9): error A2008: syntax error : ,
0133 B4 09 MOV AH,09H
0135 CD 21 INT 21H
0137 B4 4C MOV AH,4CH
0139 CD 21 INT 21H
013B CODE ENDS
END START ;(15)
Microsoft (R) Macro Assembler Version 6.11 04/10/04 18:24:50
display_1.asm Symbols 2 - 1




Segments and Groups:

N a m e Size Length Align Combine Class

CODE . . . . . . . . . . . . . . 16 Bit 013B Para Public


Symbols:

N a m e Type Value Attr

BEGIN . . . . . . . . . . . . . L Near 012F CODE
MSG . . . . . . . . . . . . . . Byte 0102 CODE
START . . . . . . . . . . . . . L Near 0100 CODE

0 Warnings
1 Errors
---------------------------------------------------------------------------------
可以看到
MOV DX,OFFSET,SG ;(9)
display_1.asm(9): error A2008: syntax error : ,

很明显 MOV DX,OFFSET SG 应该是 MOV DX,OFFSET SG 或者 LEA DX, SG

21,459

社区成员

发帖
与我相关
我的任务
社区描述
汇编语言(Assembly Language)是任何一种用于电子计算机、微处理器、微控制器或其他可编程器件的低级语言,亦称为符号语言。
社区管理员
  • 汇编语言
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧