在嵌入式x86程序集中使用数组? [英] Using an array in embedded x86 assembly?

查看:150
本文介绍了在嵌入式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天全站免登陆