Advertisement
senecatm

Lab3 x86 source code

Jan 26th, 2017
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .text
  2. .globl    _start
  3.  
  4. start = 0                       /* starting value for the loop index; note that this is a symbol (constant), not a variable */
  5. max = 30                        /* loop exits when the index hits this
  6. number (loop condition is i<max) */
  7.  
  8. _start:
  9.     mov     $start,%r15         /* loop index */
  10.  
  11. loop:
  12.     /* print the Loop message */
  13.         movq    $loop_msg_len,%rdx                       /* message length */
  14.         movq    $loop_msg,%rsi                       /* message location */
  15.         movq    $1,%rdi                         /* file descriptor stdout */
  16.         movq    $1,%rax                         /* syscall sys_write */
  17.         syscall
  18.  
  19.     mov $num_msg_len, %r13
  20.     mov %r15, %rax
  21.     mov $0, %rdx
  22.     div %r13
  23.  
  24.     /*Print the first digit */
  25.         mov     $num_msg, %r14
  26.         add     %rax, %r14
  27.     mov $num_msg, %r13
  28.     add %rdx, %r13
  29.  
  30.     cmp $0, %rax
  31.     je skip
  32.  
  33.         movq    $1,%rdx                       /* message length */
  34.     movq    %r14,%rsi                       /* message location */
  35.         movq    $1,%rdi                         /* file descriptor stdout */
  36.         movq    $1,%rax                         /* syscall sys_write */
  37.         syscall
  38. skip:
  39.         /*Print the second digit */
  40.  
  41.         movq    $1,%rdx                       /* message length */
  42.         movq    %r13,%rsi                       /* message location */
  43.         movq    $1,%rdi                         /* file descriptor stdout */
  44.         movq    $1,%rax                         /* syscall sys_write */
  45.         syscall
  46.  
  47.  
  48.     /* print the newline */
  49.         movq    $nl_msg_len,%rdx                       /* message length */
  50.         movq    $nl_msg,%rsi                       /* message location */
  51.         movq    $1,%rdi                         /* file descriptor stdout */
  52.         movq    $1,%rax                         /* syscall sys_write */
  53.         syscall
  54.  
  55.  
  56.     inc     %r15                /* increment index */
  57.     cmp     $max,%r15           /* see if we're done */
  58.    jne     loop                /* loop if we're not */
  59.  
  60.     mov     $0,%rdi             /* exit status */
  61.     mov     $60,%rax            /* syscall sys_exit */
  62.     syscall
  63.  
  64. .data
  65.  
  66. loop_msg:       .ascii  "Loop: "
  67. loop_msg_len = . - loop_msg
  68.  
  69. num_msg:        .ascii "0123456789"
  70. num_msg_len = . - num_msg
  71.  
  72. nl_msg:         .ascii "\n"
  73. nl_msg_len = . - nl_msg
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement