【发布时间】:2014-12-02 14:08:21
【问题描述】:
我在汇编编程方面很痛苦,并寻求您的帮助。我不明白的是,即使缓冲区有足够的空间,为什么我会从缓冲区中丢失字符串的字符?
我的 readBuffer 大小是 32,writeBuffer 大小是 64,我的程序所做的是在句号后添加一个空格并将第一个字母大写。
示例:
Good.morning.people hehehe in the jungle the mighty jungle //this is the data
Good. Morning. People hehehe in the jungle the mighty jungle //this is the output
我的程序做什么:
Good.morning.people hehehe in the jungle the mighty jungle //this is the data
Good. Morning. People hehehe in e jungle the mighty jungle //this is the output
如你所见,我以 'e' 而不是 'the' 结尾
这是我进行编辑的代码:
Read:
MOV bx, DataHandle
CALL ReadBuffer
CMP ax, 0 ;ax = how many symbols did I read
JE closeWrite ;if 0 then close write file
;Editing the string
MOV cx, ax ;CX FOR LOOPING
MOV si, offset rBuff ;read buffer = si
MOV di, offset wBuff ;write buffer = di
Do_It:
MOV dl, [si]
CMP dl, '.' ;comparing to period
JNE Keep_Going ;if not period put it in di (write buffer)
MOV dh, [si+1] ;put the char after the period in dh
CMP dh, ' ' ;check if space is after it
JNE If_capital ;if not I check if it is a capital letter
MOV dh, [si+2] ;if there was a space I add the char after the space
CMP dh, 'a' ;checking if it is a capital letter
JB Keep_Going
CMP dh, 'z'
JA Keep_Going
SUB byte ptr [si+2], 32 ;turn it into a capital letter
Keep_Going:
MOV [di], dl ;put the char into writebuff
INC si
INC di
LOOP Do_It
JMP Finishin
If_capital:
CMP dh, 'a'
JB Add_Space
CMP dh, 'z'
JA Add_Space
SUB byte ptr [si+1], 32
Add_Space:
MOV [di], '.'
INC di
MOV [di], ' '
INC di
INC si
JMP Do_It
;Write the result
Finishin:
MOV cx, ax
CALL checkOnScreen ;print it to command line
MOV bx, WriteHandle
CALL writeBuffer ;print it
CMP ax, rBuffSize ;compare the size to 32
JE Read ;if it was 32 then read again
【问题讨论】:
-
会不会只是你的输出函数搞砸了?据我所知,您正在将原始长度传递给它。
-
在调试器中逐行通过您的代码
标签: string assembly char output x86-16