程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> 學 Win32 匯編[25] - 符號擴展指令: CBW、CWDE、CDQ、CWD

學 Win32 匯編[25] - 符號擴展指令: CBW、CWDE、CDQ、CWD

編輯:Delphi

CBW、CWDE、CDQ、CWD: 擴展指令

;CBW(Convert Byte to Word):         將 AL 擴展為 AX 
;CWDE(Convert Word to Extended Double): 將 AX 擴展為 EAX 
;CDQ(Convert Doubleword to QuadWord):  將 EAX 擴展為 64 位數 EDX:EAX 
;CWD(Convert Word to DoubleWord):    將 AX 擴展為 DX:AX 
 
;它們都是用符號位填充多出的空間 
 
;它們對 EFLAGS 無影響, 也無參數 
 
 
; Test25_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 
 
.code 
main proc 
  ;CBW 
   mov al, 7Fh 
   cbw 
   PrintHex ax ;007F 
   
   mov al, 80h 
   cbw 
   PrintHex ax ;FF80 
   
  ;CWDE 
   mov ax, 7FFFh 
   cwde 
   PrintHex eax ;00007FFF 
   
   mov ax, 8000h 
   cwde 
   PrintHex eax ;FFFF8000 
   
  ;CDQ 
   mov eax, 7FFFFFFFh 
   cdq 
   PrintHex edx ;00000000 
   PrintHex eax ;7FFFFFFF 
   
   mov eax, 80000000h 
   cdq 
   PrintHex edx ;FFFFFFFF 
   PrintHex eax ;80000000 
   
  ;CWD 
   mov ax, 7FFFh 
   cwd 
   PrintHex dx ;0000 
   PrintHex ax ;7FFF 
   
   mov ax, 8000h 
   cwd 
   PrintHex dx ;FFFF 
   PrintHex ax ;8000 
   ret 
main endp 
end main 

  符號擴展指令的本質

;一個正數(無符號)或負數(有符號)在擴展儲存空間時, 使用這些指令可保證原值不變 
 
; Test25_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 
 
.code 
main proc 
   mov al, 68 
   cbw 
   PrintHex ax ;0044 
   PrintDec ax ;68 
   
   mov al, -68 
   cbw 
   PrintHex ax ;FFBC 
   PrintDec ax ;-68 
   ret 
main endp 
end main 

  CBW、CWDE 和 MOVSX 的關系

; Test25_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 
 
.code 
main proc 
  ;CBW 等價於 movsx ax, al 
   mov al, 80h 
   cbw 
   PrintHex ax ;FF80 
   
   mov al, 80h 
   movsx ax, al 
   PrintHex ax ;FF80 
   
  ;CWDE 等價於 movsx eax, ax 
   mov ax, 8000h 
   cwde 
   PrintHex eax ;FFFF8000 
   
   mov ax, 8000h 
   movsx eax, ax 
   PrintHex eax ;FFFF8000 
   ret 
main endp 
end main 


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved