📄 debug.asm
字号:
extern print,printc
global hex2ascii4bit,hex2ascii4bit_str,hex2ascii8bit,hex2ascii8bit_str,hex2ascii16bit,hex2ascii16bit_str,hex2ascii32bit,hex2ascii32bit_str,ascii_char2hex,hexascii2bin,ascii_8bytebin2bin,ascii_16bytebin2bin,ascii_32bytebin2bin,decascii2bin,bin2decascii,bin2ascii8bit,bin2ascii16bit,bin2ascii32bit,ascii_qword2hex_dword
section data
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Variables
hex_str db '0x',0
hex_temp dd 0,0
db 0
section code
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 4bit hex to ascii
hex2ascii4bit:
cmp al,0x09
jg .bigger_nine
add al,0x30
jmp short .end
.bigger_nine
add al,0x37
.end
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 4bit hex to ascii and output a string
hex2ascii4bit_str:
push si
push ax
and al,0x0f
call hex2ascii4bit
mov byte[hex_temp],'0'
mov byte[hex_temp+1],al
mov byte[hex_temp+2],0
mov si,hex_str
call print
mov si,hex_temp
call print
pop ax
pop si
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 8bit hex to ascii
hex2ascii8bit:
push bx
mov ah,al
and al,0x0f
call hex2ascii4bit
mov bl,al
mov al,ah
and al,0xf0
shr al,4
call hex2ascii4bit
mov ah,al
mov al,bl
pop bx
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 8bit hex to ascii and output a string
hex2ascii8bit_str:
push si
push ax
call hex2ascii8bit
mov byte[hex_temp],ah
mov byte[hex_temp+1],al
mov byte[hex_temp+2],0
mov si,hex_str
call print
mov si,hex_temp
call print
pop ax
pop si
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 16bit hex to ascii
hex2ascii16bit:
push ax
and ax,0xff00
shr ax,8
call hex2ascii8bit
mov bx,ax
pop ax
and ax,0x00ff
call hex2ascii8bit
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 16bit hex to ascii and output a string
hex2ascii16bit_str:
push si
push ax
push bx
call hex2ascii16bit
mov byte[hex_temp],bh
mov byte[hex_temp+1],bl
mov byte[hex_temp+2],ah
mov byte[hex_temp+3],al
mov byte[hex_temp+4],0
pop bx
mov si,hex_str
call print
mov si,hex_temp
call print
pop ax
pop si
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 32bit hex to ascii
hex2ascii32bit:
push eax
and eax,0xffff0000
shr eax,16
call hex2ascii16bit
mov dx,bx
mov cx,ax
pop eax
and eax,0x0000ffff
call hex2ascii16bit
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; 32bit hex to ascii and output a string
hex2ascii32bit_str:
pusha
call hex2ascii32bit
mov byte[hex_temp],dh
mov byte[hex_temp+1],dl
mov byte[hex_temp+2],ch
mov byte[hex_temp+3],cl
mov byte[hex_temp+4],bh
mov byte[hex_temp+5],bl
mov byte[hex_temp+6],ah
mov byte[hex_temp+7],al
mov byte[hex_temp+8],0
popa
mov si,hex_str
call print
mov si,hex_temp
call print
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Input:
;; SI = pointer to string with ascii hex number , 0-terminated
;; Output:
;; EAX = number
hexascii2bin:
push ebx
push si
xor ebx,ebx
.loop
xor al,al
lodsb
and al,al
jz .end
call ascii_char2hex
cmp al,0xff
je .end_error
shl ebx,4
or ebx,eax
jmp .loop
.end
mov eax,ebx
pop si
pop ebx
ret
.end_error
pop si
pop ebx
stc
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ascii_char2hex:
cmp al,'9'
jg .char
sub al,48
jmp short .end
.char
cmp al,97
jb .char1
sub al,87
jmp short .end
.char1
sub al,55
.end
ret
.end_error
mov al,0xff
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ascii_8bytebin2bin:
push si
push dx
push bx
xor dl, dl
xor bl, bl
.next
inc dl
lodsb
sub al, 30h
mov cl, 8
sub cl, dl
shl al, cl
or bl, al
cmp dl, 8
jne short .next
mov al,bl
pop bx
pop dx
pop si
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ascii_16bytebin2bin:
push si
push dx
push bx
xor dl, dl
xor bx, bx
.next
inc dl
xor ah, ah
lodsb
sub al, 30h
mov cl, 16
sub cl, dl
shl ax, cl
or bx, ax
cmp dl, 16
jne .next
mov ax,bx
pop bx
pop dx
pop si
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ascii_32bytebin2bin:
push si
push edx
push ebx
xor dl,dl
xor ebx,ebx
.next
inc dl
xor ah,ah
lodsb
sub al, 30h
mov cl, 16
sub cl, dl
shl ax, cl
or bx, ax
cmp dl, 32
jne .next
mov eax,ebx
pop bx
pop dx
pop si
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bin2decascii:
pushad
mov ebx,10
xor ecx,ecx
.loop
xor edx,edx
div ebx
add dl,'0'
push dx
inc ecx
and eax,eax
jnz .loop
.loop1
pop dx
mov byte[si],dl
inc si
loop .loop1
.end
popad
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
decascii2bin:
push ebx
push ecx
push edx
push si
mov ecx,10
xor ebx,ebx
xor eax,eax
.loop
xor edx,edx
mov bl,[si]
and bl,bl
jz .end
inc si
sub bl,'0'
mul ecx
add eax,ebx
jmp short .loop
.end
pop si
pop edx
pop ecx
pop ebx
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bin2ascii8bit:
pusha
mov ah, 0x80
.loop
test ah, al
jz .zero
.one
push ax
mov al,'1'
call printc
pop ax
jmp .donedigit
.zero
push ax
mov al,'0'
call printc
pop ax
.donedigit
shr ah, 1
jnc .loop
mov al,'b'
call printc
.end
popa
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bin2ascii16bit:
pusha
mov bx,0x8000
.loop
test bx, ax
jz .zero
.one
push ax
mov al,'1'
call printc
pop ax
jmp .donedigit
.zero
push ax
mov al,'0'
call printc
pop ax
.donedigit
shr bx, 1
jnc .loop
mov al,'b'
call printc
.end
popa
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bin2ascii32bit:
pushad
mov ebx,0x80000000
.loop
test ebx,eax
jz .zero
.one
push eax
mov al,'1'
call printc
pop eax
jmp .donedigit
.zero
push eax
mov al,'0'
call printc
pop eax
.donedigit
shr ebx, 1
jnc .loop
mov al,'b'
call printc
.end
popad
ret
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -