-
-
Save Megawats777/0ace68a2dc077e8ca5d381cf3f3bcd81 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
This is a 'hello world' program in x86_64 assembler using the | |
GNU assembler (gas) syntax. Note that this program runs in 64-bit | |
mode. | |
CTyler, Seneca College, 2014-01-20 | |
Licensed under GNU GPL v2+ | |
*/ | |
/*--Modified by: James Daniel Semilla--*/ | |
/*--Student ID: 105718175--*/ | |
/*--Date: March 4, 2020--*/ | |
/*--Print char reference: https://stackoverflow.com/questions/8201613/printing-a-character-to-standard-output-in-assembly-x86 --*/ | |
.text | |
.globl _start | |
min = 0 | |
max = 31 | |
zeroCheck = 48 | |
/*---Register Info---*/ | |
/*-r8: Left digit ASCII-*/ | |
/*-r9: Right digit ASCII-*/ | |
_start: | |
mov $min, %r15 | |
mov $10, %r10 | |
movq $msg, %r12 | |
add $8, %r12 | |
loop: | |
/*--Character Processing--*/ | |
mov %r15, %rax | |
mov $0, %rdx | |
div %r10 | |
/*--Get the left digit--*/ | |
mov %rax, %r8 | |
add $48, %r8 | |
/*--Check if the left digit is not a zero--*/ | |
cmp $zeroCheck, %r8 | |
jne onLeftDigitNotZero | |
/*--False: turn the left digit into a space--*/ | |
mov $32, %r8 | |
/*--True--*/ | |
onLeftDigitNotZero: | |
/*--Get the right digit--*/ | |
mov %rdx, %r9 | |
add $48, %r9 | |
inc %r15 | |
/*--Print the text "Loop:"--*/ | |
movq $len,%rdx /* message length */ | |
movq $msg,%rsi /* message location */ | |
movq $1,%rdi /* file descriptor stdout */ | |
movq $1,%rax /* syscall sys_write */ | |
syscall | |
/*--Print a space--*/ | |
push $32 /*--Print space character--*/ | |
mov %rsp, %rsi | |
movq $1,%rdi /* file descriptor stdout */ | |
movq $1,%rax /* syscall sys_write */ | |
syscall | |
/*--Print the first digit--*/ | |
push %r8 /*--Print first digit character--*/ | |
mov %rsp, %rsi | |
movq $1,%rdi /* file descriptor stdout */ | |
movq $1,%rax /* syscall sys_write */ | |
syscall | |
/*--Print the second digit--*/ | |
push %r9 /*--Print second digit character--*/ | |
mov %rsp, %rsi | |
movq $1,%rdi /* file descriptor stdout */ | |
movq $1,%rax /* syscall sys_write */ | |
syscall | |
/*--Print the new line--*/ | |
push $10 /*--Print new line character--*/ | |
mov %rsp, %rsi | |
movq $1,%rdi /* file descriptor stdout */ | |
movq $1,%rax /* syscall sys_write */ | |
syscall | |
cmp $max, %r15 | |
jne loop | |
movq $0,%rdi /* exit status */ | |
movq $60,%rax /* syscall sys_exit */ | |
syscall | |
.section .rodata | |
msg: .ascii "Loop:" | |
len = . - msg | |
numMsg: .ascii " " | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment