开发者

Why PUSH a variable via a register, rather than PUSH the variable directly in assembly language?

开发者 https://www.devze.com 2023-04-07 12:10 出处:网络
I came across a key logger program in asm in a forum. I though that I might create a key logger myself. When I was reading the code to see what was actually going on in that program, I came across som

I came across a key logger program in asm in a forum. I though that I might create a key logger myself. When I was reading the code to see what was actually going on in that program, I came across some interesting things.

1.The program almost never pushed a variable to the stack. It moved the value of the variable to a register and then pushed the register. eg.

;hInst:DWORD 4
lea esi, hInst
push esi

2.The program cleared arrays using stosd. eg:

    ;array1 BYTE 256 D开发者_StackOverflow中文版UP(?)
    lea edi, array1
    push 256/4
    xor eax, eax
    rep stosd 3

The program used push-pop to assign values as in the above example.

What are the advantages of the above conventions?


1) I can't think of any advantages on current machines, but way back in the day, you could only push regs. There was no push mem/immed form.

2) Simplicity/same as #1. I've heard that nowadays the string instructions are all but deprecated. However, way back in the day they were the only way to fly as they were much faster (cycle times not much better, but conserved the VERY limited memory bandwidth of the day by not forcing more instruction loads).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号