通用MASM code:存储依赖于符号的类型寄存器的8位或16位 [英] Generic MASM code: storing 8 or 16 bits of a register depending on TYPE of a symbol

查看:302
本文介绍了通用MASM code:存储依赖于符号的类型寄存器的8位或16位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想写一个数组倒车功能的正常工作静态数组是否持有字节 s或秒。

I am trying to write an array-reversing function that works correctly whether the static array holds BYTEs or WORDs.

这是我到目前为止,我认为数组是大小

This is what I have so far where I assumed the array was of size WORD

.data
    myArray WORD 1231h, 2342h, 3353h, 4564h, 5675h, 7, 9

.code
main proc
    mov eax, 0  ;index of the left side of the array
    mov esi, SIZEOF myArray
    sub esi, TYPE myArray   ;index of the right side of the array

    Switch:
        movsx edx, [myArray + eax]  ;puts the left element of the array in eax

        xchg dx,  [myArray + esi]   ;exchange edx with the right element of the array

        mov [myArray + eax], dx ;puts the right element into the left part of the array

        add eax, TYPE myArray   ;eax is currently pointing to leftPtr so we add the appropriate amount to 
                                ;it depending on the size of each element in myArray. This way it will point
                                ;to the next element in the array

        sub esi, TYPE myArray   ;same concept as above except we are subtracting the amount from the right pointer
        cmp esi, eax            ;compare the right pointer to the left pointer
        jnle Switch             ;Jump if the right pointer is !(<=) the left pointer

main endp
end main

我可以使用 MOVZX / MOVSX 指令,从阵列移动更小尺寸的值转换成32位寄存器。

I can use the movzx/movsx instruction to move the smaller sized value from the array into a 32-bit register.

问题正在写东西,汇编为8bit的商店或16bit店根据键入

The problem is writing something that assembles to an 8bit store or 16bit store depending on TYPE.

推荐答案

您可以有条件地对myArray的类型定义符号是可以是文本 DL DX EDX 和使用,在地方登记的。是这样的:

You can define a symbol conditionally on the type of myArray to be either the text dl, dx or edx and use that in place of the register. Something like:

    IF TYPE myArray EQ TYPE BYTE
@DX TEXTEQU <dl>
    ELSEIF TYPE myArray EQ TYPE WORD
@DX TEXTEQU <dx>
    ELSEIF TYPE myArray EQ TYPE DWORD
@DX TEXTEQU <edx>
    ENDIF

    mov @DX, [myArray + eax]   ;puts the left element of the array in DX
    xchg @DX, [myArray + esi]  ;exchange DX with the right element of the array
    mov [myArray + eax], @DX   ;puts the right element into the left part of the array

这篇关于通用MASM code:存储依赖于符号的类型寄存器的8位或16位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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