汇编语言问题

jihuaikui 2007-11-30 04:58:50
大家帮个忙!谢了!
我编了一个汇编程序,程序的思想是用子程序 COMPUTE 计算数组X和Y,然后将每次计算结果
保存至数组R的响应位子,X,Y,R都是字数组,子程序COMPUTE和主程序不在同一程序模块,
我是将主程序和子程序所在的俩个模块的数据段定义为同名,都被置为COMMON,程序如下,
可是在连接位.EXE文件时,汇编器提示我说:error L2029:'compute':Unresolved extrnal
请问错那里了?
;This is a program for compute sum from x,y
;**********************************************************
; source module 1
extrn compute:far

data segment common ;define data as common to cnnect with another same segment
x dw 1,2,3,4,5
y dw 1,2,3,4,5
r dw 5 dup(?)
data ends

code1 segment ;define a code segment

main proc far
assume cs:code1,ds:data
start:
mov ax,data ;initial ds
mov ds,ax

call far ptr compute ;call compute program

mov dx,r[2] ;display result
add dx,30h
mov ah,2
int 21h
mov ah,4ch
int 21h
main endp
code1 ends
end start
;**********************************************************

; source module 2
public compute ;make the program can be called

data segment common ;define data as common to cnnect with another same segment
x dw 1,2,3,4,5
y dw 1,2,3,4,5
r dw 5 dup(?)
data ends

code2 segment

compute proc far
assume cs:code2,ds:data

mov ax,data ;initial ds
mov ds,ax
push ax ;save all the register used
push si
push bx
push cx
push di
mov cx,5 ;the times of loop
lea si,x ;initial si
lea di,y
lea bx,r
xor ax,ax ;clear ax
loop1:
mov ax,[si] ;get a element of x

add ax,[di] ;cmopute x and y
mov [bx],ax ;save the result
add si,2
add di,2
add bx,2
loop loop1
pop di
pop cx
pop bx
pop si
pop ax
ret
compute endp
code2 ends
end
;**********************************************************
...全文
134 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
jihuaikui 2007-12-01
  • 打赏
  • 举报
回复
嗯,非常感谢你,我懂了,谢谢你的指导
zara 2007-12-01
  • 打赏
  • 举报
回复
/Zm 是 Masm6 的汇编目录 ml.exe 的一个选项, 就是以 Masm5 的兼容模式来进行编译.
Masm5 应该是类似的吧, 先分别对 1.asm 和 2.asm 进行编译, 然后将 1.obj 和 2.obj 链接到一起:


R:\>masm 1.asm;
Microsoft (R) Macro Assembler Version 5.00
Copyright (C) Microsoft Corp 1981-1985, 1987. All rights reserved.


50822 + 415834 Bytes symbol space free

0 Warning Errors
0 Severe Errors

R:\>masm 2.asm;
Microsoft (R) Macro Assembler Version 5.00
Copyright (C) Microsoft Corp 1981-1985, 1987. All rights reserved.


50938 + 415718 Bytes symbol space free

0 Warning Errors
0 Severe Errors

R:\>link 1.obj+2.obj;

Microsoft (R) Overlay Linker Version 3.65
Copyright (C) Microsoft Corp 1983-1988. All rights reserved.

LINK : warning L4021: no stack segment

R:\>1.exe
4
jihuaikui 2007-11-30
  • 打赏
  • 举报
回复
对不起我是刚学的,我怎么没见过ml /zm 这种汇编指令呀!
我是用MASM5汇编的,请问用MASM5怎么连接两个模块呀?
zara 2007-11-30
  • 打赏
  • 举报
回复
没有问题啊. 我将第一个模块保存为 1.asm, 第二为 2.asm, 用 Masm6 进行编译链接:
R:\>ml /c /Zm 2.asm
Microsoft (R) Macro Assembler Version 6.00
Copyright (C) Microsoft Corp 1981-1991. All rights reserved.

Assembling: 2.asm

R:\>ml /Zm 1.asm 2.obj
Microsoft (R) Macro Assembler Version 6.00
Copyright (C) Microsoft Corp 1981-1991. All rights reserved.

Assembling: 1.asm

Microsoft (R) Segmented-Executable Linker Version 5.13
Copyright (C) Microsoft Corp 1984-1991. All rights reserved.

Object Modules [.OBJ]: 1.obj+
Object Modules [.OBJ]: "2.obj"
Run File [1.exe]: "1.exe"
List File [NUL.MAP]: NUL
Libraries [.LIB]:
Definitions File [NUL.DEF]: ;
LINK : warning L4021: no stack segment

R:\>1.exe
4
R:\>

21,459

社区成员

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

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