| | |
Inline Assembly Help Please!
![]() |
•
•
Join Date: Jun 2007
Posts: 2
Reputation:
Solved Threads: 0
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?
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.
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
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
•
•
Join Date: Jun 2007
Posts: 2
Reputation:
Solved Threads: 0
•
•
•
•
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
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)
//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!!! }
Last edited by StockBreak; Jun 27th, 2007 at 5:43 am.
using VC++ 2005 express
Assembly Syntax (Toggle Plain Text)
int main() { unsigned char array[] = {1, 2, 3, 4, 5, 6, 7}; // Assembly __asm { MOV AL,array[0] ; ok MOV AL,array+2 ; ok lea ebx, array MOV AL, [ebx] ; ok }
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.
![]() |
Similar Threads
- QBASIC under Windows XP (Visual Basic 4 / 5 / 6)
- intergrating ASM to C++ (C++)
- inline assembly getting user input.(djgpp) (Assembly)
- I Need Assembly help w/reversing strings (Assembly)
- Using Assembly Codes in Bloodshed Dev-CPP (C)
- How can i use inline assembly in VC++ editor (C++)
Other Threads in the Assembly Forum
- Previous Thread: programing problem
- Next Thread: Strings and NASM - WinXP
| Thread Tools | Search this Thread |






