diff options
author | Gentoo <installgentoo@endianness.com> | 2020-06-17 13:13:54 +1000 |
---|---|---|
committer | Gentoo <installgentoo@endianness.com> | 2020-06-17 13:13:54 +1000 |
commit | 6750f239bba921339614b6f7b655d52dd761ae94 (patch) | |
tree | 3f3f4728cb5dbb95482192dad2ebc7e6677c5922 /nextchar.asm | |
download | nextchar-asm-6750f239bba921339614b6f7b655d52dd761ae94.tar.gz nextchar-asm-6750f239bba921339614b6f7b655d52dd761ae94.tar.bz2 nextchar-asm-6750f239bba921339614b6f7b655d52dd761ae94.zip |
initial commit
Diffstat (limited to 'nextchar.asm')
-rw-r--r-- | nextchar.asm | 39 |
1 files changed, 39 insertions, 0 deletions
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 |