Advertisement
Guest User

Untitled

a guest
Apr 14th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .data
  2.     firstNumber:
  3.         .long 0x00043000, 0x00000000, 0x00000000, 0x20000001
  4.         firstNumberSize = . - firstNumber
  5.     secondNumber:
  6.         .long 0x00002000, 0x00000000, 0x05000001#, 0x00000002
  7.         secondNumberSize = . - secondNumber
  8.     newLine: .ascii "\n\0"
  9.     format_string:
  10.         .ascii "%08x \0"
  11.     printingCounter:
  12.         .long 0
  13. .text
  14. .global main
  15. main:
  16.     movl $firstNumberSize, %edi
  17.     movl $secondNumberSize, %esi
  18.  
  19.     shrl $2, %edi   # przesunięcie o 2 reprezentuje dzielenie przez 4 (4 bajty to 32 bity czyli long)
  20.     shrl $2, %esi   # edi i esi są naszymi iteratorami dla liczb 1 i 2
  21.  
  22.     cmpl %esi, %edi # jeśli edi większe niż esi, to
  23.     ja next              # ja jumps if CF = 0 & ZF = 0
  24.  
  25.     # jeśli edi NIE większe niz esi, to edi --> ecx
  26.     movl %edi, %ecx
  27.     movl %edi, %edx
  28.     jmp next2
  29.  
  30.     # jeśli edi wieksze niz esi, to esi --> ecx
  31.     next:
  32.         movl %esi, %ecx
  33.         movl %esi, %edx
  34.     next2:  
  35.         clc
  36.  
  37.     while:
  38.         decl %edi
  39.         decl %esi
  40.  
  41.         movl firstNumber(, %edi, 4), %eax
  42.         movl secondNumber(, %esi, 4), %ebx
  43.  
  44.         sbbl %ebx, %eax
  45.         pushl %eax
  46.  
  47.     loop while
  48.     jc carr # skok jeśli carry po ostatnim dodawaniu
  49.  
  50.  
  51.     # nie ma przeniesienia po ostatnim dodawaniu to sprawdzamy czy nic juz nie zostalo do dodania
  52.     cmpl %edi, %esi
  53.     je systemExit
  54.     jb toEdi # gdy esi mniejsze niż edi
  55.  
  56.     # esi większe
  57.     movl %esi, %ecx
  58.     clc
  59.     while1:
  60.         decl %esi    
  61.        
  62.         movl secondNumber(, %esi, 4), %eax
  63.         sbb $0, %eax
  64.         pushl %eax
  65.  
  66.     loop while1
  67.     jmp end
  68.  
  69. toEdi:
  70.     # edi większe
  71.     movl %edi, %ecx
  72.     clc
  73.     while2:
  74.         decl %edi
  75.        
  76.         movl firstNumber(, %edi, 4), %eax
  77.         sbb $0, %eax
  78.         pushl %eax
  79.  
  80.     loop while2
  81.     jmp end
  82.  
  83. jmp end
  84.  
  85. carr:
  86.     # jest carry po ostatnim dodawaniu
  87.     cmpl %edi, %esi
  88.     je carry # jeśli nic nie zostało
  89.     jb toEdi2 # jeśli esi mniejsze niż edi
  90.  
  91.     # esi większe
  92.     movl %esi, %ecx
  93.     stc # set carry
  94.  
  95.     while3:
  96.         decl %esi
  97.  
  98.         movl secondNumber(, %esi, 4), %eax
  99.         sbbl $0, %eax
  100.         pushl %eax
  101.  
  102.     loop while3
  103.     jmp end
  104.  
  105. toEdi2:
  106.     #edi większe
  107.     movl %edi, %ecx
  108.     stc
  109.     while4:
  110.         decl %edi
  111.         movl firstNumber(, %edi, 4), %eax
  112.         sbbl $0, %eax
  113.         pushl %eax
  114.  
  115.     loop while4
  116.     jmp end
  117.  
  118. carry:
  119.     pushl $0x00000001
  120.     incl %edx
  121.     jmp systemExit
  122.  
  123. end:
  124.     jnc systemExit
  125.     incl %edx
  126.     pushl $0x00000001
  127.  
  128.  
  129. systemExit:
  130.     addl $2, %edx
  131.     movl %edx, printingCounter        
  132.    
  133.     printLoop:
  134.         decl printingCounter
  135.         cmpl $0, printingCounter
  136.         je exitCall
  137.  
  138.         pushl $format_string
  139.         call printf
  140.         addl $8, %esp
  141.       jmp printLoop
  142. exitCall:
  143.     pushl $newLine
  144.     call printf
  145.     call exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement