高手帮帮忙汇编编程

来源:百度知道 编辑:UC知道 时间:2024/05/16 15:52:10
请在LINUX的GUN环境上写.
编写程序实现将一个字符串中的小写字母转换为大写,
并输出.
最好用AT&T格式写.
才学,麻烦写一下注释

.file "toupper.s"

.section .bss
.equ len, 256 # 定义常量len
.lcomm str, len # 定义一个名为str的缓冲区,长度为256字节

.section .text

.global _start
_start:
# %eax = 3,int $0x80为linux系统调用read,%ebx是文件描述符,$0表示标准输入,%ecx是缓冲区首地址,%edx是长度
movl $str, %ecx
movl $0, %ebx
movl $3, %eax
movl $256, %edx
int $0x80

movl $str, %ecx
xor %eax, %eax

jmp ts0

up0:
incl %eax
ts0:
cmpl $len, %eax # 循环直到%eax >= $len
jge done0

# 以下3句确定每个字符的ascii码范围,如果是大写则将其转为小写,(%ecx, %eax, 1)是寻址模式,这里表示以ecx为基地址,%eax做下标,1是标量。寻址为%ecx + %eax * 1
cmpb $97, (%ecx, %eax, 1)
jl jtb_up0
cmpb $122, (%ecx, %eax, 1)
jg jtb_up0
subl $32, (%ecx, %eax, 1)

jtb_up0:
jmp up0
done0:

# 4号调用是write函数,%ebx存文件描述符,$1表标准输出,%edx存长度,%ecx存字符串首
mo