Advertisement
Guest User

aliddin

a guest
Nov 27th, 2015
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .data
  2. msg:    .string "If result is 1 Matrikelnummer is valid otherwise invalid. Result: %d\n"
  3. # number: abcdefg, valid if (a * 9 + b * 7 + c * 3 + d * 9 + e * 7 + f * 3) mod 10 = g
  4.  
  5. .text
  6. .global main
  7.  
  8. main:
  9.     movl $1611813,%eax
  10.     movl $10, %ebx
  11.     movl $0, %ecx
  12.     movl $0, %edx
  13.     movl $0, %edi
  14.    
  15.     cdq
  16.     idivl %ebx
  17.     movl %edx, %edi     # edi = g (1st digit)
  18.  
  19.     cdq
  20.     idivl %ebx
  21.     imull $3, %edx      # f*3
  22.     movl %edx, %ecx     # ecx = f*3 (2nd digit)
  23.  
  24.     cdq
  25.     idivl %ebx
  26.     imull $7, %edx      # e*7
  27.     addl %edx, %ecx     # ecx = f*3 + e*7 (3rd digit)
  28.  
  29.     cdq
  30.     idivl %ebx
  31.     imull $9, %edx      # d*9
  32.     addl %edx, %ecx     # ecx = f*3 + e*7 + d*9 (4th digit)
  33.  
  34.     cdq
  35.     idivl %ebx
  36.     imull $3, %edx      # c*3
  37.     addl %edx, %ecx     # ecx = f*3 + e*7 + d*9 + c*3 (5th digit)
  38.  
  39.     cdq
  40.     idivl %ebx
  41.     imull $7, %edx      # b*7
  42.     addl %edx, %ecx     # ecx = f*3 + e*7 + d*9 + c*3 + b*7 (6th digit)
  43.  
  44.     cdq
  45.     idivl %ebx
  46.     imull $9, %edx      # a*9
  47.     addl %edx, %ecx     # ecx = f*3 + e*7 + d*9 + c*3 + b*7 + a*9 (7th)
  48.  
  49.     movl %ecx, %eax
  50.     cdq
  51.     idivl %ebx
  52.  
  53.     cmpl %edi, %edx
  54.     je .valid
  55.     movl $0, %eax
  56.     jmp .invalid
  57.  
  58. .valid:
  59.     movl $1, %eax
  60.  
  61. .invalid:
  62.  
  63.     pushl %eax
  64.     pushl $msg
  65.     call printf
  66.    
  67.     movl $0, %eax
  68.     int $0x80
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement