我在buff
部分中定义.bss
只是1个字节的缓冲区,用于将一个字符作为输入并将其转换为大写,然后在stdout上显示它。但是当我在输入(字符串)中提供多个字符时,它仍然将整个字符串转换为大写!如果我指定缓冲一个字节,它如何缓冲多个字节。在stdin之后是否有另一个缓冲区,它一次为我的缓冲区提供1个字节?
我的代码:
SECTION .bss
buff resb 1
SECTION .data
SECTION .text
global _start
_start:
NOP
read:
MOV EAX, 3 ; Read syscall
MOV EBX, 0 ; Standard input
MOV ECX, buff ; Specify the buffer for stdin
MOV EDX, 1 ; 1 char at a time
INT 0x80 ; Interrupt for the syscal
CMP EAX, 0 ; Look at the return of read syscall, if
; unsuccessfull, exit
JE exit ; If the input was 0, jump to exit
CMP byte [buff], 0x61 ; Test for lowercase, lowercase are above
; 0x61 - 'a'
JB write ; Jump if below 'a' ASCII 0x61
CMP byte [buff], 0x7A ; Test for above 'z'- ASCII 0x7A
JA write ; Jump to write if input above 'z'
SUB byte [buff], 0x20 ; A lowercase input finally, convert it to
;uppercase by subtracting 0x20h
write:
MOV EAX, 4 ; Write syscall
MOV EBX, 1 ; Write on stdout
MOV ECX, buff ; take from this buffer
MOV EDX, 1 ; 1 charcter at a time
INT 0x80 ; Interrupt for the syscall
JMP read ; Jump for reading again
exit:
MOV EAX, 1 ; Exit syscall
MOV EBX, 0 ; Errorcode in EBX
INT 0x80 ; Interrupt for exit syscall