使用嵌入式x86汇编数组? [英] Using an array in embedded x86 assembly?

查看:157
本文介绍了使用嵌入式x86汇编数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个方法(C ++),返回一个字符,采取字符数组作为它的参数。

I have a method (C++) that returns a character and takes an array of characters as its parameters.

我和装配搞乱首次,只是试图返回数组的第一个字符在DL寄存器中。这是我到目前为止有:

I'm messing with assembly for the first time and just trying to return the first character of the array in the dl register. Here's what I have so far:

char returnFirstChar(char arrayOfLetters[])
{
 char max;

 __asm
 {
  push eax
      push ebx
       push ecx
     push edx
  mov dl, 0

  mov eax, arrayOfLetters[0]
  xor edx, edx
  mov dl, al

  mov max, dl       
  pop edx
  pop ecx
  pop ebx
  pop eax

 }

 return max;
}

由于某种原因,这个方法返回一个♀

For some reason this method returns a ♀

任何想法去上什么?谢谢

Any idea whats going on? Thanks

推荐答案

组件的行:

mov eax, arrayOfLetters[0]

移动一个指针字符数组 EAX (注意,这不是 arrayOfLetters [0] 会做在C,但装配不C)。

is moving a pointer to the array of characters into eax (note, that's not what arrayOfLetters[0] would do in C, but assembly isn't C).

您需要添加下列正确的是让你的装配工作的点点后:

You'll need to add the following right after it to make your little bit of assembly work:

mov al, [eax]

这篇关于使用嵌入式x86汇编数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆