Last active
January 29, 2017 23:40
-
-
Save blotta/61a2791d93f5f32302ecbeb024e900b0 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
.text | |
.globl _start | |
start = 0 /* starting value for the loop index; note that this is a symbol (constant), not a variable */ | |
max = 10 /* loop exits when the index hits this number (loop condition is i<max) */ | |
_start: | |
mov $start,%r15 /* loop index */ | |
loop: | |
/* ... body of the loop ... do something useful here ... */ | |
/* Printing .msg */ | |
movq $len,%rdx /*Length of data in address pointed by msg*/ | |
movq $msg,%rsi /*Message data on msg*/ | |
movq $1,%rdi /*1 for stdout*/ | |
movq $1,%rax /*sys_write instruction*/ | |
syscall | |
/*following digit*/ | |
movq $len2,%rdx /*Length*/ | |
movq $digit,%rsi /*Message data on digit (blank space)*/ | |
movb %r15b,(%rsi)/*Moves loop counter as a byte to rsi (digit)*/ | |
add $48,(%rsi) /*ASCII conversion*/ | |
movq $1,%rdi /*stdout*/ | |
movq $1,%rax /*sys_write*/ | |
syscall | |
/*prints newline char*/ | |
movq $len1,%rdx | |
movq $nl,%rsi | |
movq $1,%rdi | |
movq $1,%rax | |
syscall | |
inc %r15 /* increment index */ | |
cmp $max,%r15 /* see if we're done */ | |
jne loop /* loop if we're not */ | |
mov $0,%rdi /* exit status */ | |
mov $60,%rax /* syscall sys_exit */ | |
syscall | |
.section .data | |
msg: .ascii " Loop: " | |
len = . - msg | |
nl: .ascii "\n" | |
len1 = . - nl | |
digit: .ascii " " | |
len2 = . - digit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment