Advertisement
BartekPogoda

lab2asm

Mar 22nd, 2017
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SYSEXIT = 1
  2. SYSREAD = 3
  3. SYSWRITE = 4
  4.  
  5. STDIN = 0
  6. STDOUT = 1
  7.  
  8. SYSCALL = 0x80
  9. EXIT_SUCCESS = 0
  10.  
  11. MAX_INPUT_SIZE = 0xFF
  12. LENGTH_SIZE = 0x01
  13.  
  14. .align 32
  15.  
  16. .data
  17.     dataSize: .byte 0x00
  18.     readingCounter: .byte 0x00
  19.     readingAflag: .byte 0x01
  20.     outputBuffer: .byte 0x00
  21.  
  22. .bss
  23.     .lcomm numberA, MAX_INPUT_SIZE
  24.     .lcomm numberB, MAX_INPUT_SIZE
  25.  
  26. .text
  27.  
  28. .global _start
  29.  
  30. _start:
  31.     # dbg
  32.     mov $0, %rax
  33.     mov $dataSize, %eax
  34.  
  35.     # wczytanie dlugosci danych
  36.     mov $SYSREAD, %eax
  37.     mov $STDIN, %ebx
  38.     mov $dataSize, %ecx
  39.     mov $LENGTH_SIZE, %edx
  40.  
  41.     int $SYSCALL
  42.  
  43.     # wczytanie liczby A
  44.     mov (dataSize), %al
  45.     mov %al, (readingCounter)
  46.  
  47.     mov $numberA, %ecx
  48.     # mov $1, %r14 # counter to read numberA then numberB and jump further
  49. loadingLoop:
  50.     cmpb $0, (readingCounter)
  51.     je afterLoadingLoop
  52.  
  53.     mov $SYSREAD, %eax
  54.     mov $STDIN, %ebx
  55.     mov $1, %edx
  56.  
  57.     int $SYSCALL
  58.  
  59.     decb (readingCounter)
  60.     add $1, %ecx
  61.     jmp loadingLoop
  62.  
  63. afterLoadingLoop:
  64.     cmpb $0, (readingAflag) # meaning data is loaded
  65.     je dataProcessing
  66.     decb (readingAflag)
  67.  
  68.     mov (dataSize), %al
  69.     mov %al, (readingCounter)
  70.     mov $numberB, %ecx
  71.     jmp loadingLoop
  72.  
  73. dataProcessing:
  74.     #add
  75.     clc
  76.     lahf
  77.     mov $0, %ecx
  78. addingLoop:
  79.     cmp (dataSize), %ecx
  80.     je end
  81.  
  82.     movb numberA(,%ecx,1), %al
  83.     sahf
  84.     adcb numberB(,%ecx,1), %al
  85.     lahf
  86.     movb %al, (outputBuffer)
  87.  
  88.     mov $SYSWRITE, %eax
  89.     mov $STDOUT, %ebx
  90.     mov $outputBuffer, %ecx
  91.     mov $1, %edx
  92.  
  93.     int $SYSCALL
  94.  
  95.     inc %ecx
  96.  
  97.     jmp addingLoop
  98.  
  99.  
  100. end:
  101.     mov $SYSEXIT, %eax
  102.     mov $EXIT_SUCCESS, %ebx
  103.  
  104.     int $SYSCALL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement