944,149 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 3384
  • Assembly RSS
Jun 26th, 2007
0

Inline Assembly Help Please!

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
StockBreak is offline Offline
2 posts
since Jun 2007
Jun 27th, 2007
0

Re: Inline Assembly Help Please!

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
Team Colleague
Reputation Points: 5862
Solved Threads: 950
Posting Sage
Salem is offline Offline
7,164 posts
since Dec 2005
Jun 27th, 2007
0

Re: Inline Assembly Help Please!

Click to Expand / Collapse  Quote originally posted by Salem ...
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):

Assembly Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
StockBreak is offline Offline
2 posts
since Jun 2007
Jun 29th, 2007
0

Re: Inline Assembly Help Please!

using VC++ 2005 express
Assembly Syntax (Toggle Plain Text)
  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. }
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2283
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,963 posts
since Aug 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Assembly Forum Timeline: programing problem
Next Thread in Assembly Forum Timeline: Strings and NASM - WinXP





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC