Inline Assembly Help Please!

Reply

Join Date: Jun 2007
Posts: 2
Reputation: StockBreak is an unknown quantity at this point 
Solved Threads: 0
StockBreak StockBreak is offline Offline
Newbie Poster

Inline Assembly Help Please!

 
0
  #1
Jun 26th, 2007
Hi, I recently started programming with inline assembly (I use Visual C++), but I have found a bug that I cannot solve.
Why does it give an error?

// C language
unsigned char array[] = {1, 2, 3, 4, 5, 6, 7};

// Assembly
__asm
{
XOR CL,CL

MOV AL,array[0] ; ok
MOV AL, array+2 ; ok

MOV AL,array[CL] ; ERROR!!!
}

The error is -> "error C2403: 'CL' : register must be base/index in 'second operand'".

I tested it many times and I found that the only way to make it work is to use ECX register as index! Why?
If I use ANY OTHER register it will not compile (as above) or it will give a Fatal Error if I use another EXX register (as EAX or EBX).
The problem is that on my program I have a "nested for loop" and so I can't use just 1 counter (ECX), but I need 2 of them and they must be BYTE register (as CL/CH) because the array variable is a char. Any idea?

Thank you very much!
Luke

P.S: any better idea on how to write effective inline nested loop?
Last edited by StockBreak; Jun 26th, 2007 at 8:47 pm.
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: Inline Assembly Help Please!

 
0
  #2
Jun 27th, 2007
I guess in your rush to spam multiple message boards
http://www.tek-tips.com/viewthread.c...1382444&page=1
with the same question, that you couldn't be bothered with simple courtesy of reading the posting guidelines on any of them.
http://www.daniweb.com/forums/announcement125-3.html
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 2
Reputation: StockBreak is an unknown quantity at this point 
Solved Threads: 0
StockBreak StockBreak is offline Offline
Newbie Poster

Re: Inline Assembly Help Please!

 
0
  #3
Jun 27th, 2007
Originally Posted by Salem View Post
I guess in your rush to spam multiple message boards
http://www.tek-tips.com/viewthread.c...1382444&page=1
with the same question, that you couldn't be bothered with simple courtesy of reading the posting guidelines on any of them.
http://www.daniweb.com/forums/announcement125-3.html
Yes, you are completely right...
The problem is that I have less than 2 days to finish the project for my Computer Science school and when I posted that, I was really running mad (I worked for so many days and moreover it was 03:00 of night here in Italy!!!), so I decided to find an Assembly forum to ask for help! I still don't understand why it does not compile , I really need help...

I am very sorry
Luke

P.S: since I can no more edit my first post, here the is the code (for the problem, look at the first post):

  1. //C language
  2. unsigned char array[] = {1, 2, 3, 4, 5, 6, 7};
  3.  
  4. // Assembly
  5. __asm
  6. {
  7. XOR CL,CL
  8.  
  9. MOV AL,array[0] ; ok
  10. MOV AL,array+2 ; ok
  11.  
  12. MOV AL,array[CL] ; ERROR!!!
  13. }
Last edited by StockBreak; Jun 27th, 2007 at 5:43 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,346
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1460
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Inline Assembly Help Please!

 
0
  #4
Jun 29th, 2007
using VC++ 2005 express
  1. int main()
  2. {
  3. unsigned char array[] = {1, 2, 3, 4, 5, 6, 7};
  4.  
  5. // Assembly
  6. __asm
  7. {
  8. MOV AL,array[0] ; ok
  9. MOV AL,array+2 ; ok
  10. lea ebx, array
  11. MOV AL, [ebx] ; ok
  12. }
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC