0 Replies - 1491 Views - Last Post: 23 December 2006 - 09:49 PM

#1 born2c0de   User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 187
  • View blog
  • Posts: 4,673
  • Joined: 26-November 04

Pushing All Registers on the Stack Using One Instruction

Posted 23 December 2006 - 09:49 PM

Description: Demonstrates how we can save coding time, improve speed and reduce size of a program by using a single byte instruction that does the job.
; I've noticed that whenever we need to push all/most
; of the registers on the stack, almost everybody uses
; this construct

push eax
push ecx
push edx
push ebx
push esi
push edi

; function calls ... code ...

pop edi
pop esi
pop ebx
pop edx
pop ecx
pop eax

; This takes up 6 bytes. Later the programmer uses
; the pop instruction in reverse order so that makes
; it a total of 12 bytes.

; Instead we can use the PUSHA/POPA set of instructions
; which take only 1 byte each and they push/pop all the
; registers including the Stack Pointer and
; Base Pointer Registers in the following order:
;EAX, ECX, EDX, EBX, original ESP, EBP, ESI, and EDI
;(popa instr will do it in reverse)

; So the equivalent of the code above would be a simple

pusha ; 1 byte
popa  ; 1 byte

; Many people still do not know that these two
; instructions exist. I encourage them to use these
; instructions for a more efficient and readable code.


Is This A Good Question/Topic? 0
  • +

Page 1 of 1