汇编指令的一般性要求: 1、两个操作数的尺寸必须一致; 2、操作数不能同为内存.
MOV(Move): 最常用的数据传送指令
;该指令不影响 EFlags ;指令格式: (其中的 r、m、i 分别表示: 寄存器、内存、立即数) MOV r/m, r/m/i
; Test21_1.asm .386 .model flat, stdcall include windows.inc include kernel32.inc include masm32.inc include debug.inc includelib kernel32.lib includelib masm32.lib includelib debug.lib .data? val dd ? .code main proc mov val, 123 mov edx, val mov eax, edx PrintDec eax ;123 ret main endp end main
LEA(Load Effective Address): 有效地址传送指令
;该指令不影响 EFlags ;指令格式: LEA r, m
; Test21_2.asm .386 .model flat, stdcall include windows.inc include kernel32.inc include masm32.inc include debug.inc includelib kernel32.lib includelib masm32.lib includelib debug.lib .data szText db ‘ABCDEFG‘, 0 .code main proc lea eax, offset szText lea ebx, szText PrintHex eax ;00403000 PrintHex ebx ;00403000 ret main endp end main
XCHG(Exchange): 交换指令
;该指令不影响 EFlags ;指令格式: XCHG r/m, r/m
; Test21_3.asm .386 .model flat, stdcall include windows.inc include kernel32.inc include masm32.inc include debug.inc includelib kernel32.lib includelib masm32.lib includelib debug.lib .data val1 dd 111 val2 dd 222 .code main proc mov eax, val1 xchg eax, val2 mov val1, eax PrintDec val1 ;222 PrintDec val2 ;111 ret main endp end main
XLATB(Translate Byte)、XLAT(Translate): 换码指令
;XLATB 可简化为 XLAT ;该指令不影响 EFlags ;XLAT 无参数, 操作和 EBX、AL 相关 ;执行 XLAT 前, 先把源地址放入 EBX, 把字节序号放入 AL ;执行后, 指定字节被读入 AL
; Test21_4.asm .386 .model flat, stdcall include windows.inc include kernel32.inc include masm32.inc include debug.inc includelib kernel32.lib includelib masm32.lib includelib debug.lib .data szText db ‘ABCDEFG‘, 0 .code main proc lea ebx, szText mov al, 1 xlat PrintHex al ;42 - 这是 ‘B‘ 的 ASSII 编码 mov al, 2 xlatb PrintHex al ;43 - 这是 ‘C‘ 的 ASSII 编码 ret main endp end main
MOVZX(Move With Zero-Extend): 零扩展传送
;该指令不影响 EFlags ;指令格式: MOVZX r32, r16/m16 MOVZX r16, r8/m8
;示例同 MOVSX
MOVSX(Move With Sign-Extend): 符号扩展传送
;该指令不影响 EFlags ;指令格式: MOVZX r32, r16/m16 MOVZX r16, r8/m8 ;MOVZX 和 MOVSX 的区别是: ;1、MOVZX 会将目标寄存器中高出的位补 0 ;2、如果源操作数的最高位是 1, MOVSX 会将目标寄存器中高出的位补 1; 反之补 0
; Test21_5.asm .386 .model flat, stdcall include windows.inc include kernel32.inc include masm32.inc include debug.inc includelib kernel32.lib includelib masm32.lib includelib debug.lib .data bVal db 90h dwVal1 dw 7FFFh dwVal2 dw 8000h .code main proc movzx eax, dwVal1 movsx edx, dwVal1 PrintHex eax ;00007FFF PrintHex edx ;00007FFF movzx eax, dwVal2 movsx edx, dwVal2 PrintHex eax ;00008000 PrintHex edx ;FFFF8000 mov cl, bVal movzx ax, cl movsx dx, cl PrintHex ax ;0090 PrintHex dx ;FF90 ret main endp end main
时间: 2024-10-19 04:36:29