开发者

Need Assembly Programming Help (TASM) - Booth's Algorithm

I've written an algorithm to simulate Booth's Algorithm using only Add, Sub, and Logical Operators and return a hexadecimal value. My Tasm compiler keeps throwing me these errors. When I try to omodify the code, it still doesn't work. Could someone help me out please.

(29) Extra characters on line

(38) Illegal immediate

(44) Illegal immediate

(52) Underfined symbol: RES2

(126) Expecting pointer type

;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 开发者_如何学JAVA              
 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


My asm is a little rusty, but you can try these changes:

line 29:

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

or alternately:

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

line 38:

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

line 44:

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

line 52:

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

line 126 - I'm not sure what's going on here...


Errors in your code:

This line is completely invalid:

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

It would have to be just:

move ax,data

You should also include this right before start::

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

These are invalid as well, since you wanted to define memory variables, I guess:

n1=0
n2=0

It should be:

n1 db 0
n2 db 0

When you access n1 and n2 write it this way, as Stobor already noted:

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

All variable references done by "addressing" in assembly, so the square brackets.

And you didn't define RES2 at all as noted in a comment already.

Hope this helps.

See also:

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

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

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

Add a comment here if something is not clear enough.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜