Last active
March 18, 2017 11:09
-
-
Save banderlog/1136649a065c8e2147654dd5290953ca to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; array.asm ;; | |
;; | |
global _start | |
section .bss | |
array resb 256 | |
array2 resb 8 | |
section .text | |
;;it is very convinient to write functions before _start | |
;fill memory (edi=address, ecx = length, al = value) | |
fill_memory: | |
jecxz fm_q ;if ecx = 0 => jump | |
fm_lp: mov [edi],al ;put value to array element | |
inc edi ;next element | |
loop fm_lp ;repeat | |
fm_q: ret ;exit function | |
;;START | |
_start: | |
mov ecx, 256 ;counter | |
mov edi, array ;array start | |
mov al, '@' ;filling | |
again: mov [edi], al ;filling to array element | |
inc edi ;next el | |
dec ecx ;dec counter | |
jnz again ;again if not 0 | |
mov edi, array2 ;prepare to call function | |
mov ecx, 8 ; | |
mov al, 'a' ; | |
call fill_memory;call function | |
;; xor test. fun, but I cant enc inside %rep | |
mov ecx, 0 ;position in array | |
%rep 2 ;do 2 times - array length | |
mov eax, [array2+ecx] ;portion of 4 bytes to eax | |
xor eax, [array+ecx] ;xor with 4 bytes from other string | |
mov [array2+ecx], eax ;put xored data back | |
add ecx, 4 ;next portion | |
%endrep | |
mov eax, 10 ;breakline code char | |
mov [array2+8], eax ;put just after array2 in memory | |
;; print and exit section ;; | |
mov eax, 4 ;write | |
mov ebx, 1 ; to standard output | |
mov ecx, array2 ; our string's start | |
mov edx, 9 ; bytes long | |
int 80h ; syscall (do it) | |
mov eax, 1 ;exit | |
mov ebx, 1 ; all ok | |
int 80h ; do it |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment