我翻译了toupper.s
的AT& T版本来自"编程来自地面"英特尔集会作为一项运动。问题是我没有编译或执行错误(退出代码0),但我仍然无法看到正在创建的文件。
任何输入?我想念翻译吗?我还实现了一些参数验证,但
section .data
SYS_OPEN equ 5
SYS_WRITE equ 4
SYS_READ equ 3
SYS_CLOSE equ 6
SYS_EXIT equ 1
O_RDONLY equ 0
O_CREAT_WRONLY_TRUNC equ 3101o
STDIN equ 0
STDOUT equ 1
STDERR equ 2
LINUX_SYSCALL equ 80h
END_OF_FILE equ 0
NUMBER_ARGUMENTS equ 2
section .bss
BUFFER_SIZE equ 700000
BUFFER_DATA resb BUFFER_SIZE
section .text
ST_SIZE_RESERVE equ 8
ST_FD_IN equ -4
ST_FD_OUT equ -8
ST_ARGC equ 0
ST_ARGV_0 equ 4
ST_ARGV_1 equ 8
ST_ARGV_2 equ 12
global _start ;must be declared for using gcc
_start: ;tell linker entry point
mov ebp,esp
sub esp,ST_SIZE_RESERVE
open_files:
open_fd_in:
mov eax,[ebp+ST_ARGC]
cmp eax,2
jl use_system_files_in
jmp use_argc_files_in
use_system_files_in:
mov ebx,STDIN
use_argc_files_in:
mov ebx,[ebp+ST_ARGV_1]
mov eax,SYS_OPEN
mov ecx,O_RDONLY
mov edx,666o
int LINUX_SYSCALL
cmp eax,0
jl error
store_fd_in:
mov [ebp+ST_FD_IN],eax
open_fd_out:
mov eax,[ebp+ST_ARGC]
cmp eax,2
jl use_system_files_out
jmp use_argc_files_out
use_system_files_out:
mov ebx,STDOUT
use_argc_files_out:
mov ebx,[ebp+ST_ARGV_2]
mov eax,SYS_OPEN
mov ebx,STDOUT
mov ecx,O_CREAT_WRONLY_TRUNC
mov edx,666o
int LINUX_SYSCALL
store_fd_out:
mov [ebp+ST_FD_OUT],eax
read_data_loop_begin:
mov eax,SYS_READ
mov ebx,[ebp+ST_FD_IN]
mov ecx,BUFFER_DATA
mov edx,BUFFER_SIZE
int LINUX_SYSCALL
cmp eax,END_OF_FILE
jle read_data_loop_end
read_data_loop_continue:
push BUFFER_DATA
push eax
call convert_to_upper
pop eax
add esp,4
mov edx,eax
mov eax,SYS_WRITE
mov ebx,[ebp+ST_FD_OUT]
mov ecx,BUFFER_DATA
int LINUX_SYSCALL
jmp read_data_loop_begin
read_data_loop_end:
mov eax,SYS_CLOSE
mov ebx,[ebp+ST_FD_OUT]
int LINUX_SYSCALL
mov eax,SYS_CLOSE
mov ebx,[ebp+ST_FD_IN]
int LINUX_SYSCALL
mov eax,SYS_EXIT
mov ebx,0
int LINUX_SYSCALL
error:
mov ebx,eax
mov eax,SYS_EXIT
int LINUX_SYSCALL
; ##############################
; Function convert_to_upper
; ##############################
LOWERCASE_A equ 'a'
LOWERCASE_Z equ 'z'
UPPER_CONVERSION equ 'A' - 'a'
ST_BUFFER_LEN equ 8
ST_BUFFER equ 12
convert_to_upper:
push ebp
mov ebp,esp
mov eax,[ebp+ST_BUFFER]
mov ebx,[ebp+ST_BUFFER_LEN]
mov edi,0
cmp edx,0
je end_convert_loop
convert_loop:
mov cl,[eax+edi*1]
cmp cl,LOWERCASE_A
jl next_byte
cmp cl,LOWERCASE_Z
jg next_byte
add cl,UPPER_CONVERSION
mov [eax+edi*1],cl
next_byte:
inc edi
cmp ebx,edi
jne convert_loop
end_convert_loop:
mov esp,ebp
pop ebp
ret