Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .text
- .globl _start
- start = 0 /* starting value for the loop index; note that this is a symbol (constant), not a variable */
- max = 30 /* loop exits when the index hits this
- number (loop condition is i<max) */
- _start:
- mov $start,%r15 /* loop index */
- loop:
- /* print the Loop message */
- movq $loop_msg_len,%rdx /* message length */
- movq $loop_msg,%rsi /* message location */
- movq $1,%rdi /* file descriptor stdout */
- movq $1,%rax /* syscall sys_write */
- syscall
- mov $num_msg_len, %r13
- mov %r15, %rax
- mov $0, %rdx
- div %r13
- /*Print the first digit */
- mov $num_msg, %r14
- add %rax, %r14
- mov $num_msg, %r13
- add %rdx, %r13
- cmp $0, %rax
- je skip
- movq $1,%rdx /* message length */
- movq %r14,%rsi /* message location */
- movq $1,%rdi /* file descriptor stdout */
- movq $1,%rax /* syscall sys_write */
- syscall
- skip:
- /*Print the second digit */
- movq $1,%rdx /* message length */
- movq %r13,%rsi /* message location */
- movq $1,%rdi /* file descriptor stdout */
- movq $1,%rax /* syscall sys_write */
- syscall
- /* print the newline */
- movq $nl_msg_len,%rdx /* message length */
- movq $nl_msg,%rsi /* message location */
- movq $1,%rdi /* file descriptor stdout */
- movq $1,%rax /* syscall sys_write */
- 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
- .data
- loop_msg: .ascii "Loop: "
- loop_msg_len = . - loop_msg
- num_msg: .ascii "0123456789"
- num_msg_len = . - num_msg
- nl_msg: .ascii "\n"
- nl_msg_len = . - nl_msg
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement