diff options
Diffstat (limited to 'capital.asm')
-rw-r--r-- | capital.asm | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/capital.asm b/capital.asm new file mode 100644 index 0000000..2c75245 --- /dev/null +++ b/capital.asm @@ -0,0 +1,38 @@ +; Version : 1.01 +; Updated : 25/5/2020 +; Licence : GPLv3 +; Description : Simple lowercase to capital program. +; Capitilises each lowercase ASCII char recieved in stdin and prints such to stdout. Exit only occurs if EOF is read. +; Done byte by byte for simplicity + +section .text + global _start + +_start: xor edi, edi ; file descriptor = stdin = 0 + lea rsi, [rsp+8] ; buffer = address to store the bytes read + mov edx, 1 ; number of bytes to read + xor eax, eax ; SYSCALL number for reading from STDIN is 0 + syscall ; make the syscall + + test eax, eax ; If syscall returns 0 in rax, the character is EOF + je _exit ; if char is EOF: exit + + cmp byte[rsp+8],'a' ;check if read char is below 'a' + jl newline ;if below 'a', it's not a lowercase char + + cmp byte[rsp+8],'z' ;check if read char is equal to or below z + ja newline ;if not equal or above, it's not a lowercase char + + sub byte[rsp+8], 32 ;subtract 32 from ASCII char to capitalise it + +newline:mov edi, 1 ; file descriptor = stdout + lea rsi, [rsp+8] ; buffer = address to write to console + mov edx, 1 ; number of bytes to write + mov eax, 1 ; SYSCALL number for writing to STDOUT + syscall ; make the syscall + + jmp _start ; read the next char + +_exit: xor edi, edi ; set exit status = 0 + mov eax, 60 ; SYSCALL number for EXIT + syscall ; make the syscall |