我试图弄清楚如何将十六进制数转换为二进制补码十六进制。我已经对该字符作为十六进制数字进行了所有必要的检查,并将其转换为ASCII代码的数字代码,但是当我尝试打印转换后的Tow的补码时,它给我带来了意外的结果,我觉得我在此代码中缺少了一些内容。有人可以帮忙谢谢你吗?
INCLUDE Irvine32.inc
.data
var1 db "A",0
var2 db "error",0
char1 db ?
.code
main PROC
mov edx,OFFSET var1 ; get starting address of string
L1:
mov al,BYTE PTR [edx] ; get next character
inc edx ; increment pointer
test al,al ; test value in AL and set flags
jz Finished ; AL == 0,so exit the loop
; Otherwise,AL != 0,so we fell through.
; Here,you can do something with the character in AL.
; ...
cmp al,30h ; compare it with 30H - ASCII CODE OF 0
jb error ; if charater is below 30H - then error
cmp al,39H ; compare it with 39H - ASCII code of 9
ja Big ; if charater is above 30H
; check for A-F
jmp comp ; otherwise,go for Conversion of ASCII code
Big:
cmp al,41H ; compare al with 41H - ASCII code of A
jb error ; if code is below 41h,then error
cmp al,46H ; compare al with 46H - ASCII code of F
ja Small ; if code is above 46h,check for A-F
jmp comp ; otherwise,go for Conversion of ASCII code
; to numric value
Small:
cmp al,61H ; compare al with 46H - ASCII code of a
jb error ; if code is below 61H,66H ; compare al with 46H - ASCII code of f
ja error ; if code is above 66h,then error
comp:
sub al,30H ; subtract 30H - numeric code
cmp al,09H ; compare if al is in range of 0-9
jbe next ; then jump to next to store back to Hex Array
sub al,07H ; otherwise,for A-F,7H has to be subtracted
cmp al,0FH ; compare the value is in range of A-F
jbe next ; then jump to next to store back to Hex Array
sub al,20H ; otherwise for a-f,subtract additional 20H
next:
not al ; get 1's complement
add al,00000001b ; add 1 to get 2't complement
mov char1,al
jmp L1
error:
mov edx,OFFSET var2 ; display error massage
call writestring
Finished:
mov edx,OFFSET char1
call writestring
exit
main ENDP
END main