本文介绍了将指令转换为汇编代码段和目录,以便NASM可以进行编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好,所以我尝试使用nasm -f elf final.asm在汇编中汇编一些代码:

Ok so I am trying to assemble some code in assembly using nasm -f elf final.asm:

xor eax,eax
push eax
push dword(0x75792273)
push dword(0x70742027)
push dword(0x77777875)
push dword(0x20237678)
push dword(0x76727827)
push dword(0x27797175)
push dword(0x75711225)
push dword(0x72747676)
push dword(0x74231476)
push dword(0x70707470)
push dword(0x23247077)
push dword(0x78707822)
push dword(0x24711174)
push dword(0x22707373)
push dword(0x78717974)
push dword(0x75771777)
push dword(0x70777125)
push dword(0x73731472)
push dword(0x71277377)
push dword(0x79251822)
push dword(0x79707478)
push dword(0x78742779)
push dword(0x72727871)
push dword(0x71251475)
push dword(0x27247772)
push dword(0x79757479)
push dword(0x70227071)
push dword(0x77737420)
push dword(0x70251970)
push dword(0x74747127)
push dword(0x23277677)
push dword(0x79712024)
push esp
pop esi
mov edi,esi
mov edx,edi
cld
mov ecx,0x80
mov ebx,0x41
xor eax,eax
push eax
lods byte[esi]
xor eax,ebx
stos byte[es:edi]
loop 0xb7
push esp
pop esi
int 0x3

这将导致以下错误:

final.asm:44: error: parser: instruction expected
final.asm:46: error: parser: instruction expected

我在以下位置找到了这些错误的答案: NASM:解析器:指令预期的代表移动

I found the answer to these errors at:NASM: parser: instruction expected rep movs

基本上,这表示NASM不识别lods和stos指令.这意味着我需要将它们转换为NASM可以识别的内容,以便获得相同的结果.

Basically, this says that the lods and stos instructions are not recognized by NASM. Which means I need to convert them into something NASM does recognize so that I get the same result.

我的问题是,我可以将这两行更改为什么,以便NASM可以对其进行编译,以便最终对其进行调试.

My question is, what can I change these two lines to so that NASM can compile it so that I can ultimately debug it.

推荐答案

lodsb的作用是:

mov al,[esi]
inc esi           ; (or dec, according to direction flag)

您也可以使用
lodsw加载单词(到ax,将esi增加2),或
lodsd加载双字(到eax,将esi增加4).

you could also use
lodsw to load words (to ax, increase esi by 2), or
lodsd to load dwords (to eax, increase esi by 4).

stosb确实

mov [es:edi],al
inc edi

与此处相同,stoswstosd将存储2或4个字节(并相应地调整edi)

same here, stosw and stosd will store 2 or 4 bytes (and adjusting edi accordingly)

首先从内存中加载,由SOURCE(ESI)寄存器指向,然后再写入由DESTINATION(ES:EDI)寄存器指向的存储器.

First loads from memory, pointed to by the SOURCE (ESI) register, latter writes to memory pointed by the DESTINATION (ES:EDI) register.

您不需要(也不能)指定将使用哪些寄存器.源始终为E S I,而目标始终为E D I

You don't need to (and cannot) specify which registers will be used. Source will always be ESI, and Destination always EDI

在段寄存器上lods指令可与段覆盖前缀(即ss lodsb)一起使用. stos指令固定为es(原始答案中缺少详细信息)细分使用,并且不能被覆盖.

Edit on segment registers:The lods instruction can be used together with segment override prefix (i.e. ss lodsb). The stos instruction is fixed to es (missing detail in original answer) segment usage, and can't be overridden.

movsb/movsw/movsd指令(size*(mov [es:edi],[ds:esi] inc esi inc edi))也可以在源端被覆盖,即. es movsb将从es:esi而不是ds:esi提取字节,但是目标段寄存器固定为es.

The movsb/movsw/movsd instructions (size*(mov [es:edi],[ds:esi] inc esi inc edi)) can be also overridden on the source side, ie. es movsb will fetch bytes from es:esi instead of ds:esi, but the destination segment register is fixed to es.

这篇关于将指令转换为汇编代码段和目录,以便NASM可以进行编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 14:03