我有這樣的彙編代碼(linux下的80x86 NASM),其假定爲十六進制數轉換爲十進制:的彙編代碼不工作
my_func:
push ebp
mov ebp, esp ; Entry code - set up ebp and esp
pusha ; Save registers
mov dword[LC1],0
mov ecx,dword[ebp+8] ; Get argument (pointer to string)
start_loop:
mov ebx,0 ;zero ebx register
mov eax,16
mov edx,0
mov bl, byte[ecx] ;bl is the curr number
jmp bl_to_num ;change it to be a number
continue:
add dword[LC1], ebx ;dword[LC1] = dword[LC1]+ebx
inc ecx
cmp byte[ecx],0
je end_func
mul dword[LC1] ;dword[LC1]*eax = edx:eax
mov dword[LC1],eax
jmp start_loop
DWORD [LC1]是我回的論點C函數,而ecx是一個指向接收到的字符串的指針。 功能:bl_to_num只是BL字節轉換成一個數字(A = 10,B = 11 ..) 當運行該代碼與輸入1,I接收輸出234 當運行該代碼與輸入2 ,我收到輸出250. 等等.. 我的錯誤在哪裏? 謝謝!
編輯: 這是bl_to_num:
bl_to_num:
cmp bl,'A'
je con_a
cmp bl,'a'
je con_a
cmp bl,'B'
je con_b
cmp bl,'b'
je con_b
cmp bl,'C'
je con_c
cmp bl,'c'
je con_c
cmp bl,'D'
je con_d
cmp bl,'d'
je con_d
cmp bl,'E'
je con_e
cmp bl,'e'
je con_e
cmp bl,'F'
je con_f
cmp bl,'f'
je con_f
sub bl,48
jmp continue
con_a:
mov bl,10
jmp continue
con_b:
mov bl,11
jmp continue
con_c:
mov bl,12
jmp continue
con_d:
mov bl,13
jmp continue
con_e:
mov bl,14
jmp continue
con_f:
mov bl,15
jmp continue
其中是'bl_to_num'?當你說「十六進制到十進制」時,你的意思是浮點數(IEE754數)的小數?和BCD一樣?一個有符號整數?十六進制輸入是否應該是UINT? – 2013-04-23 11:09:16
當我說十六進制到十進制,我的意思是我收到一個字符串包含(最多8位數字)1-9,a-f – Javi 2013-04-23 11:13:16
...並且您還將它轉換爲(0-9)小數基數的字符串? – 2013-04-23 11:13:53