Reputation: 45
I am trying to read a file that has lines like this
201;18,5;2500;35 (4 information, the second one is a float, the others are ints)
And I want to convert these numbers to decimal (to operate with). I wont use the 8086 float capabilities, for example "18,5" , I will multiply 18 by 1000 plus 5 times 100, and the sum them in one number (won't reach 64k).
I know the logics, but I don't know how to do it.
I need to read until I get ";" or "," or "CR" (CRLF marks the lines)
Here's what I have so far
atoi proc near
mov ax,0
atoi_2:
cmp byte ptr[bx], 0
jz atoi_1
mov cx,10
mul cx
mov ch,0
mov cl,[bx]
add ax,cx
sub ax,'0'
inc bx
jmp atoi_2
atoi_1:
ret
atoi endp
read_char_convert proc near
put_on_string: ;To convert using atoi
cmp FileBuffer, AscSemiColon ; is it ";"?
je column_count
cmp FileBuffer, AscComma ; Is it ","?
je fechar_string_comma
cmp FileBuffer, CR ; Is it "CR"?
je close_string_CR
;I CANT DO THIS
;add String, i
;mov String, FileBuffer
;inc i
mov si, i
mov String[si], FileBuffer ;THIS IS GETTING ME AN ERROR
inc i
close_string_comma:
columnCount:
call columnCounter
fechar_string_CR:
mov SemiColonCounter, 0 ; going to the next line
read_char_convert endp
columnCounter proc near
inc i
mov si, i
mov String[si], 0
inc SemiColonCounter
cmp SemiColonCounter, 1
je chamaConversaoTempo
cmp SemiColonCounter, 2
je chamaConversaoBateria
cmp SemiColonCounter, 3
je chamaConversaoDistancia
cmp SemiColonCounter, 4
je chamaConversaoVelocidade
callTimeConversion:
call speedConversion
jmp return_columnCounter
callBatteryConversion:
call batteryConversion
jmp return_columnCounter
callDistanceConversion:
call distanceConversion
jmp return_columnCounter
callSpeedConversion:
call speedConversion
;jmp return_columnCounter
retourn_columnCounter:
ret
columnCounter endp
timeConversion proc near
lea bx, String
call atoi
mov T_PARCIAL1, ax
cmp nbr_lines, 1
jne returnTime
mov bx, T_INICIAL
mov T_PARCIAL1, bx
returnTime:
ret
timeConversion endp
batteryConversion proc near
lea bx, String
call atoi
;cmp b_int, 1 ; flag -> 1 int part, 0, decimal part
jne mult_100
mov ax, THOUSAND ;constant
mul ax
mov B_PARCIAL1, ax
jmp jump_100
mult_100:
mov ax, HUNDRED
mul ax
add B_PARCIAL1, ax
jump_100:
cmp nbr_lines, 1
jne returnBattery
mov bx, B_INICIAL
mov B_PARCIAL1, bx
returnBattery:
ret
batteryConversion endp
distanceConversion proc near
lea bx, String
call atoi
mov D_PARCIAL1, ax
cmp nbr_lines, 1
jne returnDistance
mov bx, D_INICIAL
mov D_PARCIAL1, bx
returnDistance:
ret
distanceConversion endp
speedConversion proc near
lea bx, String
call atoi
mov V_PARCIAL1, ax
cmp nbr_lines, 1
jne returnSpeed
mov bx, V_INICIAL
mov V_PARCIAL1, bx
returnSpeed:
ret
speedConversion endp
Can you guys help me out? Thanks
Upvotes: 2
Views: 100
Reputation: 9899
mov String[si], FileBuffer ;THIS IS GETTING ME AN ERROR
This is MASM!
When MASM sees the second operand (FileBuffer
) it will treat it as a memory operand.
But the first operand (String[si]
) is a memory operand too.
You can't have 2 memory operands like this in the same instruction, hence the error message.
I didn't follow the rest of the code (a bit long and without the desperately needed comments) but next 2 solutions might do the job for you.
Turn the second operand into an immediate:
mov String[si], offset FileBuffer
Read and write in separate steps:
mov al, FileBuffer
mov String[si], al
Upvotes: 2