I was modifying code that suppose to translate ASCII characters to hexadecimal values. My first version was working perfectly without any problems, however my newer function have some problems.
This is my new function which translates ASCII values to hexadecimal values:
;carry flag cleared if successed, if not then it is set
;input number should be in AL
;output number should be in AH
.translate:
xor AH,AH
mov BX, HEXASCII
.loop:
mov DL,[BX]
cmp DL,AL
je .end
inc BX
inc AH
cmp AH,0x10
je .err
jmp .loop
.end:
clc
ret
.err:
stc
ret
; ... some code
HEXASCII db '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
however this function seems to not work properly - when sending output from this function to int 13
, bochs is returning error - read/write/verify parameter out of range
. the numbers I use was 00 for Head
, 00 for cylinder
, and 01 for sector
, so I guess that it is not an actual problem with arguments which I wrote.
I also used my previous function with the same arguments and it properly loaded sector I wanted to.
I tried to use Bochs debugger to track registers in memory before int 0x13
, however it was looking like the registers have the same values I inputted.
My previous function is:
;carry flag cleared if successed, if not then it is set
;input number should be in AL
;output number should be in AH
.translate:
cmp AL,'0'
je .x0
cmp AL,'1'
je .x1
cmp AL,'2'
je .x2
cmp AL,'3'
je .x3
cmp AL,'4'
je .x4
cmp AL,'5'
je .x5
cmp AL,'6'
je .x6
cmp AL,'7'
je .x7
cmp AL,'8'
je .x8
cmp AL,'9'
je .x9
cmp AL,'a'
je .xA
cmp AL,'b'
je .xB
cmp AL,'c'
je .xC
cmp AL,'d'
je .xD
cmp AL,'e'
je .xE
cmp AL,'f'
je .xF
cmp AL,'A'
je .xA
cmp AL,'B'
je .xB
cmp AL,'C'
je .xC
cmp AL,'D'
je .xD
cmp AL,'E'
je .xE
cmp AL,'F'
je .xF
jmp .NONE
.x0:
xor AH,AH
clc
ret
.x1:
mov AH,0x1
clc
ret
.x2:
mov AH,0x2
clc
ret
.x3:
mov AH,0x3
clc
ret
.x4:
mov AH,0x4
clc
ret
.x5:
mov AH,0x5
clc
ret
.x6:
mov AH,0x6
clc
ret
.x7:
mov AH,0x7
clc
ret
.x8:
mov AH,0x8
clc
ret
.x9:
mov AH,0x9
clc
ret
.xA:
mov AH,0xA
clc
ret
.xB:
mov AH,0xB
clc
ret
.xC:
mov AH,0xC
clc
ret
.xD:
mov AH,0xD
clc
ret
.xE:
mov AH,0xE
clc
ret
.xF:
mov AH,0xF
clc
ret
.NONE:
xor AH,AH
stc
ret
I don't expect any other part of code to be damaged, as I did not modified it. If it is needed I will include the full code, however it is pretty long.
Is there anything which is missing or wrong in the new function?
edit: Forgot to mention that the code is running in 16 bit real mode
After getting some help from osdev forum
someone noticed that the function does translate the values properly, however it is damaging dl
register which I forget to keep the same as it holds hard drive
number.
If someone needs newer version of this code here you go:
.translate:
xor AH,AH
mov BX, HEXASCII
.loop:
cmp [BX],AL
je .end
inc BX
inc AH
cmp AH,0x10
je .err
jmp .loop
.end:
clc
ret
.err:
stc
ret
;... some code
HEXASCII db '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'