%include "CONSTANTS.h" section .data prompt: db `Enter a phrase: `,0 fmtString1: db `You entered '%s' \n`,0 endl: db `\n`,0 section .bss MAX_LEN equ 10 phrase: resb MAX_LEN+1 section .text global main main: ; r12 will hold the end of the string. ; r13 will hold the lcv ; prompt for a phrase mov rdi, prompt call CallPrintf ; flush the buffer, fflush needs to be called. mov rdi, 0 call Flush ; call read to read up to MAX_LEN into the buffer ; this will read until the end of line, or MAX_LEN is read ; and will store it into buffer, inclding the newline mov rax, SYS_READ mov rdi, STDIN mov rsi, phrase mov rdx, MAX_LEN syscall ; this will check to see if less then the max characters have been input mov r12, rax cmp r12, MAX_LEN jl fix ; we have max characters, is the last one an endl? mov al, byte [phrase+r12-1] cmp al, [endl] ; if the last character is not an endl don't remove it. jne skip fix: ; if it is a newline, remove it dec r12 skip: ; this make sure that the string is null terminated. mov byte [phrase + r12], 0 ; print it out. mov rdi, fmtString1 mov rsi, phrase call CallPrintf ; set the index to be 0 mov r13,0 FixerLoopTop: cmp r13, r12 je FixerLoopDone ; load the letter into the al mov al, byte [phrase + r13] ; skip changing the letter if it is less than 'a' cmp al, 'a' jl FixerLoopBottom ; also don't mess with it if it is more than z cmp al, 'z' jg FixerLoopBottom ; must be between a and z so subtract 20 to make it upper case sub al, 0x20 mov byte [phrase + r13], al FixerLoopBottom: ; increment the loop control variable inc r13 jmp FixerLoopTop FixerLoopDone: ; print it out. mov rdi, fmtString1 mov rsi, phrase call CallPrintf jmp Exit