TASM从缓冲区获取下一个字节

时间:2014-11-30 20:57:05

标签: assembly buffer tasm

我正在编写从缓冲区获取下一个字节的过程,如果在分析缓冲区时需要更多字节,它会从文件中读取更多信息。但它不起作用。不知道为什么。这个函数用在循环中,它在al寄存器中打印char,但是我得不到我需要的东西(实际上我得到了无限循环,我就像wtf?无法实现为什么)。我认为它总是在跳跃。不知道为什么。有任何想法吗?先感谢您。这是代码:

proc get_byte

  mov ah, read_buffer_length   ; read_buffer_length - actual amount of bytes read from file
  sub ah, 1                    ; subtracting one since read_position is calculated from 0
                               ; and read_buffer_length from 1
  cmp read_position, ah        ; comparing current position in buffer and buffer length
  jle @@not_less               ; if read_position <= ah then we jump to @@not_less

  @@read_input_buffer:         ; we need more bytes, since we dont have anything in buffer
    call read_input_buffer     ; function does everything good, tested
    mov read_position, 0       ; nullify position
    mov ch, 0h                 ; ch=0
    mov cl, read_buffer_length ; putting cl for loop. this function is used in loop
    mov si, offset read_buffer ; putting beginning of buffer

  @@not_less:                  ; in this case we dont need extra reading to buffer, it has enough bytes
    mov al, [si]               ; i want result in al
    inc si                     ; increasing value of pointer
    inc read_position          ; increasing position number
  ret
endp

1 个答案:

答案 0 :(得分:1)

够简单!

jge @@not_less

这与您的评论不符!使用jle

相关问题