在 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
byt2bin_ex: 從 Byte 數到二進制字符串
; Test19_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
szBin db 8 dup(0), 0 ;這是接收二進制字符串的緩沖區, 需分配好空間
bVal db 3
.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
ret
main endp
end main
wrd2bin_ex: 從 Word 數到二進制字符串
; Test19_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
szBin db 16 dup(0), 0 ;這是接收二進制字符串的緩沖區, 需分配好空間
dwVal dw 3
.code
main proc
;查看數字的二進制信息
invoke wrd2bin_ex, 2, addr szBin
PrintString szBin ;0000000000000010
;查看變量 dwVal 的二進制信息
invoke wrd2bin_ex, dwVal, addr szBin
PrintString szBin ;0000000000000011
;查看寄存器 ax 的二進制信息
mov ax, 0fffeh
invoke wrd2bin_ex, ax, addr szBin
PrintString szBin ;1111111111111110
ret
main endp
end main
dw2bin_ex: 從 DWord 數到二進制字符串
; Test19_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
szBin db 32 dup(0), 0 ;這是接收二進制字符串的緩沖區, 需分配好空間
ddVal dd 3
.code
main proc
;查看數字的二進制信息
invoke dw2bin_ex, 2, addr szBin
PrintString szBin ;00000000000000000000000000000010
;查看變量 ddVal 的二進制信息
invoke dw2bin_ex, ddVal, addr szBin
PrintString szBin ;00000000000000000000000000000011
;查看寄存器 eax 的二進制信息
mov eax, 0fffffffeh
invoke dw2bin_ex, eax, addr szBin
PrintString szBin ;11111111111111111111111111111110
ret
main endp
end main
dw2hex_ex: 從 DWord 數到十六進制字符串
; Test19_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
szHex db 8 dup(0), 0 ;這是接收十六進制字符串的緩沖區, 需分配好空間
ddVal dd 255
.code
main proc
;查看數字的十六進制信息
invoke dw2hex_ex, 16, addr szHex
PrintString szHex ;00000010
;查看變量 ddVal 的十六進制信息
invoke dw2hex_ex, ddVal, addr szHex
PrintString szHex ;000000FF
;查看寄存器 eax 的十六進制信息
mov eax, 2694881440
invoke dw2hex_ex, eax, addr szHex
PrintString szHex ;A0A0A0A0
ret
main endp
end main