开发者

Get char at index location in char array Assembly X86 embedded

I am having a lot of trouble accessing a value in an array of chars at a specific location. I am using inline-assembly in C++ and using visual studio (if that is of any help). Here is my code:

char* addTwoStringNumbers(char *num1)
{
    // here is what I have tried so far:
    movzx eax, num1[3];
    mov al, [eax]
}

When I debug, I can see that num1[3] is the value I want but I can't seem to make either al or eax equal that value, it seems to always 开发者_开发知识库be some pointer reference. I have also played around with Byte PTR with no luck.


I'm not good neither at inline assembly, neither at MASM syntax, but here are some hints:

1) Try this:

mov   eax, num1 ;// eax points to the beggining of the string
movsx eax, [eax + some_index] ;// movsx puts the char num1[some_index] in eax with sign extend.

(movzx is for unsigned char, so we used movsx)

2) You need to pass the value from eax to C. The simpliest way is to declare a variable and to put results there: int rez; __asm { mov rez, eax; };

3) If you want to write the whole function in assembly, you should consider using the naked keyword (and read about calling conventions). If not, make sure you preserve registers and don't damage the stack.


Looks like someone's doing their ICS 51 homework! Follow ruslik's advice and you'll be done in no time.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜