Learn Win32 compilation [21]-delivery instructions: MOV, LEA, XCHG, XLATB, XLAT, MOVZX, MOVSX

Source: Internet
Author: User

General requirements for assembly directives: 1, two operands must be of the same size; 2, the operand cannot be the same as memory.

MOV (Move): Most commonly used data transfer instructions

This directive does not affect eflags; instruction format: (where r, M, I are respectively: register, memory, immediate number)MOV r/m, r/m/i
; Test21_1.asm.386.Model Flat,stdcallinclude   Windows.incinclude   Kernel32.incinclude   Masm32.incinclude   Debug.incIncludelibKernel32.libIncludelibMasm32.libIncludelibDebug.lib.Data? ValDD?.CodeMainprocmovVal123mov edx, Valmov eax,edxPrintdeceax; 123 retMainENDPEndMain


LEA (Load effective address): Valid addresses delivery instructions

; This directive does not affect eflags; instruction format:LEA R, M
; Test21_2.asm.386.Model Flat,stdcallinclude   Windows.incinclude   Kernel32.incinclude   Masm32.incinclude   Debug.incIncludelibKernel32.libIncludelibMasm32.libIncludelibDebug.lib.DataSztextDB ' ABCDEFG ',0.CodeMainprocLea eax,OffsetSztextLea ebx, Sztext Printhexeax; 00403000Printhexebx; 00403000retMainENDPEndMain


XCHG (Exchange): Exchange directives

; This directive does not affect eflags; instruction format:XCHG r/m, r/m
; Test21_3.asm.386.Model Flat,stdcallinclude   Windows.incinclude   Kernel32.incinclude   Masm32.incinclude   Debug.incIncludelibKernel32.libIncludelibMasm32.libIncludelibDebug.lib.DataVal1DD 111Val2DD 222.CodeMainprocmov eax, Val1Xchg eax, Val2movVal1,eaxPrintdec Val1; 222Printdec Val2; 111retMainENDPEndMain


XLATB (Translate Byte), XLAT (Translate): Code change instruction

; XLATB XLAT ; The directive does not affect EFlags ; XLAT no parameters, operation and EBX, AL related ; before executing XLAT, first put the source address into the EBX, the byte sequence number into Al; After execution, the specified byte is read into Al
; Test21_4.asm.386.Model Flat,stdcallinclude   Windows.incinclude   Kernel32.incinclude   Masm32.incinclude   Debug.incIncludelibKernel32.libIncludelibMasm32.libIncludelibDebug.lib.DataSztextDB ' ABCDEFG ',0.CodeMainprocLea ebx, Sztextmov Al,1XlatPrinthexAl; 42-This is the assii code for ' B 'mov Al,2XLATBPrinthexAl; 43-This is the ' C ' assii code retMainENDPEndMain


MOVZX (Move with Zero-extend): 0 Extended transfer

; This directive does not affect eflags; instruction format:movzx R32, r16/m16movzx R16, R8/M8
; Example with MOVSX


MOVSX (Move with sign-extend): Symbol extension transfer

; This directive does not affect eflags; instruction format:movzx R32, r16/m16movzx R16, R8/M8; The difference between MOVZX and MOVSX is:1, MOVZX will be the target register higher than the bit 0,2, if the highest bit of the source operand is 1, MOVSX will be higher in the target register the bit 1; Reverse 0
; Test21_5.asm.386.Model Flat,stdcallinclude   Windows.incinclude   Kernel32.incinclude   Masm32.incinclude   Debug.incIncludelibKernel32.libIncludelibMasm32.libIncludelibDebug.lib.DataBValDB 90hDwVal1DW 7FFFhDwVal2DW 8000h.CodeMainprocMOVZX eax, DwVal1MOVSX edx, DwVal1 Printhexeax; 00007FFFPrinthexedx; 00007FFFMOVZX eax, DwVal2MOVSX edx, DwVal2 Printhexeax; 00008000Printhexedx ; FFFF8000mov CL, BValMOVZX Ax,CLMOVSX DX,CLPrinthexAx ; 0090PrinthexDX  ; FF90retMainENDPEndMain

Learn Win32 compilation [21]-delivery instructions: MOV, LEA, XCHG, XLATB, XLAT, MOVZX, MOVSX

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.