From 6750f239bba921339614b6f7b655d52dd761ae94 Mon Sep 17 00:00:00 2001 From: Gentoo Date: Wed, 17 Jun 2020 13:13:54 +1000 Subject: initial commit --- nextchar.asm | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 nextchar.asm (limited to 'nextchar.asm') diff --git a/nextchar.asm b/nextchar.asm new file mode 100644 index 0000000..5538a1b --- /dev/null +++ b/nextchar.asm @@ -0,0 +1,39 @@ +; Version : 1.0 +; Updated : 17/6/2020 +; Description : NextChar program. Quite slowly fills up a buff in static memory with a char, a space and then the next char etc + +;; static memory is nicer to use than the stack +section .bss + Buff resb 52 ; space for 26 characters + 25 spaces + newline + +section .text +global _start + +_start: +mov eax,'a' ;start character +mov ecx,26 ;number of times to print +xor ebx,ebx ;counter register for position in Buff + +loop: +mov byte[Buff+ebx],al ;The character in eax is copied to Buff (very slow) +mov byte[Buff+ebx+1],' ';A space is copied after the character + +inc eax ;go to next ASCII character +add ebx,2 ;Add 2 to ebx, so it now points to after the space + +dec ecx ;deincrement ecx since we just copied a character +test ecx,ecx ;test if ecx is zero +jnz loop ;jump to loop to copy the next character if ecx is not zero + +mov byte[Buff+ebx-1],0xA ;add the newline (-1 overwrites the newline) + +mov eax,1 ;sys_write +mov edi,1 ;fd = STDOUT_FILENO +mov edx,52 ;num of bytes to print +mov rsi,Buff ;where the characters are located +syscall + +Exit: +mov eax,60 ;code for sys_exit +xor edi,edi ;Return value of 0 +syscall ;Do sys_exit -- cgit v1.2.3