rendered paste body .section .data
mode_write:
.ascii "w\0"
mode_read:
.ascii "r\0"
#.equ stores numerical data, don't know if we could use those for these modes ie r0
.section .text
.globl _start
.equ ST_ARGC, 0
.equ ST_ARGV_0, 4
.equ ST_ARGV_1, 8
.equ ST_ARGV_2, 12
#we'll take an input/output file as arguements
_start:
movl %esp, %ebp
subl $8, %esp #local file descriptor variables
pushl $mode_read
pushl ST_ARGV_1(%ebp)
call fopen #not too interested in error checking stuff now :p
addl $8, %esp
movl %eax, -4(%ebp)
pushl $mode_write
pushl ST_ARGV_2(%ebp)
call fopen
addl $8, %esp
movl %eax, -8(%ebp)
.equ LOWERCASE_A, 'a' #I don't know why i put these, just keeping to an example i seen :)
.equ LOWERCASE_Z, 'z'
.equ TO_UPPER_CONVERT, 'A' - LOWERCASE_A
convert_loop:
pushl -4(%ebp)
call fgetc
addl $4, %esp
cmpl $0, %eax #returns EOF/0 or error.. whatever works :)
jle done_convert
cmpl $LOWERCASE_A, %eax
jl convert_loop
cmpl $LOWERCASE_Z, %eax
jg convert_loop
#convert the character
addl $TO_UPPER_CONVERT, %eax
pushl -8(%ebp) #push descriptor or FILE struct pointer
pushl %eax #push the character code
call fputc
continue: #just a marker
jmp convert_loop
done_convert:
pushl -8(%ebp)
call fclose
pushl -4(%ebp)
call fclose
pushl $0
call exit