Other Push and Pop Instructions


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

PUSHAD and POPAD Instructions
The instruction pushes all of the 32-bit general-purpose registers on the stack in the following order: , , , , (value before executing ), , , and . The 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
An Execution Example
  (()(())) 
Correct
The italic white text with navy background is entered by users.





      “I’m not arguing, I’m just explaining why I’m right.”    
      ― Unknown