21,459
社区成员
发帖
与我相关
我的任务
分享
section .bss
Buff resb 1
section .data
section .text
global _start
_start:
nop
Read: mov eax,3 l
mov ebx,0
mov ecx,Buff
mov edx,1
int 80h
cmp eax,0
je Exit
cmp byte [Buff],61h
jb Write
cmp byte [Buff],7Ah
ja Write
sub byte [Buff],20h
Write: mov eax,4
mov ebx,1
mov ecx,Buff
mov edx,1
int 80h
jmp Read
Exit: mov eax,1
mov ebx,0
int 80H
section .bss
Buff resb 1
section .data
section .text
global _start
_start:
nop ; This no-op keeps the debugger happy
Read: mov eax,3 ; Specify sys_read call
mov ebx,0 ; Specify File Descriptor 0: Standard Input
mov ecx,Buff ; Pass offset of the buffer to read to
mov edx,1 ; Tell sys_read to read one char from stdin
int 80h ; Call sys_read
cmp eax,0 ; Look at sys_read's return value in EAX
je Exit ; Jump If Equal to 0 (0 means EOF) to Exit
; or fall through to test for lowercase
cmp byte [Buff],61h ; Test input char against lowercase 'a'
jb Write ; If below 'a' in ASCII chart, not lowercase
cmp byte [Buff],7Ah ; Test input char against lowercase 'z'
ja Write ; If above 'z' in ASCII chart, not lowercase
; At this point, we have a lowercase character
sub byte [Buff],20h ; Subtract 20h from lowercase to give uppercase...
; ...and then write out the char to stdout
Write: mov eax,4 ; Specify sys_write call
mov ebx,1 ; Specify File Descriptor 1: Standard output
mov ecx,Buff ; Pass address of the character to write
mov edx,1 ; Pass number of chars to write
int 80h ; Call sys_write...
jmp Read ; ...then go to the beginning to get another character
Exit: mov eax,1 ; Code for Exit Syscall
mov ebx,0 ; Return a code of zero to Linux
int 80H ; Make kernel call to exit program
这是完整的带注释的代码,我不知道你说的漏了什么
这段代码我编译运行过了,没问题,功能是是读取一个文本文件,将所有小写转成大写保存到另一个文件
./uppercase1 < xxx.txt > xxxUp.txt