两个指数在装配阵列比较 [英] Comparing two indices in an array in assembly

查看:100
本文介绍了两个指数在装配阵列比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在写汇编程序,将反向的字符串的顺序。

我的字符串存储在 EBX 注册。结果
当前计数被保存在 ECX 注册和
字符串长度存储在 EAX 注册。
我很困惑如何在计数地位,在EBX,并在阵列中的另一个元素访问的元素。
在伪code

 诠释计数= 0;
INT RCOUNT = myString.length() - 1;
而(COUNT< RCOUNT)
    MyString的[统计] ^ =的myString [RCOUNT]
    MyString的[RCOUNT] ^ =的myString [统计]
    MyString的[统计] ^ =的myString [RCOUNT]
    算上++;
    rcount--;

了^ =运算符是一个异或声明。
所以在组装这将是沿着线(带编码不正确的,我不知道如何访问数组汇编)

  XOR EBX [计数],EBX [RCOUNT]


解决方案

异或交换是不是在这种情况下非常有用的。就在2项加载到2个寄存器,并把它们写出来交换。例如:

  MOV人,[EBX + ECX];假设ECX =计数
MOV啊,[EBX + EDX];假设EDX = RCOUNT
MOV [EBX + ECX]啊;写出
MOV [EBX + EDX]人;换

I'm currently writing a program in assembly that will "reverse" the order of a string.

My string is stored in the ebx register.
The current count is stored in the ecx register and the string length is stored in the eax register. I'm confused about how to access the element at the 'count' position in the ebx and at another element in the array. in psuedo code

int count = 0;
int rcount = myString.length() - 1;
while(count < rcount)
    myString[count] ^= myString[rcount];
    myString[rcount] ^= myString[count];
    myString[count] ^= myString[rcount];
    count++;
    rcount--;

the ^= operator is an xor statement. so in assembly it would be along the lines of(with improper coding I don't know how to access arrays in assembly)

 xor ebx[count], ebx[rcount]

解决方案

The XOR swap is not very useful in this case. Just load the 2 items into 2 registers and write them out swapped. For example:

mov al, [ebx + ecx] ; assume ecx = count
mov ah, [ebx + edx] ; assume edx = rcount
mov [ebx + ecx], ah ; write out
mov [ebx + edx], al ; swapped

这篇关于两个指数在装配阵列比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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