Created
March 17, 2017 11:26
-
-
Save banderlog/cc112502b211fe234774ceb916eaa33d 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
;; hello_2.asm ;; | |
;; prints 5 strings 'hello' with one syscall ;; | |
global _start ;should ALWAYS be global, or ld upsets | |
section .bss ;non-initialized but reserved memory | |
string resb 30 ;reserve 30 bytes | |
section .text ;executive code section | |
msg db "hello",10 ;our message + \r | |
msglen equ $-msg ;length of msg, $ - current memory address | |
_start: ;main() | |
xor ebx, ebx ;ebx := 0, start of next msg | |
mov eax, 5 ;eax := 5, counter of msg amount | |
loop: ;cycle - put msg 5 times in memory | |
mov esi, msg ;adress of msg start | |
mov edi, string ;adress of string start | |
add edi, ebx ;start of string + msg's | |
mov ecx, msglen ;tell what length of msg to copy | |
cld ;set direction | |
rep movsb ;start copy byte-to-byte ecx times | |
add ebx, msglen ;calculate start point for next iteration | |
dec eax ;decrease counter | |
cmp eax, 0 ;if it != 0 | |
jnz loop ; do again | |
;; print and exit section ;; | |
mov eax, 4 ;write | |
mov ebx, 1 ; to standard output | |
mov ecx, string ; our string's start | |
mov edx, 30 ; 30 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