Assembly 缓冲区上的TASM重复字节
我找不到我算法中的漏洞。基本上我希望get_字节能够处理一件事情,当整个缓冲区被分析时,新的缓冲区将被加载。例如,如果我将缓冲区长度设置为3,并调用get_byte 5次,则得到输出12245,文件内容为123456789。。。。。例如,如果我将缓冲区大小增加到5 9以上,则输出为12345。请帮我找出发生这种情况的原因。非常感谢。代码如下Assembly 缓冲区上的TASM重复字节,assembly,x86,tasm,procedures,Assembly,X86,Tasm,Procedures,我找不到我算法中的漏洞。基本上我希望get_字节能够处理一件事情,当整个缓冲区被分析时,新的缓冲区将被加载。例如,如果我将缓冲区长度设置为3,并调用get_byte 5次,则得到输出12245,文件内容为123456789。。。。。例如,如果我将缓冲区大小增加到5 9以上,则输出为12345。请帮我找出发生这种情况的原因。非常感谢。代码如下 proc get_byte mov ah, read_buffer_length ; ah = read_buffer_length cmp r
proc get_byte
mov ah, read_buffer_length ; ah = read_buffer_length
cmp read_position, ah ; comparing current position and ah
jl @@less ; if read_position < read_buffer_length, then we jump to @@less part
@@read_input_buffer:
call read_input_buffer
; if we have read 0 bytes, we are done
cmp read_buffer_length, 0
je @@done
; if not, we renew buffer information
mov read_position, 1 ; setting position to 1
mov si, offset read_buffer ; showing to read position
inc current_position ; for other purposes
ret
@@less: ; we dont have to reread buffer, it wokrs okay
mov al, byte ptr[si] ; putting al byte from buffer
inc si ; going to next byte
inc read_position ; to know when to renew buffer
inc current_position ; for other purposes
ret
; no more to do, stopping loop
@@done:
mov stop_prog_loop, 1
ret
endp
proc read_input_buffer
; saving registry values
push ax
push bx
push cx
push dx
mov bx, input_handler ; descriptor number
mov cx, read_buffer_size ; how many bytes to read
mov dx, offset read_buffer ; address of buffer
mov ah, 3Fh ; calling dos
int 21h ; calling dos
mov read_buffer_length, al ; how many symbols current buffer has
; giving registers values back
pop dx
pop cx
pop bx
pop ax
ret
endp
我看不出你在哪里叫get_byte 无论如何-由于您将读取位置初始化为1而不是0,因此 jl@@less 应该是 jle@@less
将读取位置与读取缓冲区长度进行比较后。当您调用GET\u BYTE并且处于缓冲区的末尾,并且没有条件跳转到@@LESS时,流继续@@read\u INPUT\u缓冲区和被调用的子例程,在堆栈上推送寄存器,然后弹出它们。但是,请注意,在增加SI时,上一次调用GET_BYTE的AL值保持不变,因此再次显示相同的字符。您可以通过在GET_BYTE中调用READ_INPUT_BUFFER之前添加:MOV AL,BYTE PTR[SI]来修复它。jle给出输出12334。它仍然不是期望的输出。顺便说一下,我编辑了这个问题并添加了如何调用get_字节。
call open_input_file
call open_output_file
call read_input_buffer
mov read_position, 1
mov si, offset read_buffer
call get_byte
int 29h
call get_byte
int 29h
call get_byte
int 29h
call get_byte
int 29h
call get_byte
int 29h
call close_output_file
call close_input_file