-2

我编写了一个算法来模拟布斯算法,只使用加、减和逻辑运算符并返回一个十六进制值。我的 Tasm 编译器不断向我抛出这些错误。当我尝试修改代码时,它仍然不起作用。有人可以帮帮我吗?

(29) 行上的额外字符
(38) 非法立即数
(44) 非法立即
数 (52) 下划线符号:RES2
(126) 期望指针类型

;Booths Algorithm

;
;
;
;
;


.model small

.stack

 .data
 prompt db 13,10,"Enter first number to multiply. $"
 prompt2 db 13,10,"Enter second number to multiply. $"
 res db 13,10,"The answer is $"

 ans dw 2
 hold db 0 
 n1=0
 n2=0


.code

start:

mov ax,seg prompt,prompt2,res,ans,hold,n1,n2
mov ds,ax

mov ah,09h
mov dx,offset prompt                     
int 21h

call read                

mov n1,bl            
mov ah,09h
mov dx, offset prompt2           
int 21h

call read                
mov n2,bl            


call Algorithm              

 mov [ans],ax          
 mov bx,ax

 mov dx,offset res2             
 mov ah,09h
 int 21h

 call write              

 mov ah,4ch
 int 21h

 hlt

read:                       
 mov ah,00h             
 mov [hold],bl

f0:
 mov al,01h              
 int 21h                 
 cmp al,0dh             
 je Copy                   
 mov cl,al              
 sub cl,30h            
 mov al,[hold]           
 mov bl,0ah              
 mul bl                  
 mov [hold],al           
 add [hold],cl           
 jmp f0                 


Copy :
 mov bl,[hold]           
 ret                     

Algorithm:                     
 mov ah,0              
 mov al,n1         
 mov cx,8                
 mov bh,n2         
 clc      

f1:
 mov bl,al      
 and bl,1                
 jnz f2               
  JNC f3               
  sub ah,bh               
 jmp f3

f2:
 jc f3
 add ah,bh

 f3:
  shr ax,1
  loop f1
  ret

write:
 mov al,bl
 lea di,[ans]
 mov bh,0ah
 mov cl,24h
 mov [di],cl
 dec di

f4:
 mov ah,00h
 div bh
 add ah,30h
 mov [di],ah
 dec di
 cmp al,00h
 jnz 4
 inc di
 mov ah,09h
mov dx,di
 int 21h
 ret

end start
4

2 回答 2

2

我的 asm 有点生疏了,但你可以尝试以下更改:

第 29 行:

mov ax,@data  ; should pick up the address of the data segment

或者:

mov ax, seg prompt   ; seg takes only one variable, not multiple...

第 38 行:

mov [n1],bl      ; memory addresses need square brackets

第 44 行:

mov [n2],bl      ; memory addresses need square brackets

第 52 行:

mov dx,offset res    ; don't know where res2 came from

第 126 行 - 我不确定这里发生了什么......

于 2009-11-29T00:51:54.813 回答
0

您的代码中的错误:

此行完全无效:

mov ax,seg prompt,prompt2,res,ans,hold,n1,n2.

它必须是:

move ax,data

您还应该在之前包含此内容start:

assume cs:code, ds:data, ss:stack

这些也是无效的,因为你想定义内存变量,我猜:

n1=0
n2=0

它应该是:

n1 db 0
n2 db 0

当您以这种方式访问n1​​和n2编写它时,正如 Stobor 已经指出的那样:

mov [n1],bl
mov [n2],bl

所有变量引用都是通过汇编中的“寻址”完成的,所以方括号。

而且您根本没有RES2按照评论中的说明进行定义。

希望这可以帮助。

也可以看看:

http://www.xs4all.nl/~smit/asm01001.htm

http://www.laynetworks.com/assembly%20tutorials2.htm

http://www.faqs.org/faqs/assembly-language/x86/borland/

如果不够清楚,请在此处添加评论。

于 2009-11-29T01:21:36.167 回答