我正在尝试读取具有此类行
的文件201; 18,5; 2500; 35(4个信息,第二个是浮点数,其他是整数)
我想将这些数字转换为十进制(与之一起操作)。我不会使用8086浮点功能,例如“18,5”,我会将18乘以1000加5倍100,并将它们加在一个数字中(不会达到64k)。
我知道逻辑,但我不知道该怎么做。
我需要阅读,直到我得到“;”或“,”或“CR”(CRLF标记线条)
这是我到目前为止所拥有的
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
你能帮助我吗?感谢
答案 0 :(得分:2)
mov String[si], FileBuffer ;THIS IS GETTING ME AN ERROR
这是MASM!
当MASM 看到第二个操作数(FileBuffer
)时,它会将其视为内存操作数。
但第一个操作数(String[si]
)也是一个内存操作数。
在同一条指令中不能有2个这样的内存操作数,因此出现错误信息。
我没有遵循其余的代码(有点长而没有急需的评论),但接下来的2个解决方案可能会为你完成这项工作。
将第二个操作数转为立即数:
mov String[si], offset FileBuffer
分别阅读和写作:
mov al, FileBuffer
mov String[si], al