Slide 10.3: PUSH and POP instructions
Slide 10.5: Defining and using procedures
Home

Other Push and Pop Instructions


PUSHFD and POPFD Instructions
The PUSHFD pushes the 32-bit EFLAGS register on the stack, and POPFD pops the stack into EFLAGS.

PUSHAD and POPAD Instructions
The PUSHAD instruction pushes all of the 32-bit general-purpose registers on the stack in the following order: EAX, ECX, EDX, EBX, ESP (value before executing PUSHAD), EBP, ESI, and EDI. The POPAD instruction pops the same registers off the stack in reverse order.

 Checking Balanced Parentheses of ( and ) 
 INCLUDE Irvine32.inc
 .data
 expr     BYTE  64 DUP(0)      ;; Only characters ‘(’ and ‘)’ allowed
 depth    WORD  0
 prompt1  BYTE  "Correct", 0
 prompt2  BYTE  "Incorrect", 0

 .code
 main PROC
      call  Clrscr
      mov   edx, OFFSET expr
      mov   ecx, (SIZEOF expr) - 1
      call  ReadString
      mov   esi, OFFSET expr
      mov   ecx, eax

 L1:  cmp   BYTE PTR [esi], '('
      jne   L2    
         
push eax call increment jmp L3 L2: cmp depth, 0 je ERR pop eax cmp al, BYTE PTR [esi] jne ERR dec depth L3: inc esi loop L1 cmp depth, 0 jne ERR mov edx, OFFSET prompt1 call WriteString jmp L4 ERR: mov edx, OFFSET prompt2 call WriteString L4: exit main ENDP increment PROC ; This procedure is not really required. pushad ; It is used to demonstrate the use of mov cx, depth ; PUSHAD and POPAD. inc cx mov depth, cx popad ret increment ENDP END main