在 masm32.inc 中有这样几个函数的声明:
byt2bin_ex PROTO :BYTE, :DWORD
wrd2bin_ex PROTO :WORD, :DWORD
dw2bin_ex PROTO :DWORD, :DWORD
dw2hex_ex PROTO :DWORD, :DWORD
bin2byte_ex PROTO :DWORD
--------------------------------------------------------------------------------------------------------------
.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
szBin db 8 dup(0), 0 ;这是接收二进制字符串的缓冲区
bVal db 3
wVal dw 3
szHex db 8 dup(0), 0 ;这是接收十六进制字符串的缓冲区
dwVal dd 255
szTxt1 db '00000010', 0
szTxt2 db '01111011', 0
szTxt3 db '11111111', 0
.code
main proc
;------------------------------------------------------------------------------------------------
;查看数字的二进制信息
invoke byt2bin_ex, 2, addr szBin
PrintString szBin ;00000010
;查看变量 bVal 的二进制信息
invoke byt2bin_ex, bVal, addr szBin
PrintString szBin ;00000011
;查看寄存器 al 的二进制信息
mov al, 0feh
invoke byt2bin_ex, al, addr szBin
PrintString szBin ;11111110
PrintLine
;------------------------------------------------------------------------------------------------
;查看数字的二进制信息
invoke wrd2bin_ex, 2, addr szBin
PrintString szBin ;0000000000000010
;查看变量 wVal 的二进制信息
invoke wrd2bin_ex, wVal, addr szBin
PrintString szBin ;0000000000000011
;查看寄存器 ax 的二进制信息
mov ax, 0fffeh
invoke wrd2bin_ex, ax, addr szBin
PrintString szBin ;1111111111111110
PrintLine
;------------------------------------------------------------------------------------------------
;查看数字的十六进制信息
invoke dw2hex_ex, 16, addr szHex
PrintString szHex ;00000010
;查看变量 dwVal 的十六进制信息
invoke dw2hex_ex, dwVal, addr szHex
PrintString szHex ;000000FF
;查看寄存器 eax 的十六进制信息
mov eax, 2694881440
invoke dw2hex_ex, eax, addr szHex
PrintString szHex ;A0A0A0A0
;------------------------------------------------------------------------------------------------
invoke bin2byte_ex, addr szTxt1
PrintDec eax ;2
invoke bin2byte_ex, addr szTxt2
PrintDec eax ;123
invoke bin2byte_ex, addr szTxt3
PrintDec eax ;255
PrintLine
;------------------------------------------------------------------------------------------------
lahf ;LAHF 指令是把 EFLAGS 寄存器的低字节读入 AH
invoke byt2bin_ex, ah, addr szBin
PrintString szBin ;01000110-----EFlage的低8位
ret
main endp
end main
-------------------------------------------------------------------------------------------------------------------------------------------------
szBin = 00000010 (Test.asm, 28)
szBin = 00000011 (Test.asm, 32)
szBin = 11111110 (Test.asm, 37)
----------------------------------------
szBin = 0000000000000010 (Test.asm, 42)
szBin = 0011000000110000 (Test.asm, 46)
szBin = 1111111111111110 (Test.asm, 51)
----------------------------------------
szHex = 00000010 (Test.asm, 56)
szHex = 000000FF (Test.asm, 60)
szHex = A0A0A0A0 (Test.asm, 65)
eax = 2 (Test.asm, 68)
eax = 123 (Test.asm, 71)
eax = 255 (Test.asm, 74)
----------------------------------------
szBin = 00000110 (Test.asm, 79)
所以大家以后多看看头文件 给我们提供了哪些比较方便的东东哦