summaryrefslogtreecommitdiffstats
path: root/capital.asm
blob: 4f92d7fa7fc4bd2f000bedd737c02cae30e2cd84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
; Version	: 1.01
; Updated	: 25/5/2020
; Copyright (C)	: 2020 Gentoo-libre Install
; 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