%include "CONSTANTS.h" MAX_LEN equ 100 section .data prompt: db `Enter some text, up to %d characters `,0 endl: db `\n`,0 debugFmt1: db `\n%d characters were input\n`,0 debugFmt2: db `\n The string is "%s"\n`,0 debugFmt3: db `\n phrase[%d] = '%c'\n`,0 section .bss phrase: resb MAX_LEN+1 section .text global main main: ; prompt for input mov rdi, prompt mov rsi, MAX_LEN call CallPrintf ; flush the buffer 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 ; r12 will hold the length of the string mov r12, rax dec r12 ; print the number of bytes input mov rdi, debugFmt1 mov rsi, rax call CallPrintf mov byte [phrase + r12], 0 ; print the string input mov rdi, debugFmt2 mov rsi, phrase call CallPrintf ; let r13 be i ; i = 0 mov r13, 0 TopOfLoop: ; while i < size cmp r13, r12 je OutOfLoop ; if islower(phrase[i] ) ; rdx = phrase[i] mov rdx, 0 mov dl, byte [phrase + r13] ; is it less than 'a', if so, escape the if cmp rdx, 61h jl PastIf ; is it more than 'z', if so escape cmp rdx, 7ah jg PastIf ; it must be between a and z, so subtract 20h ; the difference between a and A ; phrase[i] = toupper(phrase[i]) sub rdx, 20h mov byte[phrase+r13], dl PastIf: ; ++i; inc r13 jmp TopOfLoop OutOfLoop: mov byte [phrase + r12], 0 ; print the string input mov rdi, debugFmt2 mov rsi, phrase call CallPrintf jmp Exit