In the assembly if the assembly and call API mix, pay attention to Pushad Popad

Source: Internet
Author: User

A group of people raised a strange problem, the loop of this code is not normal

; Masmplus code Templates-Console programs

.386
. Model Flat, StdCall
Option Casemap:none

Include Windows.inc
Include User32.inc
Include Kernel32.inc
Include Masm32.inc
Include Gdi32.inc

Includelib Gdi32.lib
Includelib User32.lib
Includelib Kernel32.lib
Includelib Masm32.lib
Include Macro.asm
. Data
Lpmsg db "Hello world!", 0

. Data?
Buffer db Max_path dup (?)

. CODE
START:

MOV ecx,5
@@:

Invoke Messageboxa,null,ctext (""), Ctext ("" "), MB_OK

Loop @B

Invoke exitprocess,0

End START

The reason loop equals ECX-1, and then look at ecx==0, if not loop, if not equal to the loop, but this ecx is not 5

Adding Pushad Popad before and after calling the API is normal.

;masmplus Code Templates-Console programs.386. Model flat, Stdcalloption casemap:noneinclude windows.Incinclude User32.Incinclude KERNEL32.Incinclude Masm32.Incinclude GDI32.Incincludelib gdi32.libincludelib user32.libincludelib kernel32.libincludelib masm32.libinclude macro.asm.data LPMSG DB"Hello world!",0. Data?    Buffer db Max_path dup (?) . CODESTART:       movEcx5@@:   PushadInvoke Messageboxa,null,ctext (" -"), Ctext (" -"), MB_OKPopadLoop @B invoke ExitProcess,0End START

In the assembly if the assembly and call API mix, pay attention to Pushad Popad

Large-Scale Price Reduction
  • 59% Max. and 23% Avg.
  • Price Reduction for Core Products
  • Price Reduction in Multiple Regions
undefined. /
Connect with us on Discord
  • Secure, anonymous group chat without disturbance
  • Stay updated on campaigns, new products, and more
  • Support for all your questions
undefined. /
Free Tier
  • Start free from ECS to Big Data
  • Get Started in 3 Simple Steps
  • Try ECS t5 1C1G
undefined. /

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.