Does pushing a register empty that register?

后端 未结 2 1508
终归单人心
终归单人心 2021-01-28 04:28

I have read many books and instructions on this, but one thing that is never specified is what happens to a register after you push it on the stack. For example if you write in

2条回答
  •  一整个雨季
    2021-01-28 05:24

    The register keeps its value after push instruction.

    push effects two places: the stack memory that get new value, and the value of esp which now points to the new top. You can deduce that from the description of push operation:

    if(StackAddressSize == 32) {
        if(OperandSize == 32) {
            ESP = ESP - 4;
            SS:ESP = Source //push doubleword
        }
        else { //OperandSize == 16
            ESP = ESP - 2;
            SS:ESP = Source; //push word
        }
    }
    else { //StackAddressSize == 16
        if(OperandSize == 16) {
            SP = SP - 2;
            SS:ESP = Source //push word
        }
        else { //OperandSize == 32
            SP = SP - 4;
            SS:ESP = Source; //push doubleword
        }
    }
    

    source: https://c9x.me/x86/html/file_module_x86_id_269.html

    https://c9x.me/x86/ is a great pocket reference for x86 instructions, use it at will!

提交回复
热议问题