Assembly Code Help

Please support our Assembly advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2009
Posts: 1
Reputation: ovidiu82 is an unknown quantity at this point 
Solved Threads: 0
ovidiu82 ovidiu82 is offline Offline
Newbie Poster

Assembly Code Help

 
0
  #1
Nov 9th, 2009
I am trying to do this: z=(5*a-b/7)/(3/b+a*a) in assembly code and I keep getting some errors.
Here is the code & the errs.


  1. assume cs:code,ds:data
  2. data segment
  3. a dw 5
  4. b dw 6
  5. z dw 10
  6.  
  7.  
  8. intermed dw ?
  9. rez db ?
  10. data ends
  11. code segment
  12. start:
  13.  
  14. mov ax,data
  15. mov ds,ax
  16. mul 5 ; ERROR Argument needs type override & Illegal immediate
  17. ; in ax we will have a*5;
  18. mov bx,ax ; we move the ax data in the bx register bx:ax
  19. mov ax,b; we move the b in the ax register ax:b
  20. cwd ; ERROR Argument needs type override& Illegal immediate ;we convert the word from ax in doubleword, in dx:ax
  21. idiv 7 ; ax=b/7
  22. sub bx,ax; we substract ax out of bx ( ax: ax-bx <=> 5*a-b/7 )
  23. mov intermed, ax ;we move all the data from ax to interm=(5*a-b*7)
  24.  
  25. mov al,3
  26. idiv b; ax:3/b
  27. mov bx,a; bx:a
  28. mul a; bx:a*a
  29. add ax, bx; ax=ax+bx;
  30. mov bx,intermed; Err. Undefined symbol Intermed
  31. idiv ax; we obtain the result in al and the reminder in ah
  32.  
  33. mov rez,al
  34.  
  35. mov ax, 4C00h
  36. int 21h
  37. code ends
  38. end start

Where are my sins? Thank you !
Last edited by ovidiu82; Nov 9th, 2009 at 1:12 am. Reason: i clarified some potential confusing aspects
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 95
Reputation: gusano79 is on a distinguished road 
Solved Threads: 9
gusano79 gusano79 is offline Offline
Junior Poster in Training
 
0
  #2
Nov 9th, 2009
Originally Posted by ovidiu82 View Post
Where are my sins?
As a general recommendation, you should read some technical documentation on the x86 instructions... this page is a good start, but the Intel processor manuals are the real deal.

As for your specific questions:

  1. mul 5 ; ERROR Argument needs type override & Illegal immediate

operands to mul are either registers or memory locations; immediate values aren't supported.

  1. cwd ; ERROR Argument needs type override& Illegal immediate ;we convert the word from ax in doubleword, in dx:ax
  2. idiv 7 ; ax=b/7

cwd should be fine... this error might be for your idiv , which has the same restriction as mul --only registers or memory locations.

  1. mov bx,intermed; Err. Undefined symbol Intermed

Not sure what's wrong off the top of my head.
--smg
Reply With Quote Quick reply to this message  
Reply

Tags
assembly

Message:




Views: 634 | Replies: 1
Thread Tools Search this Thread



Tag cloud for assembly
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC