Convert Instruction in assembly code lods and stos so NASM can compile

后端 未结 2 1739
长发绾君心
长发绾君心 2021-01-21 07:11

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)
         


        
2条回答
  •  心在旅途
    2021-01-21 08:09

    what lodsb does is:

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

    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).

    and stosb does

    mov [es:edi],al
    inc edi
    

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

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

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


    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.

    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.

提交回复
热议问题