Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SYSEXIT = 1
- SYSREAD = 3
- SYSWRITE = 4
- STDIN = 0
- STDOUT = 1
- SYSCALL = 0x80
- EXIT_SUCCESS = 0
- MAX_INPUT_SIZE = 0xFF
- LENGTH_SIZE = 0x01
- .align 32
- .data
- dataSize: .byte 0x00
- readingCounter: .byte 0x00
- readingAflag: .byte 0x01
- outputBuffer: .byte 0x00
- .bss
- .lcomm numberA, MAX_INPUT_SIZE
- .lcomm numberB, MAX_INPUT_SIZE
- .text
- .global _start
- _start:
- # dbg
- mov $0, %rax
- mov $dataSize, %eax
- # wczytanie dlugosci danych
- mov $SYSREAD, %eax
- mov $STDIN, %ebx
- mov $dataSize, %ecx
- mov $LENGTH_SIZE, %edx
- int $SYSCALL
- # wczytanie liczby A
- mov (dataSize), %al
- mov %al, (readingCounter)
- mov $numberA, %ecx
- # mov $1, %r14 # counter to read numberA then numberB and jump further
- loadingLoop:
- cmpb $0, (readingCounter)
- je afterLoadingLoop
- mov $SYSREAD, %eax
- mov $STDIN, %ebx
- mov $1, %edx
- int $SYSCALL
- decb (readingCounter)
- add $1, %ecx
- jmp loadingLoop
- afterLoadingLoop:
- cmpb $0, (readingAflag) # meaning data is loaded
- je dataProcessing
- decb (readingAflag)
- mov (dataSize), %al
- mov %al, (readingCounter)
- mov $numberB, %ecx
- jmp loadingLoop
- dataProcessing:
- #add
- clc
- lahf
- mov $0, %ecx
- addingLoop:
- cmp (dataSize), %ecx
- je end
- movb numberA(,%ecx,1), %al
- sahf
- adcb numberB(,%ecx,1), %al
- lahf
- movb %al, (outputBuffer)
- mov $SYSWRITE, %eax
- mov $STDOUT, %ebx
- mov $outputBuffer, %ecx
- mov $1, %edx
- int $SYSCALL
- inc %ecx
- jmp addingLoop
- end:
- mov $SYSEXIT, %eax
- mov $EXIT_SUCCESS, %ebx
- int $SYSCALL
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement