我目前编程大会转换为十六进制字符为8086内装配
当前的任务,我做的是将4个十六进制数字到它的十进制表示。我已经试过遵循我的导师方法,但我很困惑,在我必须将一个临时值乘以十六进制数字的部分,特别是因为我被告知要使它为0,所以每当临时值被乘以它总是会是0对吗?
我到目前为止的代码如下,任何帮助真的很感激!
; ------------------------------------
; Name : Gethex
; Function: converts a word (4 hex digits) into a numerical value
; Inputs : Upto a word hex values input into the console
; Outputs : Return within DX the numerical conversion
; ------------------------------------
Gethex:
MOV BX,0H ;Temp value to 0
MOV CX,0H ;Counter set to 0
Gethexloop:
call Getch
push DX ; Putch requires DL, need to save current reg
MOV DL,AL
call Putch
pop DX ; restore DL reg
MOV BH,AH ;Use BH as temp storage as AH will be corrupted
cmp AL,30H ; ASCII 0
JL Gethexloop ; If less than 0 jump to the start as not an Alphabetical char
cmp AL,39H ; ASCII 9
JLE Nums ; If less or equal to 9 then it will be a number
cmp AL,46H
JLE Case ; Start the conversion procedure
Case:
SUB AL,10
jmp Convert
Nums:
SUB AL,30 ; Convert to normal number
Convert:
push AX ; Prepare to multiply
MOV AX,BX
mul BX
POP AX
ADD AX,BX
ADD DX,AX ; final value
ADD CX,1 ; Increase counter
cmp CX,3 ; if greater than 4 (0 being included so 3)
JG EndLoop
jmp Gethexloop
EndLoop:
ret ; return to calling statement
要求人们发现代码中的错误并不是特别有效。您应该使用调试器来分析问题,追踪程序的进度,并将其与预期发生的情况进行比较。只要两者发生分歧,那么你就发现了你的问题。 (然后如果有必要,你应该构造一个[最小测试用例](http://sscce.org)。) – 2013-04-08 22:42:22