我怎样才能将内存中的值放到masm32中的eax寄存器中

时间:2015-02-26 13:53:20

标签: assembly masm32

所以我尝试做"加密"使用xor命令的代码

这是我的代码

.486
.model flat,stdcall
option casemap :none ;case sensitive

;;_____MASM MACROS___
include \masm32\include\masm32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\masm32.lib
includelib \masm32\lib\kernel32.lib

;;_____DATA____
.data
msg DB "I LIKE ASSEMLY$",0H
my_xor db 0101010101010101b

;;_____CODE____
.code
_start:

encript_lbl:

mov ax,[word msg]
xor ax,[my_xor]
mov [msg],ax
jmp print_lbl

decript_lbl:
mov ax,[msg]
xor ax,[my_xor]
mov [msg],ax


print_lbl:
mov dx,offset msg
mov ah,9h
int 21h
mov ah,2 ;new line
mov dl,10
int 21h
mov dl,13
int 21h
jmp decript_lbl





end _start

当我尝试在masm32中编译它时,我得到一堆错误

lines 23,24,28,29,30 invalid instruction operand (a2070)
line 22 missing operator in expration (a2206)
line 34 (a2022) instruction operand must be in the same size
line 14 (a2071) initializer magnitude to large for spesofied 

现在我尝试做很多事来解决这个问题,但是当我成功修复1个问题时,我会得到一个新的......

所以这个节目采取了字符串"我喜欢汇编$"通过0101010101010101的xor opernd加密此字符串,然后打印加密的字符串 然后使用my_xor db 0101010101010101的xor再次解密字符串 并打印解密的字符串

任何一个人都知道如何解决这个问题?

谢谢你们 迈克

1 个答案:

答案 0 :(得分:0)

修复这些特定错误消息不会为您提供所需的结果。

当您指示计算机对存储在AX中的值进行异或时,它仅适用于当前存储在AX中的16位。汇编程序不知道您在[msg]的地址存储字符串。

你需要遍历[msg]引用的数据,只要它没有值为0(空终止字符串),就对每个字节进行异或。

From StackOverflow:第一个答案显示循环如何工作,但不处理保存结果。

的伪代码:

Get a pointer to the start of the message.
Start loop.
  - Exit loop if referenced byte is 0.
  - XOR the byte referenced by the pointer.
  - Increment the pointer.
End loop.

查看Using Square Brackets To Reference Memory in ASM

-----------------编辑---------------

要从代码中获取单字符功能,请尝试删除方括号,因为它们取消引用存储在寄存器中或标识符位置的值。此外,一次执行一个字节,因为您的字符串以单个空字节终止。

如果希望INT 21h函数生成输出,则需要生成MS-DOS .EXE或.COM文件。

encript_lbl:
mov al,msg
xor al,my_xor
mov msg,al
jmp print_lbl

Details on the XOR instruction